Thursday, 13th October 2011
Follow WikiJava on twitter now. @Wikijava

Installing the JDK

From WikiJava

Jump to: navigation, search
The author suggests:

buy this book

Installing the JDK is apparently simple, but we have to take care of few tricky points to do it properly.

It's a simple procedure, but it's important to follow it to be sure to have everything properly installed.


Contents

the article

check that it installed well

The meter we will use to verify if we have installed the JDK properly is simply to open a prompt (for example in windows XP it would be: Start -> Run, Type cmd and hit Enter) and insert the following two commands in the prompt:

  java -version
  javac -version

These two commands print out the version information of the java virtual machine and java compiler we have in our computer configured as default one.

java is the command for executing the Java Virtual Machine, the option -version tells the JVM to exit immediately after printing the version information
javacis the command for executing the Java Compiler, the option -version does the same as for java it prints the version information.

It is important that the version number is exactly the same for the JVM and the Java Compiler up to the update number (the fourth one).

The result in your machine should look like follows:

 
C:>java -version
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)

C:>javac -version
javac 1.6.0_10

As you can see the Java version I've installed on my computer is the 1.6.0_10 and I have both the JVM and the Java Compiler in the same version installed. My computer has the JDK installed properly.

Since many computers have already a JRE installed when you install the JDK it's not always straightforward to get the JVM and Java Compiler on the same version.

In the next paragraph I'll guide you to install the JDK properly.

Installing the JDK properly

Note: this procedure refers to installing the JDK on a Windows XP machine, refer to this page for installing on a Linux machine.

First of all we need to download the JDK, you can do this from this page which allows you do download several files, the one you will choose is the Java SE Development Kit (JDK) that bundles both the JDK and the JRE.

Select the best settings for your computer and select to download the Offline Installation by clicking on the link.

Once we have downloaded the JDK bundle on our hard disk we need to install it. To do so simply execute the installation file that we have downloaded. Normally all the default settings work fine. Mind that the Install the JRE checkbox is selected.

Take note of the directories to which you are installing both the JDK and the JRE, they may come useful later on if problems arise.

The third phase is to verify that the installation was successful, to do so we follow the procedure described in the previous paragraph: open a command prompt and execute the two commands

  java -version
  javac -version

If the version numbers are the same, then everything went perfect and we don't need to go any further, if the version numbers differ or the prompt said that the commands did not exist, read the next paragraph to fix your installation.

Fixing the JDK installation

It is very common that the version numbers do not match or that the javac command is not found.

The first is because very often computers have already the JRE installed and the procedure of installing the JDK does not override the configurations of the JRE.

The second is because the JDK installation doesn't configure the system to have the javac in the execution path.

Make the commands to be found

If the javac command was not found you need to follow this procedure to put the directory containing it in the execution path.

To solve this we need to add the bin directory of the JDK in the execution path.

