File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Issues with checking that my JDK is configured properly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Issues with checking that my JDK is configured properly" Watch "Issues with checking that my JDK is configured properly" New topic
Author

Issues with checking that my JDK is configured properly

Scott Allen
Greenhorn

Joined: Jan 29, 2011
Posts: 5
Hi All,

I just started trying to learn Java a couple of hours ago, so I'm about as green as you're going to find. I have no other programming experience - the closest I've come is some html several years ago.

At this point, I have:
- begun reading Head First Java
- downloaded and installed Java jdk1.6.0_23
- followed the instructions on the "How to create your first Java program" page on this site
- set the JAVA_HOME and PATH environment variables as follows:
- User variables: JAVA_HOME C:\Program Files\Java\jdk1.6.0_23
- System variables: Path %JAVA_HOME%\bin; placed at the beginning of the Variable value field

So when I go to my command prompt and type in "javac" (quotations not included in my command prompt entry), I get the following:
- 'javac' is not recognized as an internal or external command, operable program or batch file
I have the same issue when I type "javac -version".

When I enter "java", it spits out a bunch of stuff that doesn't make sense to me (yet). When I enter "java -version", it says:
java version "1.6.0_23"
Java(TM) SE Runtime Environment <build 1.6.0_23-b05>
Java HotSpot(TM) Client VM (build 19.0-b09, mixed mode, sharing)

My question, then, is why am I getting the error message when I enter "javac" but not when I enter "java"? Please note that I have no clue what the difference is between "java" and "javac".

If additional information is needed in order to assist, please let me know. I'll be checking in here tomorrow morning (past my bedtime) and hopefully I'll be able to figure out what I'm doing wrong.

Thanks in advance for any and all assistance. It's kind of frustrating to hit a roadblock this early in the game, but it's important to me that I set things up properly and that I understand everything as I move forward.

Best regards,
Scott
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3054
    
  33

Scott, Welcome to JavaRanch

So once you have set your PATH variable- You need to re-enter/exit and start the command prompt. So that the environment variables are recalculated.

javac- java compiler- This is used to compile your java source files to generate the corresponding class files (files with .class extension). These class files are also called as Bytecode

java- This interprets the Bytecode and executes them- Can also be thought of as a way to launch/run your java programs.

And I am not sure why "javac" is not identified as a valid command whereas "java" is. Might be the case that when you installed the JDK it might have identifies "java" as a valid command or it might have been there even before you actually installed JDK.

JDK- Is required when you are developing java applications- it provides development tools required.
JRE- Its the Runtime environment which allows you to execute your java bytecode.


Mohamed Sanaulla | My Blog
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36499
    
  16
Mohamed Sanaulla wrote: . . . And I am not sure why "javac" is not identified as a valid command whereas "java" is. . . .
Probably because most computers have a JRE installed and in their PATH already. The JRE includes the "java" tool, so that is found, but it doesn't include "javac".
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3054
    
  33

Campbell Ritchie wrote:
Mohamed Sanaulla wrote: . . . And I am not sure why "javac" is not identified as a valid command whereas "java" is. . . .
Probably because most computers have a JRE installed and in their PATH already. The JRE includes the "java" tool, so that is found, but it doesn't include "javac".


Yeah that was what I thought initially. But the java version was similar to the one OP had installed. Might be this is a coincidence.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36499
    
  16
You would install "java" and "javac" together, in which case the command line would have found both if they were in the same path.

The other possibility is that Scott Allen has mistakenly downloaded a JRE instead of a JDK. Please check. It is easily done. You should be able to tell from the name or size (JDK ≅ 76MB, JRE ≅ 16MB) of the file it was installed from.
Scott Allen
Greenhorn

Joined: Jan 29, 2011
Posts: 5
Thanks so much for the assistance - I'll get this down yet. Let me address the responses thus far:

"So once you have set your PATH variable- You need to re-enter/exit and start the command prompt. So that the environment variables are recalculated."

- I did this, but it didn't make any difference.

"The other possibility is that Scott Allen has mistakenly downloaded a JRE instead of a JDK. Please check. It is easily done. You should be able to tell from the name or size (JDK ≅ 76MB, JRE ≅ 16MB) of the file it was installed from."

- I double-checked, and I definitely downloaded the following:
Java SE Development Kit 6u23 (jdk-6u23-windows-i586.exe), 76.3 MB

