Forums Register Login
How do I change the path environment?
Hi - I'm a newbie using the Head First Java book. I've been trying to follow the instructions on the book on how to change the path, but they are not very helpful. Someone else posted the same question and I tried that, but it didn't work either.

I am using XP home edition. I downloaded the J2SDK from Sun�s website. I created a new folder on my desktop called java and saved the following code with .java extension:

public class MyFirstApp{

public static void main (String[] args){
System.out.println("I Rule!");
System.out.println("The World");


How do change the path and get it to compile? Please help!
You can change it permanently in Start / Settings / Control Panel / System / Advanced / Environment Variables.

I have a bunch of different JREs installed and don't dare mess with permanent stuff because it might mess up my work life, so I prefer to set the path right before starting the program. I have batch files like:

Once that gets going, your next question is likely to be about classpath. The answer is the same right before the Java command:
I went to Start / Settings / Control Panel / System / Advanced / Environment Variables and added "C:\Program Files\Java\jdk1.5.0_04\bin" Is there anything else I should do?
set classpath some.jar;%classpath%

instead of this if i use than

set classpath some.jar;.
is it correct
Adding the bin dir to the path will make it so you can open a command window and type "java" or "javac" and those programs will run. That's a critical step for sure.

When you run your program it might say it cannot find classes that you imported from various places. That means the compiler knew the classpath to those classes and the runtime did not. If and when this happens, you'll need to add the path to those classes to your classpath.

I showed "set classpath = some.jar;%classpath%" because the classpath might already have some good things in it. This puts my new things in the front but preserves anything already there. If I have to add several things to the classpath I just have more commands in that format.

You could set up classpath permanently as well, but it's really something that changes depending on the program you're running, so it makes more sense to set it up every time you run.

I'm working my way through HFJ aswell. I added two lines to autoexec.bat


This worked for me although this is only my second week as a would be Java programmer.
Thanks for all the help guys!

But know everytime I try to run the class i get the following error:

Exception in tread "main" java.lang.NoClassDefFoundError

I am trying to run:

public class MyFirstApp{

public static void main (String[] args){
System.out.println("I Rule!");
System.out.println("The World");

This is the error i am getting:

You’ll find me in my office. I’ll probably be drinking. And reading this tiny ad.
Why should you try IntelliJ IDEA ?

This thread has been viewed 759 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jul 21, 2018 07:37:53.