Open Source Technical Information: How to Install JDK 7 in windows

Thursday 1 March 2012

How to Install JDK 7 in windows

,


How to Install JDK 7

Java Development Kit (JDK) 1.7 (officially named Java SE 7), which is freely available from Sun Microsystems (now part of Oracle), is needed for writing Java programs. JDK can be downloaded from the Java mother site @ http://java.sun.com (or http://www.oracle.com/technetwork/java/index.html).

1.  How To Install JDK

JDK or JRE?
JRE (Java Runtime) is needed for running Java programs. JDK (Java Development Kit), which includes JRE plus the development tools (such as compiler and debugger), is need for writing Java programs. Since you are supposed to write Java Programs, install JDK (which includes JRE).
STEP 0: Un-install Older Version of JDK/JRE
If you have previously installed older version of JDK/JRE, un-install them. Run "Control Panel" ⇒ "Program and Features" ⇒ Un-install programs such as "Java SE Development Kit" and "Java SE Runtime". (If you are not sure whether you have older versions of JDK, check!)
STEP 1: Download JDK
  1. Goto Java SE download site @ http://www.oracle.com/technetwork/java/javase/downloads/index.html.
  2. Click the "Download" button under "JDK" of "Java SE 7".
  3. Choose your operating platform, e.g., Windows x86 (for 32-bit Windows OS - "jdk-7u2-windows-i586.exe" 84MB); or Windows x64 (for 64-bit Windows OS).
(For Mac Users Only) Download JDK from http://developer.apple.com/java/download/ and follow the instructions to install (or google "how to install JDK on Mac").
STEP 2: Install JDK/JRE
Run the downloaded installer, which installs both the JDK (Java Development Kit) and JRE (Java Runtime). By default, the JDK and JRE will be installed into directories "C:\Program Files\java\jdk1.7.0" and "C:\Program Files\java\jre7", respectively. For novices, accept the defaults.
I shall refer to the JDK installed directory as <JAVA_HOME>, hereafter, in this article.
(For Advanced Users Only)
  • The default JDK/JRE directories work but I recommend avoiding "Program Files" directory because of that blank character in the directory name. You may change the installed directories for JDK and JRE during installation. I personally installed JDK and all my programming tools in "d:\bin" (instead of "C:\Program Files") for ease of maintenance.
  • It is always cleaner to un-install all the out-dated JDK/JRE before installing a new version.
STEP 3: Include JDK's "bin" directory in the PATH
Windows Operating System searches the current directory and the directories listed in the PATH environment variable for executable programs invoked from the CMD shell. JDK's programs (such as compiler javac.exe and runtime java.exe) reside in directory "<JAVA_HOME>\bin" (where <JAVA_HOME> denotes the JDK installed directory you have chosen in the previous step). You need to include the "<JAVA_HOME>\bin" directory in the PATH environment variable.
To edit the PATH environment variable in Windows 2000/XP/Vista/7:
  1. Click the "Start" button ⇒ "Control Panel" ⇒ "System" ⇒ (Vista/7 only) "Advanced system settings".
  2. Switch to "Advanced" tab ⇒ "Environment Variables..."
  3. In "System Variables" box, scroll down to select "PATH" ⇒ "Edit..."
  4. In "Variable value" field, INSERT "c:\Program Files\java\jdk1.7.0\bin" (assume that this is your JDK's binary directory) IN FRONT of all the existing directories, followed by a semi-colon (;) which separates the JDK's binary directory from the rest of the existing directories. DO NOT DELETE any existing entries; otherwise, some existing applications may not run.
    Variable name  : PATH
    Variable value : c:\Program Files\java\jdk1.7.0\bin;....exiting entries....
    
(For Advanced Users Only) I suggested that you place the JDK binary directory in front of "c:\windows\system32" and "c:\windows". This is because some Windows systems may have an out-dated copy of JDK/JRE in these directories. Do a search for "java.exe", and you will be amazed of the findings.
You could read "Java Applications and Environment Variable" for more discussions about PATH environment variable.
(For Mac and Linux Users Only) You can set the environment variables JAVA_HOME and PATH in your .profile or .bashrc or .bash_profile (under your home directory $HOME) by including the following commands:
export JAVA_HOME=path_to_JDK_directory
export PATH=$JAVA_HOME/bin:$PATH
For Mac OS X, the path_to_JDK_directory is probably /Library/Java/Home. For Linux (Ubuntu), it is probably /usr/lib/jvm/java-7-xxx.
STEP 4: Verify the JDK Installation
Launch a CMD shell (click the "Start" button ⇒ run... ⇒ enter "cmd"), and
  1. Issue a "path" command to list the content of the PATH environment variable. Check the output and make sure that <JAVA_HOME>\bin is listed in the PATH.
    prompt> path
    PATH=c:\Program Files\java\jdk1.7.0\bin;......other entries......
  2. Issue the following commands to verify that JDK is properly installed and display its version:
    prompt> java -version
    java version "1.7.0"
    Java(TM) SE Runtime Environment (build 1.7.0-b147)
    Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)
    prompt> javac
    Usage: javac <options> <source files>
    .........
    .........
