Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem compiling pgm

 
Sue Mi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I work on win xp and have written my first java pgm c:/sue/exercise/HelloWorld.java. My java s/w is in c:/j2sdk1.4.2
After writing the pgm, in the exercise directory I set path as:

set path="c:\j2sdk1.4.2\bin;c:\j2sdk1.4.2\jre\bin"

and the classpath as

set classpath="c:\j2sdk1.4.2\lib;.;c:\sue\exercise"

and tried to compile in the exercise dir, but the error message is

"javac is not recognized as an inernal or external command, operable pgm or batch file"

Can anybody help me compile my first pgm please!!!
 
Abdulla Mamuwala
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sue

I followed the following steps inorder to compile my java programs.

Step 1
Downloaded the j2sdk1.4 and unziped in a folder jdk1.4 in my "C:" drive.

Step 2
I clicked the following tabs after going to the Control Panel,
System-->Advanced-->Environmental Variables

Step 3
Now perform the following steps in the Environmental Variables dialog box

1> click New Variable
Variable Name: JAVA_HOME
Vaiable Value: c:\jdk1.4

2> double click Path
Variable Name: Path
Variable Value: c:\jdk1.4\bin
You do not need to create a new variable because the Path variable aldready exists.

I performed the above steps on Windows 2000, I think it should work fine for Windows XP too.

I am not sure whether we need to set up the Classpath, honestly. I dont know the difference between Path and Classpath.

I hope it helps
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PATH is used to locate programs that are run from the command line. In this case, it is used to find javac.exe, java.exe, and other java utilities. However the PATH variable is not only for Java's use. It can be used to run other programs easily as well, without typing the full path (all the directories and subdirectories).

On the other hand, CLASSPATH is only used by Java to locate classes that are needed. As you start writing larger programs, you will have more and more classes. Often a single program can have dozens of classes. The CLASSPATH can help locate all of them. At this point, you probably only need to add the current directory "." to the CLASSPATH.

Eventually you will learn all about packages and download third-party Java components. These will most likely need to be added to your CLASSPATH, but for now, I suggest not worrying about it too much.

Keep coding!

Layne
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12098
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that for simple programs like this, you can also try running the program with the classpath as an argument:

java -cp . HelloWorld

the "-cp ." means look in the current directory for the class file. this assumes you are in the directory where you compiled your code - i.e. the HelloWorld.class file is in the directory you're currently in.
 
Sue Mi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thx guys my first pgm worked. gives me a big boost to brush up my long forgotten (4 yrs!!) java
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by fred rosenberger:
Note that for simple programs like this, you can also try running the program with the classpath as an argument:

java -cp . HelloWorld

the "-cp ." means look in the current directory for the class file. this assumes you are in the directory where you compiled your code - i.e. the HelloWorld.class file is in the directory you're currently in.


AFAIK, the class file with main() (HelloWorld.class in this case) is automatically resolved with the current directory. The classpath helps when the main class depends on other classes as well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic