Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Rujitha Patel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 272
C++ Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more possibility is that your HelloWorldApp.java has some other name for its public class.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic