@icecoolz: I wasn't talking about the PATH variable pointing to the JDK installation, but was referring to the CLASSPATH environment variable. True, if he's set the PATH to JDK, then it obviously will compile the .java file, but unless he
explicitly specifies the CLASSPATH, then it wont execute from the command line, even if its in the same directory as the .java file. Take a look at this screenshot, I removed the CLASSPATH variable from my ENV_VARS list for this example:
*img215.exs.cx/img215/7291/screenshot0lx.th.jpg
I copied the .java file and compiled it, but when I executed it without the CLASSPATH variable, it refused to run, even when it was the same directory, as confirmed by the DIR command. But the second I set the CLASSPATH, it works without a hitch. Now, I personally never use the command line, everything I do is via the Eclipse IDE, which automatically adds the -cp switch corresponding to my workspace, but I guess this is how a newbie would compile/run a Java program.
Its easier to use the -cp switch for the java.exe file or to maintain a consistent directory for all the .class files rather than creating all files helter-skelter, but I guess the newbies just dont learn all this stuff. Hmm, maybe we need to point them to a good book.
So, if our friend were to just set the CLASSPATH and stick to a single directory for his .class files, he wouldn't have had this problem. Which is why I push every newbie I find towards the Gel IDE first then towards Eclipse.
@shivi4: Please take note of our discussion. It might help you as a Java programmer. Also know that while DOS is not case-sensitive, the Java interpreter IS. So
java Shivi1
is not the same as
java shivi1
Make sure you type the exact punctuation as specified in the class name in the source code. Also, its a hard and fast rule among us programmers that you NEVER EVER start a class declaration with a capital letter, it can be only used to separate two words. There's a really long Do's-and-don'ts when it comes to naming variables, classes, objects, methods, etc. but the simple rule is that never start your classname with an uppercase letter, if you want to merge two words together, like Time and Calculation, then you should a classname like timeCalculation. These are the standard naming conventions and should be strictly adhered to if you want to maintain code readability.
Also, I dont know about EditPlus2, but the way you configure ANY IDE is to use the concept of a workspace/project. Create a new one and any self-respecting IDE will automatically use the -cp/-classpath switch to properly compile and run your files. Plus, you maintain a neat, ordered coding workbench.
You can set the CLASSPATH variable by following the steps I outlined earlier in my message, by right clicking My Computer>Properties>Advanced>Environment Variables>System Variables and then clicking New and then entering the variable name and its value, which is the directory in which you have the .class files. This works on Windows 2000/XP/2003 systems. If you have any other operating system, click Start>Run and type in msconfig and press Enter. Open the Autoexec.bat tab and click the New button and enter
set CLASSPATH=<directory of your .class files>
for example
set CLASSPATH="G:\My Documents\My Code\Java\Classes"
and then confirm it, hit Apply and OK and you should never see these problems again.
As for IDEs, I personally recommend Gel for a beginner. You can download the small, 4.3MB download from here:
*memescape.co.uk/gexperts/download.html
I highly recommend Gel from personal experience, and once you use it, you will never go back to anything else, except move to something better called Eclipse.