wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes 'javac' is not recognized as an internal or external command, Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark " Watch " New topic
Author

'javac' is not recognized as an internal or external command,

Gary Ba
Ranch Hand

Joined: Oct 23, 2009
Posts: 150

Hi All,
This is my first time at javaranch.com and I am pretty new with java. I installed Java JDK 6 Update 16 under C:ProgramsFiles\Java\ on my computer (windows xp). Of course, I had to try the simple Hello World program. I set up my PATH variable on
System Properties->Advanced->Environment Variables->CLASSPATH=C:\Program Files\Java\jdk1.6.0_16\bin; I then tried to compile hello.java which is

public class hello {

public static void main (String[] args) {

System.out.println("Hello World");
}
}

using javac hello.java but it gave an error that says: 'javac' is not recognized as an internal or external command, operable program or batch file. I then tried to move the program inside the bin, compile it and it didn't give me an error. However, I couldn't find the hello.exe program to run. I then tried to break the program (take the quotation mark ") to see if the compiler will complain about it and it sure did give me a compile error on command prompt. I've also tried closing cmd window and even restarted my computer but still no luck. I've tried searching online about and it points to the PATH variable but I think I've set my path correctly.
If anyone ran into this problem or know of any other things I can try, please let me know.


Thanks,
LostSoul


star chaser..
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
John:

PATH and CLASSPATH are two different environment variables. PATH is where Windows looks for your executable file (javac). CLASSPATH is where Java looks for your classes and jar files.

John.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37926
    
  22
Welcome to JavaRanch

If you managed to get a compiler error when you took the quote mark out, you would appear to have set up your PATH correctly.
The javac command doesn't produce an .exe file. You get a .class file and (if it contains a main method) execute that main method with the command

java hello

Not .class.

I suggest next time you open your command line you execute these two commands

mkdir java
cd java

Now you have a folder to put all your java work into. Put your "hello World" files into that directory. Now using the cd java instruction whenever you open a command prompt will take you into that folder. You can obviously use a different name, make subfolders, etc. Now try java hello in that folder.

By the way: the convention is for class names to start with a capital letter.
Gary Ba
Ranch Hand

Joined: Oct 23, 2009
Posts: 150

Guys,
Thanks a bunch for the pointer. I thought about it this morning and did a little lookup on PATH and CLASSPATH. I was setting the wrong environment variable. I needed to set PATH to the write address.
I made a directory using the commands you mentioned on your reponse. I am not totally familiar with command prompt keyword yet but I will look into more of this and use command line to write small program before I switch to gui base compiler (ie eclipse).

Regards,
lostsoul
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37926
    
  22
Avoid Eclipse and other IDEs until you are a lot more experienced. You have enough to learn with Java without burdening yourself with learning the IDE too.
Gary Ba
Ranch Hand

Joined: Oct 23, 2009
Posts: 150

Hi Richie,
I have another quick question. In C++, I can use #include whenever I used a class within a class. I am wondering what is the equivalent of this in JAVA.

Thanks,
lostsoul
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: 'javac' is not recognized as an internal or external command,
 
Similar Threads
Program: Change Due/Tendered
path variable
Help with running my first program.
help me with the installation process
java on command