Hi! Can some one explain what exactly is setting the class path . I was shown a way to run my programs , and that's how i have been doing it with out knowing why. I save my java files in the bin folder of jdk1.5.0_15 and my class file are also stored there.
Originally posted by Nabila Mohammad: ...I save my java files in the bin folder of jdk1.5.0_15 and my class file are also stored there...
This is a Bad Idea. The bin directory is for Java's "inner workings." If you add your own files there, you're headed for trouble (especially when you start cleaning things up and accidentally remove something you shouldn't). The main reason people do this is because they have not updated their PATH variable. See step 4 of Sun's installation instructions for Windows.
Originally posted by Nabila Mohammad: ...And then befor running a program(for the first time) I type
This shouldn't be needed. If no classpath is specified, then Java's default is to look for classes in the current directory. So if you're compiling from the directory that stores your class files, you should be fine.
Originally posted by Nabila Mohammad: ...Now I am trying to enable assertion which I am unable to do so.
From what I understood the code to be used is java -ea package.subpackage.TestClass.
I am not sure which package I am supposed to mention and whether I am supposed to run it from my present directory ie.bin...
Why do you say it isn't working? Is the code running at all, and just not throwing an assertion error when it should?
Note that this package configuration is a little different than what you're describing above. If the package is "package.subpackage," then the file should be in a directory called "subpackage," and "subpackage" should be in a parent directory called "package." You would then set the current directory to the parent of "package" (in your case, "bin") and compile with...
...and run with...
java -ea package.subpackage.TestClass
This should work fine with assertions using Java 5 or above. (In Java 1.4, you needed to compile using -source 1.4 for assertions to work.) [ March 20, 2008: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Nov 05, 2007
I am not sure what to do.
I set the PATH variable to bin as mentioned ie. C:\Program Files\java\jdk1.5.0_15\bin
By storing my java file in another folder(and trying to store my class file in the same folder) I cannot even compile it
Suppose I store it in "Class files" folder located in "My Documents" and try to compile MyClass.java file there, ie.
c:\Document and settings\My Documents\Class files>javac MyCLass.java
I get the error - javac is not an recognised as an internal or external command,operatble program or batch file
How am I supposed to compile a program elsewhere.
IF i am trying to run the program saved in the bin folder (like i have been doing )
And if I dont use the command : set CLASSPATH=
I get an error- NoClassDefFoundError.
I got the assertion error part. I was using packages and subpackages even when I was in the current directory. so sorted that out.
If you can please help me out with the rest. What does CLASSPATH specify and what does PATH specify..?
The PATH tells your system where to find Java executables, like javac and java. With the PATH set properly (to include the JDK's bin directory, which is where these executables are), you can simply type javac or java at the command prompt, and your system will use the PATH to make sense of these commands.
After updating your system class variable, did you open a new Command Prompt? Some operating systems even require a reboot for this to take effect.
The CLASSPATH tells Java where to find user-created Java class files. As I mentioned above, if there is no classpath specified, then Java's default is to look in the current directory.
So if your classes are in the current directory and Java can't find them, that indicates you have a system classpath set as an environment variable (so the default is not being used), and it does not include a dot (.) for the current directory.