• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Wrong version appearing for "java" command

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am a novice to coding and very new to Java. It appears that I am having a similar problem as the user above "Scott Allen". With a few exceptions.

My issue is that when I run the command "javac" from the command prompt I am receiving the same error:
- "javac is not recognized as an internal or external command, operable program or batch file"

After reading the comments from above I have configured my System Variables "Path" and "JAVA_HOME" to match the following:
JAVA_HOME: C:\Program Files\Java\jdk1.6.0_21\bin
Path: %JAVA_HOME%\bin; [First Variable]

There is no "Path" User variable on my computer, although there is a "TEMP" and "TMP" in the User Environment variables.

Currently I have the following Java related software installed:
- C:\Program Files\Java\jre6
- C:\Program Files\Java\jdk1.6.0_21
- C:\Program Files\Sun\JavaDB
- C:\Program Files\Eclipse-jee-galileo-3.5.2

I have confirmed the "javac.exe" is located within the \bin directory of Java\jdk.1.6.0_21

When I send "Java -version" to the command prompt the following is returned:
java version "1.6.0_26"

Immediately I noticed that the version is wrong, but don't know why or what to do.

Below is the output from the command "Java" using the command prompt.

Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)

where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.

-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image



Any help you can render would be very appreciated.

Thank you.
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi James,
There could be two reasons:
1. The javac command returns error since the javac executable path is not recognized by the OS. Correct your java home path to C:\Program Files\Java\jdk1.6.0_21 (remove the \bin)
2. The java command returns a different version because it refers to the java installed which comes along with the OS. I hope you have given your custom path installation as the First variable as you mentioned in the Path. But it might look into C:\Program Files\Java\jdk1.6.0_21\bin\bin based on the java home you have configured.

and Welcome to the Ranch

 
Marshal
Posts: 80739
485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The error message you got from "java" alone is a subset of the help menu; you always get that if you miss out the options and class name. By the way: the instruction is "java" not "Java". And you appear to be asking a new question on an old thread, so I shall create a new thread.
 
James Skene
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your response.

I have followed the advice from the previous recommendation.

1. The javac command returns error since the javac executable path is not recognized by the OS. Correct your java home path to C:\Program Files\Java\jdk1.6.0_21 (remove the \bin)
2. The java command returns a different version because it refers to the java installed which comes along with the OS. I hope you have given your custom path installation as the First variable as you mentioned in the Path. But it might look into C:\Program Files\Java\jdk1.6.0_21\bin\bin based on the java home you have configured.



After making these changes my System Environment Variables are as follows.

NOTE: The "Path" variable supplied is my complete "Path" for reference.

JAVA_HOME - C:\Program Files\Java\jdk1.6.0_21\
Path - %JAVA_HOME%\bin;C:\Python27\;C:\Python27\Scripts;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Intel\DMIX;c:\Program Files\Intel\WiFi\bin\;c:\Program Files\Common Files\Roxio Shared\DLLShared\;c:\Program Files\Common Files\Roxio Shared\10.0\DLLShared\;c:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\WINDOWS\system32\WindowsPowerShell\v1.0;C:\Program Files\jEdit;C:\Program Files\BillQuick2010\;C:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\QuickTime\QTSystem\

After making these changes and running the "java" command I receive the same message as above.

I am unfortunately still receiving
the same error when running the "javac" command.

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



As a side note I am running Windows XP SP3.

If I have made an error somewhere please let me know.

Thanks again.
 
Campbell Ritchie
Marshal
Posts: 80739
485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you close the command line and re-open it? The new PATH only works on a new command line.

You are supposed to call the name of a class after "java". You are supposed to write a class or several classes. Let's put all those classes in the same directory, not in Program Files or similar, navigate to that directory with the command line, and then compile the class which has the main() method in. Let's not put any package names in any of the classes (at this early stage). Now what happens is that the "javac" command recursively finds files in the same directory and compiles them. Let's say your class with the main method is called Foo.

javac Foo.java
java Foo

Note the second time, you miss out the file extension.

What appears to be happening is that you are getting a "javac is not recognised..." message for that first instruction (if all goes well, you get no "success" messages, only stony silence from the compiler). Your PATH looks all right to me, but it is worth exploring that jdk1.6.0_21 folder with Windows Explorer. You should find that folder contains a "bin" folder, and you should find the "javac.exe" file inside that "bin" folder. If you don't find that, try a search for it.

