Campbell Ritchie wrote:Welcome to JavaRanch
Please don't put your files in the bin folder; leave that for java executables. If you uninstall Java to install a new version, your work will all vanish.
Create a new folder. If you are using Windows you will probably start in "my documents" when you open the command line.That will create a "java" folder where you happen to be working, move you to that "java" folder, and print its contents. At present there should be nothing there.
Use a text editor (preferably not NotePad, go for Jedit, Notepad++ or Notepad2 which can all be downloaded free) and save the .java file in that same java folder. Write dir again at the command line, then try compiling withIf that works, you need to go back and edit your CLASSPATH. Don't put your Java bin folder in the CLASSPATH. Delete it. If you have an empty CLASSPATH, then you don't need a CLASSPATH at all. If there is anything else in the CLASSPATH, add .; at the beginning.
The . means current folder. If you have no CLASSPATH set, then Java will look in the current folder anyway.
If that doesn't work, come back and ask again
Holden Cornfield wrote:Hello, I am also a beginner to Java (and to programming as a whole).
I am facing a similar problem:
I have installed JDK onto my computer and typed up code.
I set the PATH variable to C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.7.0_09\bin
So now JDK compiles my program without any problem.
But I cannot find the class file anywhere on the computer.
And when I try to run my program, JDK/JRE says the class cannot be found.
I have followed all of your advice until compiling with
javac -cp . MyFile.java
which worked.
But CLASSPATH is nowhere to be found in the list of environment variables \ system variables.
Which according to you is not a problem.
What is the problem? How do I modify where class files are saved?
Thanks for your help!
Henry Wong wrote:
Holden Cornfield wrote:Hello, I am also a beginner to Java (and to programming as a whole).
I am facing a similar problem:
I have installed JDK onto my computer and typed up code.
I set the PATH variable to C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.7.0_09\bin
So now JDK compiles my program without any problem.
But I cannot find the class file anywhere on the computer.
And when I try to run my program, JDK/JRE says the class cannot be found.
I have followed all of your advice until compiling with
javac -cp . MyFile.java
which worked.
But CLASSPATH is nowhere to be found in the list of environment variables \ system variables.
Which according to you is not a problem.
What is the problem? How do I modify where class files are saved?
Thanks for your help!
Well, from the way you compiled it, the classpath is the current directory. And the location of where the classes will be placed, is the current directory, plus the subdirectories that matches the package name of your class. So, where the classes are saved depends on the package defined in your java file.
Henry
Campbell Ritchie wrote:Tryat the command line. See what the classpath is set to. It is usually best not to set it at all, so if you get a blank so much the better.
What do you get from the dir command when in your default java folder?
Do your .java files include a package name? That might move the .class files elsewhere.
Campbell Ritchie wrote:Tryat the command line. See what the classpath is set to. It is usually best not to set it at all, so if you get a blank so much the better.
What do you get from the dir command when in your default java folder?
Do your .java files include a package name? That might move the .class files elsewhere.
Holden Cornfield wrote:
Campbell Ritchie wrote:Tryat the command line. See what the classpath is set to. It is usually best not to set it at all, so if you get a blank so much the better.
What do you get from the dir command when in your default java folder?
Do your .java files include a package name? That might move the .class files elsewhere.
Well I did that and it didn't work.
To answer your other questions:
I get C:\Users\MyName\java from the dir command, which is why I suggested changing value for QTJAVA to .;C:\Users\MyName\java (but that has not worked)
As for your last question, I'm not sure what you mean by name inclusion for .java files
The filename for my .java files are ones such as Set.java and Item.java so nothing special.
But perhaps you mean something else?
In any case, echo %CLASSPATH% shows that my classpath is set to something weird.
I included the zip file at address C:\Program Files (x68)\Java\jre6\lib\ext\QTJava.zip in attachment so you can check it out!
From what I've found, there are a bunch of random classes (APIs?) that come from god knows where.
It looks like this file is a library for exterior classes coming from this QTJava variable.
The biggest gamble will be to ask a question whose answer you know in that it will challenge your theory | www.TechAspire.blogspot.in
No, it shouldn’t. That would be a mistake. Some older versions of Java required such a classpath, but those days are long behind us.Rajdeep Biswas wrote: . . . Your CLASSPATH should something look like:
.;C:\Program Files\Java\jdk1.5.0_22\lib . . .
Campbell Ritchie wrote:
No, it shouldn’t. That would be a mistake. Some older versions of Java required such a classpath, but those days are long behind us.Rajdeep Biswas wrote: . . . Your CLASSPATH should something look like:
.;C:\Program Files\Java\jdk1.5.0_22\lib . . .
Holden Cornfield, take it easy. I was safely in the Land of Nod while you were trying all sorts of things. It can be hazardous to try too many things too quickly. You never know what sort of confusion you get into!
That classpath .;...QTJava.jar tells me that you have installed QuickTime at some time. That is notorious for setting a classpath, which can mess up all your other settings. Adding .; should, however, sort it out. The fact that your programs work when you use the -cp . option and not without makes me suspicious that there is something wrong with that classpath. Is that the system or the user classpath? Is it down as an environment variable called classpath (case‑insensitive in Windows® so might be CLASSPATH)? Does it come up as .;%QTJAVA% or similar anywhere? What happens when you use -cp .;%CLASSPATH% instead of -cp . ?
What I meant about package name is: is the first non‑comment line in the code something like package foo; ? If you have written that (it must be the first part of the .java file), then the name of the .class file will not be MyClass but foo.MyClass.
When you used the dir command inside your java folder (which you have by the way chosen a good location and name for), do the .class files appear? What messages do you get after using the javac instruction? [Normal compilation ≡ no messages at all.] Are there any subfolders inside java?
If you are working inside your java file then having . inside the classpath should sort it out without your adding your java folder to the classpath.
Holden Cornfield wrote:PS: would you still like me to perform the commands which you recommended so that we can understand why things are working now?
The biggest gamble will be to ask a question whose answer you know in that it will challenge your theory | www.TechAspire.blogspot.in
Campbell Ritchie wrote:
No, it shouldn’t. That would be a mistake. Some older versions of Java required such a classpath, but those days are long behind us.Rajdeep Biswas wrote: . . . Your CLASSPATH should something look like:
.;C:\Program Files\Java\jdk1.5.0_22\lib . . .
The biggest gamble will be to ask a question whose answer you know in that it will challenge your theory | www.TechAspire.blogspot.in
Joanne
The biggest gamble will be to ask a question whose answer you know in that it will challenge your theory | www.TechAspire.blogspot.in
Don’t knowRajdeep Biswas wrote: . . . From which version do you mean its no more required?
No. It is not necessaryIs there any registry addition that serves the purpose?
No. The path would be different, however.Further is there any difference in Windows and Unix for this?