Thanks!
Scott
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36499
    
  16
Open the C:\Program Files\Java\jdk1.6.0_23\bin directory, and confirm that the javac.exe file is in it. The name of the folder looks correct to me.
Scott Allen
Greenhorn

Joined: Jan 29, 2011
Posts: 5
Confirmed. C:\Program Files\Java\jdk1.6.0_23\bin contains javac.exe.

Thanks,
Scott
Joydeep Ghatak
Ranch Hand

Joined: Sep 30, 2009
Posts: 41

Hi Scott,

please try the following,

1. Put the path as: C:\Program Files\Java\jdk1.6.0_23\bin; [ I mean the complete path where JDK is installed in your machine] at the beginning of the PATH environment variable, instead of using through JAVA_HOME, initailly

2. Then open a new command prompt window to check the 'java' and 'javac' command.

3. Also please check the 'Java' version that you have downloaded is for 32 bit or 64 bit and what is the architecture of your machine.

4. Also as per your post, you have set the 'JAVA_HOME' as 'User variables' and PATH is present in 'System variables' section.
I am not sure if there is any specific reason for you to put 'JAVA_HOME' as 'User variables', but my suggestion will be to put both JAVA_HOME and PATH under 'System variables' section.


Thanks,
Joydeep


“Men are only as good as their technical development allows them to be.”
Scott Allen
Greenhorn

Joined: Jan 29, 2011
Posts: 5
Joydeep Ghatak wrote:

1. Put the path as: C:\Program Files\Java\jdk1.6.0_23\bin; [ I mean the complete path where JDK is installed in your machine] at the beginning of the PATH environment variable, instead of using through JAVA_HOME, initailly

2. Then open a new command prompt window to check the 'java' and 'javac' command.

3. Also please check the 'Java' version that you have downloaded is for 32 bit or 64 bit and what is the architecture of your machine.

4. Also as per your post, you have set the 'JAVA_HOME' as 'User variables' and PATH is present in 'System variables' section.
I am not sure if there is any specific reason for you to put 'JAVA_HOME' as 'User variables', but my suggestion will be to put both JAVA_HOME and PATH under 'System variables' section.


OK - looks like we have a winner.

1. Done.
2. I did this and it now works - when I enter javac -version as a command prompt, it returns
javac 1.6.0_23. javac appears to return non-error related information that I'll understand at some point in the near future
3. 32 bit was downloaded, system has been confirmed as 32 bit as well.
4. The tutorial on creating your first Java program stated:
"You can set environment variables for either your user only, or for all users (System variables)". Per your recommendation, I went ahead and moved this to the System variables. All functionality seems to still work after this change.

Everything seems to be working now, but I'm sure I'll be back in the near future with more stuff I can't figure out.


Scott
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36499
    
  16
I never realised you can have that problem if JAVA_HOME is a user variable and PATH a system variable.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36499
    
  16
I have added a warning to the FAQ against using a user JAVA_HOME and a system PATH.
Scott Allen
Greenhorn

Joined: Jan 29, 2011
Posts: 5
Campbell Ritchie wrote:I have added a warning to the FAQ against using a user JAVA_HOME and a system PATH.


Thanks! I, for one, am both grateful for the assistance I received as well as to find out that I didn't just make some stupid mistake.

Scott
Joydeep Ghatak
Ranch Hand

Joined: Sep 30, 2009
Posts: 41

Hi Scott,

Its good to know that, your problem got resolved

Also, Thanks Ritchie, for adding the information in FAQ.

Thanks,
Joydeep
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36499
    
  16
nithiy arunagiri,
Your post was moved to a new topic.
manasi belhe
Greenhorn

Joined: Jun 21, 2011
Posts: 3
hi... i am very much new to java and i am facing the exact same problem that Scott had... i have tried everything that you guys suggested but it still does not work. whether i type 'java-version' or 'javac-version' i get that it is not recognized as an internal or external command, operable program or batch file.
i do get something complicated when i type just java.
please help me out.. i have just started and it is sad to stumble on my first step....
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36499
    
  16
Welcome to the Ranch

Please tell us what you get if you write "java" and also show us your PATH environment variable. As stated earlier in this thread, you usually have another java in the operating system, which you are obviously picking up with the "java" command. The error message you are suffering from "javac" almost always means you haven't set your PATH variable. Try this Java™ Tutorials page.
manasi belhe
Greenhorn