When you execute the second command, you will either get the class running, or a message like "Exception ... ClassNotFoundException ..." If that happens, then your "java" command has worked, but there was nothing compiled for it to use.

We have an FAQ which tells you about setting up the PATH. The setting-up process varies slightly from one version of Windows® to another, but the PATH can look the same for all versions.
Try removing the last \ from your JAVA_HOME variable. You might be getting ...jdk1.6.0_21\\bin in your PATH.

Please try those suggestions and tell us what happens.
 
James Skene
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell,

OK, so as a first step I understand you are recommending the following.

Moving:
C:\Program files\Java\ containing the following sub-directories:
jdk1.6.0_21
jre6
src

To the following location:
C:\Java

Question: Will this cause any errors due to dependencies?
- Other than obviously I will need to change my Path and JAVA_HOME variable again.

Also I will change:
JAVA_HOME - C:\Program Files\Java\jdk1.6.0_21\
To:
JAVA_HOME - C:\Java\jdk1.6.0_21 (after the files have been moved to the new parent directory, note the '\' removal)

Anything else??
 
Campbell Ritchie
Marshal
Posts: 80739
485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Skene wrote:Campbell,

OK, so as a first step I understand you are recommending the following.

Moving:
C:\Program files\Java\ containing the following sub-directories:
jdk1.6.0_21
jre6
src

To the following location:
C:\Java . . .

No, not at all. Leave those directories unchanged, but check where the "javac.exe" file is. Make sure you haven't got any of your own work in those directories, otherwise it may mysteriously vanish if you uninstall and reinstall Java.
 
Campbell Ritchie
Marshal
Posts: 80739
485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Skene wrote:Campbell,

. . . I will change:
JAVA_HOME - C:\Program Files\Java\jdk1.6.0_21\
To:
JAVA_HOME - C:\Java\jdk1.6.0_21 (after the files have been moved to the new parent directory, note the '\' removal) . . .

Yes, try that. You will see there was no final \ in the JAVA_HOME in the FAQ I showed you earlier.
 
Campbell Ritchie
Marshal
Posts: 80739
485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Skene wrote:Campbell,

. . .

Anything else??

Do as little as possible at a time. The fewer changes you make, the less risk there is of damaging something.

But you will most probably have to close and re-open the command line.
 
James Skene
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell,

So throughout today I had made the changes that you suggested, however the output from the command line was presenting the same error.

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



However, I restarted the computer after receiving the errror and this has seemed to provide a solution. The test below is the output I now receive from a command prompt "javac" command from the C:\documents and settings\user>javac shell.

Usage: javac <options> <source files>
Where possible options include:
-g Generate all bugging info
-g:none Generate no bugging info
-g:{lines, vars, source} Generate only some bugging info
Etc....



Please let me know if this is the output that I should be receiving.

Thanks for all your help.
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is shell here? If it's a java file, then the usage of javac command will be javac shell.java and not javac shell as you have tried.
 
James Skene
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello John,

In the example above I used the term "shell" in reference to accessing the "javac" command from the command prompt, without any arguments, or file access.

As in (using the command prompt):
C:\>javac

The output after using this command is what I reported above, although I truncated the output for readability.

My question refers to whether this is an expected output, or if I should be expecting another output which is not occurring.

Thanks for your help.
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The output is the help command on how to use javac. So now the javac command is working perfectly, you should try compiling java classes and run them using the java command.
 
James Skene
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell and John,

Since my last post I have been working on some Java tutorials and using the javac command to compile all the files to classes. Looks like the compile issue has be solved.

One thing to note:
- I did restart my command prompt many times. After reading previous comments and listening to your recommendations I knew that this could be a problem. However it took my restarting the OS for the Path and JAVA_HOME variables to take effect.

The version reported using the "java -version" command is returning the correct version of my JDK as well.

Thank you for all your help, I am sure to have more questions and will definitely be coming back. Once I have some knowledge to provide I'll work to repay the help with other newbies.

:beerchug:
 
Campbell Ritchie
Marshal
Posts: 80739
485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,

I had a similar problem and adding JAVA_HOME var in front of PATH variable resolves the problem actually.

Thanks to everyone!

Regs,
Senthil
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This may be helpful for understanding the issue and its fixes: There is another java.exe in the System folder on Windows systems
Confer http://stackoverflow.com/a/13734429/1143126
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic