Sie sind auf Seite 1von 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 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).

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 latest update number) "Download JDK". Take note that JRE is needed for running Java programs, while JDK (which includes JRE) is needed for writing and running Java programs. Select your operating platform (e.g., "Windows") "Continue" Choose "jdk-6uxxwindows-i586.exe" (about 76MB).

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.6.0_xx" and "C:\Program Files\java\jre1.6.0_xx", respectively, where "xx" is the update number. For novices, accept all 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 Unixfriendly. You may change the installed directory for JDK and JRE during installation. I personally installed JDK and other programming tools in "d:\bin" (instead of "C:\Program Files") for ease of maintenance.

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). 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) "Advanced system 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 the existing 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, other applications 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 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. 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 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 its version:
C:\xxxx> java -version java version "1.6.0_18"

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 your first Java program. 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 my students to download a local copy of JDK API Documentation. But, today, you can easily access the 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 "Java SE 6 Documentation" (under "Additional Resources") "Download ZIP". You shall receive 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.

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 CMD shell (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:\program files\java\jdk1.6\bin". Otherwise, include JDK's bin directory in the PATH environment variable. Read Step 3 of "How to 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 ".".

SOLUTION First, issue a "dir" command to list the contents of the current directory, and check that it contains the class to be run (e.g., Hello.class). You need to compile the program to get the class file. If the class file is present in the current directory, start a CMD shell (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 is correct, 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 User variables) Select variable "CLASSPATH" Delete. (Delete from both the System variables and User 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 current directory (denoted by a single dot ".") in front of the existing classpaths. Read "Java Applications 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 an argument of "String[] args" (check the SPELLING carefully):
public static void main(String[] args) { ...... }

(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 in the CLASSPATH. If you get a runtime error "java.lang.UnsatisfiedLinkError: no xxx in java.library.path", which means that JRE cannot find your native library at runtime. The easier way to debug is to print out the contents of "java.library.path" via System.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 in java.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_21 Last modified: October, 2010 Feedback, comments, corrections, and errata can be sent to Chua Hock-Chuan (ehchua@ntu.edu.sg) | HOME

Das könnte Ihnen auch gefallen