Joined: Jun 21, 2011
Posts: 3
ok... i get this when i type just 'java' :

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

... i dont understand what this actually means.

and the path environment variable is
C:\Program Files\PC Connectivity Solution\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Java\jdk1.6.0_17;C:\Java\jdk1.6.0_17\bin;C:\glassfishv3\glassfish;C:\glassfishv3\glassfish\bin;D:\mysql\bin;D:\softwares.

well actually java was installed in my computer earlier by my brother. i was just trying to run a program in java... but i dont know what my brother has done to the path variable its way to much longer... and he is not around to tell me... and when i tried to check whether java is configured or not i got the errors as explained in previous message.

so is java actually configured or not?
Ove Lindström
Ranch Hand

Joined: Mar 10, 2008
Posts: 326

It should be. The message you get is the java commands way of saying "yes, I heard that you yelled at me, but what do you really want me to do".

If I would just say "Manasi, could you", how would you react?

If I say "Manasi, could you tell me your version number", that would be easier for you to execute (= java -version). Right? You need to tell your java command WHAT to do. Not only to do.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36499
    
  16
What that means is that you are supposed to put the name of a class after the java command. This is a simple example of how you usually compile and run a Java™ class:
javac MyClass.java
java Myclass
manasi belhe
Greenhorn

Joined: Jun 21, 2011
Posts: 3
hmm... ok i understand now... thanks....
but i was trying the MooseGreetings program from the tutorial and there is a small problem
the program runs and i get the mooooooooooo output as well but it was given in the tutorial about the classpath command...

this is what was expected:
C:\java\src>java classpath . MooseGreetings
mooooooooooo

but i got this:
C:\Java\src>javac MooseGreetings.java
C:\Java\src>java MooseGreetings
mooooooooooo
C:\Java\src>java classpath.MooseGreetings
Exception in thread "main" java.lang.NoClassDefFoundError: classpath/MooseGreetings
Caused by: java.lang.ClassNotFoundException: classpath.MooseGreetings
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: classpath.MooseGreetings. Program will exit.

i mean i get the moooooooo which means the program is getting compiled but why am i getting this error about classpath?
actually i am really not sure what does the classpath command do?

p.s. this may be a stupid question but i am very much new to java and i have just started.... thank you so much for helping me... i may come up with even stupider questions but please help me out..
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36499
    
  16
If you don't have spaces around the . the java tool will think there is one token and you are trying to find a class called classpath.MooseGreetings.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36499
    
  16
You don't need a classpath option in this example.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36499
    
  16
James Skene,
Your post was moved to a new topic.
Jean Deschamps
Greenhorn

Joined: Oct 14, 2011
Posts: 1
Scott Allen wrote:Confirmed. C:\Program Files\Java\jdk1.6.0_23\bin contains javac.exe.

Thanks,
Scott


Hello, I am having the probelm Scott had as well. I have followed the advice thus far and when I get to this direction I see that I have a javac file in my bin folder, but it does not have a .exe in the name. When I click on its properties I see that it is infact an .exe file but this does not show up in the actual name. can you offer me any help?

Thanks,

Jean
Madhushree Lakshman
Greenhorn

Joined: Mar 19, 2012
Posts: 4
Hi Everyone,

I have just started to learn Java. So with the help of JAVA Beginner's FAQs, i downloaded the latest version of Java
platform Standard Edition which is jdk1.7.0_3 (jdk-7u3-windows-i586). I installed it into my F drive.

Now for setting the JAVA_HOME and path Environment variables, i had done the following

-User Variable:JAVA_HOME
-User Value:F:\Program Files\Java\jdk1.7.0_3

Editing the System variable 'Path',
-System Value:%JAVA_HOME%\bin;

Now i restart the system.

For this in the command prompt, if i typed either java, javac, javac-version, i get the response as
"'java' is not recognized as an internal or external command, operable program or batch file."

Then after reading the discussion about not setting both user JAVA_HOME and a system PATH, i changed only the System
variable 'Path' value to

F:\Program Files\Java\jdk1.7.0_3\bin;

But still i'm getting the same result despite of trying in different ways of putting these values, as learnt from the
discussions. I dont know where i'm going wrong. Please Help Me!
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Check this FAQ - SettingJavahomeAndPath
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36499
    
  16
You should read the rest of that FAQ; it’s good.