STEP 5: Compile & Run a Java Hello-world Program
Read "Writing your First Java Program with JDK and a Programming Text Editor".
"Everything that can possibly go wrong will go wrong": Read "JDK Installation Common Errors".
STEP 6: Download JDK API Documentation
The JDK download does not include the documentation, which needs to be downloaded separately. In the past, I always insist that my students should have a local copy of JDK API Documentation. But, today, you can easily access the online copy by googling "JDK 7 Documentation".
To install JDK API documentation:
  1. From the Java SE download page (@ http://www.oracle.com/technetwork/java/javase/downloads/index.html), look for "Java SE 7 Documentation" (under "Additional Resources") ⇒ Download the zip-file (e.g., "jdk-7....zip" - about 57MB).
  2. Unzip into the <JAVA_HOME> (JDK installed directory). The documentation will be unzipped into "<$JAVA_HOME>\docs". Browse the JDK documentation by opening "<JAVA_HOME>\docs\index.html".
STEP 7: (For Advanced Users Only) JDK's Source Code
Source code for JDK is provided and kept in "<JAVA_HOME>\src.zip". I strongly recommend that you to go through some of the source files such as "String.java", "Math.java", and "Integer.java", under "java\lang".

2.  Using External JAR files and Native Libraries In JDK (For Advanced Users Only)

External Java packages (such as JOGL, JUnit) are often distributed in JAR-files together with possibly native libraries (lib, dll). To use an external package in JDK, you need to:
  1. Include ALL the JAR-files in the CLASSPATH environment variable (e.g., classpath=.;path1\a.jar;path2\b.jar).
  2. Include the native libraries's directory in the PATH environment variable. (To be precise: The native libraries are to be kept in a directory accessible via JRE's property "java.library.path", which normally but not necessarily includes all the paths from the PATH environment variable).
If you cannot compile your program, make sure that the all the JAR files are included in the CLASSPATH. (Native libraries are not involved in the compilation.)
If you get a runtime error "java.lang.UnsatisfiedLinkError: no xxx in java.library.path". This means that JRE cannot find your native library at runtime. You could print the contents of "java.library.path" via System.out.println(System.getProperty("java.library.path")) and check whether it includes your native library's path.
You could set the native library path via the command-line option -Djava.library.path=xxx.
Alternatively, you could copy the JAR-files into JDK's extension directory at "<JDK_HOME>\jre\lib\ext", instead of using CLASSPATH; and copy all the dll's and lib's into a directory included in java.library.path.



If you found any thing wrong then pleas Let me know ...Write Your tips and suggestion in comment ... Thank you...

0 comments to “How to Install JDK 7 in windows”

Post a Comment

Write your tips here...

Deal of the Day

Advertisement here

Advertisement here