I am new to the world of Java programming. I downloaded the HelloWorldApp program from Oracle's website and saved it to c:\java , which is also where all my JDK and JRE files are. I ran javac and the program compiled to HelloWorldApp.class. I ran c:\java -cp . HelloWorldApp and I get the could not find the main class error. Note that I also used c:\set classpath= as has been suggested in other posts. I am stumped - can anyone help?
That will be a problem, because if you compile your classes with the compiler from JDK 7 they will not run on Java 6. You would get a different error for that though than "could not find the main class".
Make sure you set the PATH variable to include the JDK bin directory, as explained in the installation instructions for the JDK. The JDK bin directory should be in the PATH before any other directory that contains a java.exe. If you've done this correctly, your java and javac versions should match.
For your "could not find the main class" error: It's best to leave CLASSPATH not set. Java should take the current directory as the default classpath if you do that, so that you should just be able to do java HelloWorldApp to run the program (after you've compiled it, ofcourse).
Note: it's java HelloWorldApp, not java HelloWorldApp.class. The java command expects a class name, not a filename.
Also, I wouldn't save Java source files in the JDK directory. Create a separate directory somewhere else to store your own Java programs, don't mess with anything in the JDK directory.
Scott McWilliams wrote:(not sure why the old version isn't deleted automatically anyway).
You can have multiple Java versions installed on your system, in fact I have JDK 5, 6, and 7 installed on my system (for testing my code with different versions). It would be very annoying if the installer for one JDK would automatically remove the older JDKs!