• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 280
VI Editor C++ Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more possibility is that your HelloWorldApp.java has some other name for its public class.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic