Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 3 123 LastLast
Results 1 to 25 of 54

Thread: How to referenc a class file. using only notepad and run cmd.

  1. #1
    Member
    Join Date
    Feb 2011
    Location
    Pittsburgh
    Posts
    62
    My Mood
    Angelic
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Unhappy How to referenc a class file. using only notepad and run cmd.

    Dear all:

    How in a java program, how do I tell java, where on my computer, another class is stored?

    I am using Note Pad and the run command.

    I am not sure how to reference a class in my code, I need to know the format, that is all.

    import java.util.Scanner;
    import java.lang.Math;

    POOR EXAMPLE OF WHAT I WANT TO DO
    import java.class.NotSureWhatIAmDoing C/Users/BackWaterFile/SepticTankFillingSchedule/etc.

    public static void main(String[] args)
    {
    NotSureWhatIAmDoing.RunScreaming() //Calling of pretend method from the class I have called.
    }


    Thanks in advance.

    Space Monkey


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    You need to tell Java what the classpath is. Recommended reading: Setting the class path
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Feb 2011
    Location
    Pittsburgh
    Posts
    62
    My Mood
    Angelic
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    Dear the WorkMan:

    Ok so i see:

    C : > sdkTool -classpath classpath1;classpath2...

    But I am confused, in Notepad, where I am programming, and assuming that the base directories do not match.

    How will the program know that I am creating a link (class path) to the class I want to reference, when I write:

    C : > sdkTool -classpath classpath1;classpath2...

    in the Command Prompt?

    If I could see an example I could work it out my self.

    Cheers.

    SpacedOut Monkey.
    Last edited by SPACE MONKEY; May 8th, 2012 at 10:47 AM. Reason: Removal of smily faces caused by C:>

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    You don't "tell" notepad anything about the classpath. You tell the compiler and the JRE about the classpath. You do that be specifying the classpath as an argument when you compile and run your program.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Member
    Join Date
    Feb 2011
    Location
    Pittsburgh
    Posts
    62
    My Mood
    Angelic
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Thumbs down Re: How to referenc a class file. using only notepad and run cmd.

    Dear the WorkMan:

    I do not think I am asking the write question.

    I understand that if I keep my classes in the same file, I should be OK.

    To your point:

    You tell the compiler and the JRE about the classpath.
    How do I tell the JRE about the classpath?

    I will go back and look at the link you posted in your first post.

    I am not even sure if classpath is part of the problem I am having, in trying to reference a Class from another class not in the same base file.



    Cheers.

    SpacedOut Monkey.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    Both the javac and the java commands have commandline options to specify the classpath to use. Look at the doc for those commands to get the correct syntax.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Feb 2011
    Location
    Pittsburgh
    Posts
    62
    My Mood
    Angelic
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    Dear Workman:

    QUESTIONS AT END OF POST

    My problem is that I do not have a good understanding of the computer.

    I a case like this you need to let me know that I need to deal with the "Environmental Variables" otherwise I am just floundering.

    In the Environmental Variables, in the UserVariables section I have entered the:
    Variable Name: Classpath
    Variable value: .;C:\Users\Kevin\Documents\JavaNotepad\Bootclasspa th.class;C:\Users\Kevin\Documents\JavaNotepad\Pres entStudy

    The directory to the class I am calling is in JavaNotepad file.
    The class is called Bootclasspath, and I am calling it as "Bootclasspath.class".

    The place from where I am calling it is:
    C:\Users\Kevin\Documents\JavaNotepad\PresentStudy
    The program I am working on is FixChap5.java, which is located in the file "PresentStudy"

    This is not working, the error I am getting is. "package Bootclasspath does not exist."
    FixChap5.java calls the class "Bootclasspath", and gets the error message "package Bootclasspath does not exist.".

    So I think the problem is with the ending of each of the two lines of classpath statement
    .:
    I sort of understand the above line indicates look in the current folder.

    C:\Users\Kevin\Documents\JavaNotepad\Bootclasspath .class;

    Should the above classpath end in the JavaNotepad folder name, or Bootclasspath.java, or should Bootclasspath be in a jar or zip file?

    C:\Users\Kevin\Documents\JavaNotepad\PresentStudy

    Is the above classpath correct or should it contain the file name (FixChap5) with a java or class or zip or jar file ending?

    I started my computer a lot, put this comment in caps and did not realize that people where interpreting it as shouting, sorry. Note the cheers after, that was the intended tone. Crap.
    Cheers.

    SpaceMonkey.

    P.S. Look at the views over the last two day, you lot need to put up a tutorial on this one because it is not covered well anywhere. Also for us not using eclips, just notepad, it is vital.
    Last edited by SPACE MONKEY; May 11th, 2012 at 12:04 AM. Reason: The caps at the end where not intended to look angry.

  8. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    Quote Originally Posted by SPACE MONKEY View Post
    I a case like this you need to let me know that I need to deal with the "Environmental Variables" otherwise I am just floundering.
    Word to the wise- don't tell somebody who is helping you, for free, in their spare time, what they "need" to do. It just comes off as ungrateful, which I don't think you actually intend.

    Quote Originally Posted by SPACE MONKEY View Post
    In the Environmental Variables, in the UserVariables section I have entered the:
    Variable Name: Classpath
    Variable value: .;C:\Users\Kevin\Documents\JavaNotepad\Bootclasspa th.class;C:\Users\Kevin\Documents\JavaNotepad\Pres entStudy
    Please read the tutorial I linked to you. It contains an explanation of what you're doing wrong here.

    Quote Originally Posted by SPACE MONKEY View Post
    Should the above classpath end in the JavaNotepad folder name, or Bootclasspath.java, or should Bootclasspath be in a jar or zip file?
    Is the above classpath correct or should it contain the file name (FixChap5) with a java or class or zip or jar file ending?
    The tutorial I linked you contains the answer to this question.


    Quote Originally Posted by SPACE MONKEY View Post
    .S. Look at the views over the last two day, you lot need to put up a tutorial on this one because it is not covered well anywhere. Also for us not using eclips, just notepad, it is vital.
    Again, telling "you lot" what we "need" to do is pretty rude. I already linked you a tutorial that you seem to be misunderstanding, plus there are tons of resources out there on this exact issue. Do a google search of "setting Java classpath" or something before you declare that we NEED to put up a tutorial because it's not covered ANYWHERE.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    Try doing a more simple exercise without packages so you will not have to worry about classpath just yet. Remove the package statement from all the source and put all the .java files in the same folder. Also remove any import statements that refer to any of your packages.
    When all the source compiles and executes with no errors, then work on moving one of the classes to a package.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Member
    Join Date
    Feb 2011
    Location
    Pittsburgh
    Posts
    62
    My Mood
    Angelic
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    Dear Workman:

    I work hard at this java to learn to understand.

    I did not capitalize the word NEED, and out of my post you have taken umbridge over 3 words, without commenting on the 55 views in two days which is a pertinent fact.

    One of the reasons people like me can not find the information on linking classes is because we are using the wrong search terms to find the information.

    So should you have time, I suggest someone at this site create a tutorial that would be useful to a whole lot of people.

    Kevin I appreciate your help and hope that you will help me in the future.

    Cheers.

    SpaceMonkey.

  11. #11
    Member
    Join Date
    Feb 2011
    Location
    Pittsburgh
    Posts
    62
    My Mood
    Angelic
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    Dear Norm:


    I do not have any packages. I need to look up packages?
    The whole point is that I do not understand how to reference classes and thus I want to know. It is integral to java so I need to understand.
    Last edited by SPACE MONKEY; May 10th, 2012 at 10:16 AM. Reason: Sonded impertanent.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    If everything is in one folder you do not need import statements or classpath settings. When you get a working group of classes THEN work on the next step: putting a class in a package and using an import statement and classpath. Take one small step from a known working version.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Member
    Join Date
    Feb 2011
    Location
    Pittsburgh
    Posts
    62
    My Mood
    Angelic
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    Dear Norman:

    Ok got it, I have two classes that talk to each other. Both classes are in the same folder.
    So onto step 2.

    ;C sdkTool -classpath classpath1;classpath2...

    Is the above the same as going to Environmental Variables and setting the class path?

    MAIN PROBLEM

    Taken from Setting the class package:


    Setting the class path
    For .class files in an unnamed package, the class path ends with the directory that contains the .class files.
    So I have referenced the JavaNotepad file containing the Bootclasspath.class, which is not in a package, so the calling ends in the file name.
    . ;C:\Users\Kevin\Documents\JavaNotepad;
    (the spaces between the . and the ; stop a smiley face from appearing.

    I did this in the "Environmental Variables, as explained in my last post.

    This will not work, and I did move the Bootclasspath.class & .java from the folder it was in, to JavaNotepad. Then I restarted my computer just in case.

    In my code to reference the Bootclasspath.class I wrote.
    [CODE]import Bootclasspath.*;[CODE/]

    So in what area is my problem is my referencing the method Bootclasspath? I say this because my code works when both files are in the same folder.


    Thanks.

    SpaceMonkey

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    Do you have a set of classes that compile and execute without packages, import statements or classpath settings? You need to start from a known working position.

    Can you list the names of the source files you are working with?

    onto step 2.
    Define what you want to do for step 2.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Member
    Join Date
    Feb 2011
    Location
    Pittsburgh
    Posts
    62
    My Mood
    Angelic
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    Dear Norm:

    Norm sorry for not answering your question I ran out of time.

    For point two I wanted to know how to set the class path so I could call a method from a class that is not in the same base folder as the calling class.

    First class
     
    import java.util.Scanner;
    import java.lang.Math;
    public class FixChap5
    {
    public static void main(String[] args)
    {
    Scanner keyboard = new Scanner(System.in);
    	int x = 1;
    	boolean b = false;
    	do
    	{
    		if ( x%2 == 0)
    	 		b = true;
    		else
    			b = false;
     
    		x++;
    	}
    	while ((!b )|| (x < 7));
    	System.out.println(" x = " + x);
    	Bootclasspath.callBootClass();
    }}

    Second class
    public class Bootclasspath {
     
    public static void callBootClass()
    	{
    	System.out.println(System.getProperty("sun.boot.class.path"));
    	}
        public static void main(String[] args) {
        callBootClass();
        }
    }

    so the classes are real simple, I just want to understand how to link them. Then I go onto packages.

    Cheers.

    SpaceMonkey
    Last edited by SPACE MONKEY; May 11th, 2012 at 07:08 AM. Reason: Did not answer Norms question about what is point 2, and removed the Bootclasspath.*;

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    If the .java and the .class files are in the same folder, there should not be a problem.
    Why is the import Bootclasspath.*; statement there? Using that entails classpath and folder usages that you claim you are not using.
    Remove it.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Member
    Join Date
    Feb 2011
    Location
    Pittsburgh
    Posts
    62
    My Mood
    Angelic
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    Dear Norm:

    First, I checked out a few of your other posts and you are incredibly patient with people, from them and me thanks.

    I have obviously given you the impression that I do not want to use class path. I am very sorry. The whole point of all these reply's is so that I can get help to learn to use class path. I DO want to learn to use classpath. (Capitals used with respect.)

    What I am trying to do is learn the process. I do not understand the correct method to complete the task: Calling a method from one class not in the same base folder as the calling class.

    The reason the import Bootclasspath.*; is there is because I am/want to learn to use classpath.

    WHAT I KNOW HOW TO DO
    I know how to call a method from another class that is in the same folder as the calling class.

    WHAT I WANT TO DO
    I want to learn, how to call a method from a class that is NOT in the same folder as the calling class.

    WHY I WANT TO DO WHAT I WANT TO DO
    Because I want to learn java. Not to fix a specific problem.

    SORRY FOR THE CAPITALS
    Sorry for the capitals.


    Cheers

    Space Monkey.

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    I am trying to do this one step at a time.
    When you have the two class files so that they compile and execute using only one folder and no import statement, we'll move one step to using a package.

    Do your two .java files compile and execute?
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Member
    Join Date
    Feb 2011
    Location
    Pittsburgh
    Posts
    62
    My Mood
    Angelic
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    Dear Norm:

    Done, I edited my code in the post 3 or 4 back and it works fine. I simply remove the import Bootclasspath.*; and everything is fine.

    The two .java files compile and execute when in the same base file.

    Forgive me if this is impossible or unwise, but I am not looking to learn Packages unless it is a prerequisite for learning to connect two classes.

    I just want to know how to set the class path. Of course if I need to know Packages right now, then thanks for keeping me on the right path.

    Thanks.

    SpaceMonkey
    Last edited by SPACE MONKEY; May 11th, 2012 at 07:07 AM. Reason: Forgot to answer the question, and a bit of clarification.

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    Now to the use of package and import statements:
    create a folder: package1 in the folder which the FixChap.java is in.
    Move the Bootclasspath files to that folder.
    Add a package package1; statement to the Bootclasspath.java file.
    Compile it.
    Edit the FixChap5.java and add import Bootclasspath.*; to it
    compile and execute it. (the default classpath should be the folder with these three things in it: the FixChap5 files and the package1 folder.)
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Member
    Join Date
    Feb 2011
    Location
    Pittsburgh
    Posts
    62
    My Mood
    Angelic
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    Dear Norm:

    Thanks.

    I set the folders up as you said.

    I moved Booclasspath to the package1 folder and added the
     package package1:

    I get a problem, AFTER compiling javac Bootclasspath.java, when I enter java Bootclasspath I get the following error:

    Exception in thread "main" java.lang.NoClassDefFoundError: Bootclasspath (wrong name: package1/Bootclasspath).

    total code for Bootclasspath below:

    package package1; 
    public class Bootclasspath {
     
    		public static void callBootClass()
    		{
    		System.out.println(System.getProperty("sun.boot.class.path"));
    		}
    public static void main(String[] args) {
        callBootClass();
        }
    }

    Thanks again. Cheers.

    Space Monkey, off to see my Space Daughter, back not so soon.

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    I did not say to execute the Bootclasspath program. That will require setting the classpath.
    You were to execute the FixChap5 program the same way you did it before.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Member
    Join Date
    Feb 2011
    Location
    Pittsburgh
    Posts
    62
    My Mood
    Angelic
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    Dear Norm;

    In the FixChap5 class:

    The two lines of code that referenced the Bootclasspath.class. are now they are causing problems, because it can not find the method from the Bootclasspath.

    Without the referenced to Bootclasspath class it works fine.

    Cheers

    SpaceMonkey

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    Please post the full text of the error messages.
    If you don't understand my answer, don't ignore it, ask a question.

  25. #25
    Member
    Join Date
    Feb 2011
    Location
    Pittsburgh
    Posts
    62
    My Mood
    Angelic
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Default Re: How to referenc a class file. using only notepad and run cmd.

    cannot find symbol:
    symbol : variable Bootclasspath
    location class FixChap5
    Bootclasspath.callBootClass();

    Again I had put // before this line of code because I know it is going to shit the bed.

    Cheers.

    SpaceMonkey.

Page 1 of 3 123 LastLast

Similar Threads

  1. making a notepad with java netbeans
    By tobioleye in forum Member Introductions
    Replies: 1
    Last Post: May 10th, 2011, 07:46 AM
  2. Ok, Notepad class has returned!
    By javapenguin in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 1st, 2011, 09:50 PM
  3. Replies: 5
    Last Post: November 13th, 2010, 01:53 PM
  4. notepad as backend database
    By chinni in forum JDBC & Databases
    Replies: 0
    Last Post: October 21st, 2009, 01:48 AM