*
The moose likes Beginning Java and the fly likes 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 ""javac HelloWorldApp.java" not recognized, but "java -version" recognized    " Watch ""javac HelloWorldApp.java" not recognized, but "java -version" recognized    " New topic
Author

"javac HelloWorldApp.java" not recognized, but "java -version" recognized

Rujitha Patel
Greenhorn

Joined: Sep 07, 2006
Posts: 8
I have downloaded and installed Java SE version 6 update 4, as described in the Installation Instructions in the Java website.

When I run "java -version" command in the command prompt, the following message comes:

java version "1.6.0_04"
Java(TM) SE Runtime Envinronment (build 1.6.0_04-b12)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)

But when I try to compile my Java program with the command "javac HelloWorldApp.java", the following message comes:

'javac' is not recognized as an internal or external command, operable program or batch file.

Any help from anyone is greatly appreciated.

Thank you.
Anand Hariharan
Rancher

Joined: Aug 22, 2006
Posts: 257

java (without the 'c') is the byte code interpreter. This is the platform on which your java application runs.

javac is the compiler which translates your java source code to byte code.

These are two different executables.

Either you do not have the JDK installed (i.e., only the Java runtime environment, not the Java development kit), or javac for some reason, is not in the path, while java is.

- Anand


"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37945
    
  22
Originally posted by Anand Hariharan:
Either you do not have the JDK installed (i.e., only the Java runtime environment, not the Java development kit), or javac for some reason, is not in the path, while java is.
Agree. It is possible you have the JRE (Java Runtime Environment) installed and not the JDK. that would mean you can run Java but not create new programs.
If you need to download the JDK, try here: click the button nearest the top of the page. It gives you installation instructions. This part of the Java Tutorial tells you about "getting started;" note the "Common Problems" link, and at the end of "common problems" there is a link to how to set the PATH.

Good luck with it.
Rujitha Patel
Greenhorn

Joined: Sep 07, 2006
Posts: 8
Now I have reinstalled the JDK. Now, if I run the command "java -version" the following message appears:

java version "1.6.0_04"
Java(TM) SE Runtime Envinronment (build 1.6.0_04-b12)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)

If I run "javac -version" the following message appears:
javac 1.6.0_04

Now I am able to compile the HelloWorldApp.java and create the HelloWorldApp.class. But if I run the command "java HelloWorldApp" from the directory where the HellowWorldApp.class exist, I get the following message:

Exception in thread "main" java.lang.noClassDefFoundError C:\temp\HelloWorldApp
Caused by: java.lang.ClassNotFoundException.............
................................
................................

But I am very sure that the HelloWorldApp.class is in C:temp

Any help is very much appreciated.

Thank you.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

If your current directory in the Command Prompt is C:\temp, then all you need to type is...

If you are in some other directory, then you can tell java where to find the class by specifying a classpath (with the -cp flag)...

Note the space between "C:\temp" (the classpath) and "HelloWorldApp" (the class name).
[ February 25, 2008: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215

One more possibility is that your HelloWorldApp.java has some other name for its public class.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37945
    
  22
Originally posted by Balasubramanian Chandrasekaran:
One more possibility is that your HelloWorldApp.java has some other name for its public class.
Really? If you have a public top-level class with a different name from its enclosing file, it will throw a compiler error.
 
jQuery in Action, 2nd edition
 
subject: "javac HelloWorldApp.java" not recognized, but "java -version" recognized
 
Similar Threads
Problems compiling servlet
Doubt in static import
Trouble installing JDK 7
JAVAC not found ??? I cant compile - help
Issues with checking that my JDK is configured properly