To do so you need to find the installation directory, called home directory, of your JDK (normally it's c:\Program Files\Java\JDKw.x.y_z -where w.x.y_z is the version you installed-).

The bin directory is the subdirectory bin of the home directory. so if the home directory is C:\Program Files\Java\jdk1.6.0_10 the bin directory that we need to put in the execution path is C:\Program Files\Java\jdk1.6.0_10\bin.

Open your System Manager (Start -> Control Panel -> System) and select Advanced then hit the button environment variables.

Find in the bottom list the variable called Path and double click on it.

In the window verify that the path to your bin directory (in the example it would be the C:\Program Files\Java\jdk1.6.0_10\bin) is included in the list.

In case it was the JRE not to be found follow this same procedure but use the JRE home directory instead.

The versions are different

To fix this we need to be sure that the execution path contains the paths to the correct JRE and JDK bin directories with the same procedure explained above.

After checking that the path is set correctly we need to create a new environment variable called JAVA_HOME and point it to the JDK home directory (most often C:\Program Files\Java\jdk1.6.0_10).

Setting the JAVA_HOME environment variable solves also when you have another common problem which you may incur when starting to use the compiler. If the compiler tells you that it can't find the tools.jar file then it means that the JAVA_HOME is not set correctly.

See Also

JDK download site, install JDK under Linux

Comments from the users

To be notified via mail on the updates of this discussion you can login and click on watch at the top of the page

Java Home directory

The JAVA_HOME directory should be set to C:\Program Files\Java\jdk1.6.0_10 and not C:\Program Files\Java\jdk1.6.0_10\bin

--59.160.74.254 09:30, 10 April 2009 (UTC)


Ganesh Gowtham said ...

Thanks and blog is corrected to reflect the changes

--Ganesh.gowtham 21:24, 2 January 2010 (PST)


installation error

Hello all I am new to this java programming! And as a novice I am having troubles with installing the java on my pc. I am unable to run the javac command even after setting the environment correctly as always an error message pops out as javac is not recognized as internal or external command. kindly help me asap!

--Shreya 09:39, 22 September 2010 (PDT)


RE: installation error

Hi Shreya,

your problem seems to be related to the fact the javac.exe file is not in the path.


The Path is a list of directory names that windows searches in when you try to execute a program from the prompt. If a file with the name you typed is not present, Windows will print the message you see.

The easiest way in windows (xp) to update the path is by hitting start - control panel - system - advanced - environment variables. then search in "system variables" and double click on "path", then add a ; in the end of the string there and add in the end the path where you installed your jdk (usually C:\Program Files\Java\jdk*.*.*_*). Then click ok to save the changes, open a new "cmd" window and try again.

Hope this helps. Good luck with your learning.


--DonGiulio 01:24, 23 September 2010 (PDT)


class version error

hi.. i red the story above given by you and i follwed the same.but still i am getting the same error i.e.,"UnsupportedClassVersionError"(unsupported major.minor version 50.0).. pls help me in fixing this problem

--class version error 11:15, 12 July 2011 (PDT)


class version error

what's the problem exactly? what are you doing to see that error?

--DonGiulio 12:07, 12 July 2011 (PDT)


class version error

actually i have written a simple prog. called Hello world. When i compiled this program i am not at all getting any error it is working perfectly. But when i run this same file getting the error called "unsupportedclassversionerror(unsupported major.minor version 50.0)". in system variables i have created JAVA_HOME,path,classpath like as you said...

--class version error 10:21, 13 July 2011 (PDT)


you're using different versions of java

I believe your problem is in the fact that you are compiling (javac) with the version you recently installed following the tutorial, but you are executing (java) with the version installed in the operating system, which is previous to the javac.

A method to verify this is explained in the tutorial, in the shell type :

java -version 

and

javac -version

and verify that the two versions are different.. if they are it means that somewhere in your path you have the directory of the other java version, which I think can be removed safely.

Hope this helps,



--DonGiulio 12:39, 13 July 2011 (PDT)


class version error

exactly. those two are different versions.now i found the other version of java(jdk1.6.0_01) . but to delete/de-install this file ,i was unable to find this in control panel. if i remove directly it is giving the error that (cannot delete used by another person). give me guid lines to remove it from the system

--class version error 06:13, 14 July 2011 (PDT)


class version error

That's the java used by the system, if you remove it some of your programs could stop working.

You have to find in the %path% (I assume you use windows) the reference to the directory of the other java and remove it. This should be a safe operation.

Once that one is removed, the check above should start telling you the same versions.

alternatively, when you run the java command, you can type the whole path for it, like :

c:\directory\subdirectory\java_1.6.1\bin\java  

so you ensure you are using the right java version.

Your problem is that you have two java versions installed. these are: the one you installed, and the one that is resident in your operating system.

When you run the java command you need to be using the right one, which is the same you used when you ran javac.

Hope this helps

--DonGiulio 06:57, 14 July 2011 (PDT)


class version error

the path i know that the removed java file where it is present in the system . But the problem is i was unable to delete it . i have tried it directly to remove but giving an error and also there is no installation folder in control panel . so how can i remove it...

--class version error 07:58, 14 July 2011 (PDT)


class version error

You don't want to remove the program, you want to remove the path of the other java install, from the %PATH%. so that when you enter java [whatever] the console will execute the java version you installed, and not the one you have with the operating system.

If you deinstall that java installation you risk to break several parts of your OS. That is why it's not possible/easy to do.

Hope this helps,


--DonGiulio 08:13, 14 July 2011 (PDT)


class version error

thankyou very much for guided me

--class version error 08:22, 15 July 2011 (PDT)


Comments on wikijava are disabled now, cause excessive spam.