And welcome to the Ranch
Madhushree Lakshman
Greenhorn

Joined: Mar 19, 2012
Posts: 4
@John Jai: Ya..i started out setting the environment variables using the same FAQ. When it did not work, i searched for the same in the forum and tried different things mentioned in them but, all in vain.

@Campbell Ritchie: Thanks I read the remaining part and tried to compile and execute my first java program.
At the command prompt, i went to the directory where i have saved the MooseGreetings.java file, typed "javac MooseGreetings.java", and Entered. The file did not compile. I got the same reply that "JAVAC is not recognised as an internal or external command, operable program or batch file."
Interestingly a file called "JAVA" has been created by this in my 'src' directory instead of the required "MooseGreetings.class" file. I dont know what it does!
Further, i tried to execute it by using the "java -classpath . MooseGreetings" command although, i know it should be compiled first.. Then again its showing the same message as above.

What should i do?? Should i try uninstalling the application and then Re-install?

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36499
    
  16
Do you mean javac or JAVAC? How did you set the PATH? If you have been trying “different things”, you have probably done them incorrectly.
Madhushree Lakshman
Greenhorn

Joined: Mar 19, 2012
Posts: 4
It is 'JAVAC'. Start>Control Panel>System>Advanced System Settings>Advanced>Environment Variables>

-User Variable:JAVA_HOME
-User Value:F:\Program Files\Java\jdk1.7.0_3

-System Value:%JAVA_HOME%\bin;

As it did not work i tried this.
Only System variable 'Path' value to

F:\Program Files\Java\jdk1.7.0_3\bin;
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36499
    
  16
You didn’t read the FAQ very well. It says you should not use a user JAVA_HOME to set a system PATH. If you are setting PATH as a system variable, set JAVA_HOME as a system variable too.
And if you wrote JAVAC, that won’t work well because the program is called javac.
Madhushree Lakshman
Greenhorn

Joined: Mar 19, 2012
Posts: 4
Okay.. Thank you so much. I'll post about my progress again.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36499
    
  16
darren taylor,
Your post was moved to a new topic.
Pondurai Singh
Ranch Hand

Joined: Jun 27, 2011
Posts: 35
For setting PATH environment variables
How to create your first Java program -JavaRange

You will probably have to open a new command line or terminal window to use the updated PATH; the old window usually uses the old PATH environment variable.

Windows XP
  • Start/Settings/Control Panel.
  • Double-click System, and select the Advanced tab.
  • Click the Environment Variables button.
  • You can set environment variables for either your user only, or for all users (System variables). But don't set a user JAVA_HOME and a system PATH (see this discussion). Add a new variable in either of them by clicking the New button.
  • Set the variable name as JAVA_HOME, and its value to the directory where you installed the JDK (e.g. C:\java\jdk1.6.0_21)
  • Click OK.
  • Look for a variable called PATH (the name might slightly vary, for example 'Path'). Select it and click Edit. At the beginning of its value, add the following : "%JAVA_HOME%\bin;" (without the double quotations). Don't forget the semi-colon at the end, to separate this directory to the other directories already in the path.
  • Click OK and close all remaining windows.


  • Windows Vista / Windows 7
  • Start/Control Panel.
  • Double-click System, and select "Advanced system settings" on the left.
  • On the "Advanced" tab, click the Environment Variables button.
  • You can set environment variables for either your user only, or for all users (System variables). But don't set a user JAVA_HOME and a system PATH (see this discussion). Add a new variable in either of them by clicking the New button.
  • Set the variable name as JAVA_HOME, and its value to the directory where you installed the JDK (e.g. C:\java\jdk1.6.0_21)
  • Click OK.
  • Look for a variable called PATH (the name might slightly vary, for example 'Path'). Select it and click Edit. At the beginning of its value, add the following : "%JAVA_HOME%\bin;" (without the double quotations). Don't forget the semi-colon at the end, to separate this directory to the other directories already in the path.
  • Click OK and close all remaining windows.

  • On Windows 7 it may be necessary to reboot your PC before the new environment variables are recognised.


    Software Developer, Oracle Java Certification Training Labs at EPractize Labs.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Issues with checking that my JDK is configured properly
     
    Similar Threads
    JDK 7u3 : problem checking configured properly
    'javac' is not recognized as an operable program or batch file
    'javac' is not recognized | Special case
    Java\bin PATH setup
    Trouble installing JDK 7