Instal JDK

Embed Size (px)

Citation preview

  • 8/3/2019 Instal JDK

    1/6

    http://www.oracle.com/technetwork/java/javase/downloads/index.html

    http://www3.ntu.edu.sg/home/ehchua/programming/howto/JDK_Howto.html

    JDK 1.6

    How to Install and Get Started

    Java Development Kit (JDK) 1.6 (officially named Java SE 6.0), freely available from SunMicrosystems (now part of Oracle), is needed for writing Java programs. JDK can bedownloaded from the Java mother site @ http://java.sun.com (orhttp://www.oracle.com/technetwork/java/index.html ).

    How To Install JDK

    STEP 1: Download JDK

    Goto Java SE download site @http://www.oracle.com/technetwork/java/javase/downloads/index.html .

    Look for Java Platform, Standard Edition JDK 6 Update xx (where xx is the latestupdate number) "Download JDK ". Take note that JRE is needed for running Javaprograms, while JDK (which includes JRE) is needed for writing and running Javaprograms.

    Select your operating platform (e.g., "Windows") "Continue" Choose "jdk-6uxx-windows-i586.exe" (about 76MB).

    STEP 2: Install JDK/JRE - Run the downloaded installer, which installs both the JDK (JavaDevelopment Kit) and JRE (Java Runtime). By default, the JDK and JRE will be installed intodirectories " C:\Program Files\java\jdk1.6.0_ xx " and " C:\ProgramFiles\java\jre1.6.0_ xx ", respectively, where " xx " is the update number. For novices, acceptall the defaults.

    The JDK installed directory is hereafter denoted as $JAVA_HOME (Unix notation) or %JAVA_HOME% (Windows notation) in this writing.

    (For Advanced Users) The default JDK/JRE directories work but I recommend avoiding"Program Files " because of that blank character in the directory name which is not Unix-friendly. You may change the installed directory for JDK and JRE during installation. Ipersonally installed JDK and other programming tools in " d:\bin " (instead of " C:\ProgramFiles ") for ease of maintenance.

    http://java.sun.com/http://java.sun.com/http://java.sun.com/http://www.oracle.com/technetwork/java/index.htmlhttp://www.oracle.com/technetwork/java/index.htmlhttp://www.oracle.com/technetwork/java/javase/downloads/index.htmlhttp://www.oracle.com/technetwork/java/javase/downloads/index.htmlhttp://www.oracle.com/technetwork/java/javase/downloads/index.htmlhttp://www.oracle.com/technetwork/java/index.htmlhttp://java.sun.com/
  • 8/3/2019 Instal JDK

    2/6

    STEP 3: Include JDK's "bin" directory in the PATH - Windows Operating System searches thecurrent directory and the directories listed in the PATH environment variable for executableprograms invoked from the CMD shell. JDK's programs (such as compiler javac.exe andruntime java.exe ) reside in directory " $JAVA_HOME\bin " (where $JAVA_HOME denotes the JDKinstalled directory you have chosen in the previous step). This directory needs to be included in

    the PATH .

    To edit the PATH environment variable in Windows 2000/XP/Vista:

    Click the "Start" button "Control Panel" "System" (Vista only) "Advancedsystem settings".

    Switch to "Advanced" tab "Environment Variables..." In "System Variables" box, scroll down to select "PATH" "Edit..." In "Variable value" field, type " c:\Program Files\java\jdk1.6.0_ xx \bin " (if this is

    your installed directory, change " xx " to the actual update number) in front of all theexisting directories, followed by a semi-colon ( ; ) to separate the JDK's directory from the

    rest of the directories. DO NOT delete any existing path entries; otherwise, otherapplications may not run.For example,

    Variable name : PATH Variable value : c:\Program

    Files\java\jdk1.6.0_xx\bin;c:\windows\system32;c:\windows;...

    Read "Java Applications and Environment Variable " for more discussions about PATH environment variables.

    (For Advanced Users) I suggested that you place the JDK bin directory in front of

    "c:\windows\system32 " and " c:\windows ". This is because some Windows systems may havean out-dated copy of JDK/JRE in these directories. Do a search for " java.exe ", and you will beamazed of the findings.

    STEP 4: Verify the JDK Installation - Launch a CMDshell (click the "Start" button run... enter "cmd"), and

    1. Issue a " PATH" command to list the search paths for executable programs:

    C:\xxxx> path PATH= c:\Program Files\java\jdk1.6.0_xx\bin ;c:\windows\system32;c:\windows;...

    Check the output and make sure that $JAVA_HOME\bin is listed in the PATH .

    2. Issue the following command to check that JDK is properly installed and display itsversion:

    C:\xxxx> java -version java version "1.6.0_18"

    http://www3.ntu.edu.sg/home/ehchua/programming/howto/Environment_Variables.html#JavaEnvhttp://www3.ntu.edu.sg/home/ehchua/programming/howto/Environment_Variables.html#JavaEnvhttp://www3.ntu.edu.sg/home/ehchua/programming/howto/Environment_Variables.html#JavaEnvhttp://www3.ntu.edu.sg/home/ehchua/programming/howto/Environment_Variables.html#JavaEnv
  • 8/3/2019 Instal JDK

    3/6

    Java(TM) SE Runtime Environment (build 1.6.0_18-b07)Java HotSpot(TM) Client VM (build 16.0-b13, mixed mode, sharing)

    STEP 5: Compile & Run a Java Hello-world Program

    Read "Writing your First Java Program with JDK and a Programming Text Editor ".

    Read "Common JDK Installation Errors ", if you encounter problems compiling or running yourfirst Java program.

    STEP 6: Download JDK API Documentation - The JDK download does not include thedocumentation, which needs to be downloaded separately. In the past, I always insist mystudents to download a local copy of JDK API Documentation. But, today, you can easily accessthe online copy by googling "JDK 6 Documentation".

    To install JDK API documentation:

    From the Java SE download page (@http://www.oracle.com/technetwork/java/javase/downloads/index.html ), look for "JavaSE 6 Documentation" (under "Additional Resources") "Download ZIP". You shallreceive a zip-file (e.g., " jdk-6uxx-docs.zip " - about 56MB).

    Unzip into the JDK installed directory. The documentation will be unzipped into"$JAVA_HOME\docs " directory, where $JAVA_HOME denotes the JDK installed directory.Browse the JDK documentation by opening " $JAVA_HOME\docs\index.html ".

    STEP 7: JDK Source Code - Source code for JDK is provided and kept in"$JAVA_HOME\src.zip ". Highly recommended to go through some of the source files such as"String.java ", " Math.java ", and " Integer.java ", under " java\lang ".

    Common JDK Installation Problems

    Cannot compile Java program (e.g., javac Hello.java ) from the CMD shell

    ERROR MESSAGE

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

    http://www3.ntu.edu.sg/home/ehchua/programming/java/J0_GettingStarted.html#First_program_JDKhttp://www3.ntu.edu.sg/home/ehchua/programming/java/J0_GettingStarted.html#First_program_JDKhttp://www3.ntu.edu.sg/home/ehchua/programming/howto/JDK_Howto.html#CommonProblemhttp://www3.ntu.edu.sg/home/ehchua/programming/howto/JDK_Howto.html#CommonProblemhttp://www3.ntu.edu.sg/home/ehchua/programming/howto/JDK_Howto.html#CommonProblemhttp://www.oracle.com/technetwork/java/javase/downloads/index.htmlhttp://www.oracle.com/technetwork/java/javase/downloads/index.htmlhttp://www.oracle.com/technetwork/java/javase/downloads/index.htmlhttp://www3.ntu.edu.sg/home/ehchua/programming/howto/JDK_Howto.html#CommonProblemhttp://www3.ntu.edu.sg/home/ehchua/programming/java/J0_GettingStarted.html#First_program_JDK
  • 8/3/2019 Instal JDK

    4/6

    PROBABLE CAUSES The PATH environment variable, which maintains a list of search paths for executable programs,including " javac.exe ", does not include JDK's bin directory.

    SOLUTION

    First, start a CMDshell (click "Start" button "run..." enter "cmd") and issue a PATH command:

    > path PATH=.......

    Check if it includes your JDK's bin directory. For example, suppose that your JDK is installed in"c:\program files\java\jdk1.6 ", then PATH should include " c:\programfiles\java\jdk1.6\bin ".

    Otherwise, include JDK's bin directory in the PATH environment variable. Read Step 3 of "Howto install JDK" .

    Can compile but cannot run Java program (e.g., java Hello ) from the CMD shell

    ERROR MESSAGE

    Exception in thread "main" java.lang.NoClassDefFoundError: Hello

    PROBABLE CAUSES

    1. The class (e.g., Hello.class ) is NOT in the current directory.2. The CLASSPATH environment variable is set, but does not include the current directory

    ". ".

    http://www3.ntu.edu.sg/home/ehchua/programming/howto/JDK_Howto.html#jdk-install-step3http://www3.ntu.edu.sg/home/ehchua/programming/howto/JDK_Howto.html#jdk-install-step3http://www3.ntu.edu.sg/home/ehchua/programming/howto/JDK_Howto.html#jdk-install-step3http://www3.ntu.edu.sg/home/ehchua/programming/howto/JDK_Howto.html#jdk-install-step3http://www3.ntu.edu.sg/home/ehchua/programming/howto/JDK_Howto.html#jdk-install-step3http://www3.ntu.edu.sg/home/ehchua/programming/howto/JDK_Howto.html#jdk-install-step3
  • 8/3/2019 Instal JDK

    5/6

    SOLUTION First, issue a " dir " command to list the contents of the current directory, and check that itcontains the class to be run (e.g., Hello.class ). You need to compile the program to get theclass file.

    If the class file is present in the current directory, start a CMDshell (click "Start" button "run..".enter "cmd"), and issue a " set CLASSPATH " command to display its settings:

    > set classpath CLASSPATH=.......

    If you receive the message "Environment variable CLASSPATH not defined" and your program iscorrect, I can't help you here.

    Otherwise, if the CLASSPATH is defined, for beginner, I suggest that you remove the CLASSPATH environment variable. From "Control Panel" System (Vista only) Advanced system settings

    Switch to "Advanced" tab Environment Variables System variables (and also Uservariables) Select variable " CLASSPATH " Delete. (Delete from both the System variables andUser variables.)

    (For Advanced Users ) If CLASSPATH is set, the current directory is not implicitly included. If CLASSPATH is not set, it is defaulted to the current directory. You can include the currentdirectory (denoted by a single dot " . ") in front of the existing classpaths. Read "JavaApplications and Environment Variable " for more dicussion on CLASSPATH .

    ERROR MESSAGE Exception in thread "main" java.lang.NoSuchMethodError: main

    PROBABLE CAUSES

    1. You program does not have a main() method (check the SPELLING carefully).2. The signature of the main() method is incorrect ( public static void main(String[]

    args) { ... } ).

    SOLUTION Check that your program including a main() method with the correct signature including anargument of " String[] args" (check the SPELLING carefully):

    public static void main(String[] args) { ...... }

    http://www3.ntu.edu.sg/home/ehchua/programming/howto/Environment_Variables.html#JavaEnvhttp://www3.ntu.edu.sg/home/ehchua/programming/howto/Environment_Variables.html#JavaEnvhttp://www3.ntu.edu.sg/home/ehchua/programming/howto/Environment_Variables.html#JavaEnvhttp://www3.ntu.edu.sg/home/ehchua/programming/howto/Environment_Variables.html#JavaEnvhttp://www3.ntu.edu.sg/home/ehchua/programming/howto/Environment_Variables.html#JavaEnv
  • 8/3/2019 Instal JDK

    6/6

    (Advanced) Using External JAR files and Native Libraries In JDK

    To use external packages in JDK, you need to provide a CLASSPATH for EACH of the jar files.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 EACH of the JAR file are included inthe CLASSPATH .

    If you get a runtime error " java.lang.UnsatisfiedLinkError: no xxx injava.library.path ", which means that JRE cannot find your native library at runtime. Theeasier way to debug is to print out the contents of " java.library.path " viaSystem.out.println(System.getProperty("java.library.path")) .

    You could set the native library path via the command-line option -Djava.library.path=xxx .

    Alternatively, you could copy the JAR file into JDK's extension directory at"$JDK_HOME\jre\lib\ext ", and the dll 's and lib 's into a directory included injava.library.path .

    REFERENCES & RESOURCES

    Java mother site @ http://java.sun.com (http://www.oracle.com/technetwork/java/index.html ); Java SE mother site @

    http://java.sun.com/javase (http://www.oracle.com/technetwork/java/javase/overview/index.html ).

    JDK 6 API Documentation. Online version is available @http://download.oracle.com/javase/6/docs/ Click "Java SE 6 Documentation" link.

    Java Developers' sites, e.g., http://java.sun.com , http://java.com , http://java.net .

    Latest version tested: JDK 1.6.0_21Last modified: October, 2010

    Feedback, comments, corrections, and errata can be sent to Chua Hock-Chuan([email protected]) | HOME

    http://java.sun.com/http://java.sun.com/http://java.sun.com/http://www.oracle.com/technetwork/java/index.htmlhttp://www.oracle.com/technetwork/java/index.htmlhttp://www.oracle.com/technetwork/java/index.htmlhttp://java.sun.com/javase/http://java.sun.com/javase/http://www.oracle.com/technetwork/java/javase/overview/index.htmlhttp://www.oracle.com/technetwork/java/javase/overview/index.htmlhttp://www.oracle.com/technetwork/java/javase/overview/index.htmlhttp://download.oracle.com/javase/6/docs/http://download.oracle.com/javase/6/docs/http://java.sun.com/http://java.sun.com/http://java.sun.com/http://java.com/http://java.com/http://java.com/http://java.net/http://java.net/http://java.net/http://www3.ntu.edu.sg/home/ehchua/programming/index.htmlhttp://www3.ntu.edu.sg/home/ehchua/programming/index.htmlhttp://www3.ntu.edu.sg/home/ehchua/programming/index.htmlhttp://java.net/http://java.com/http://java.sun.com/http://download.oracle.com/javase/6/docs/http://www.oracle.com/technetwork/java/javase/overview/index.htmlhttp://java.sun.com/javase/http://www.oracle.com/technetwork/java/index.htmlhttp://java.sun.com/