Downloading and Installing JDK

1. JDK Versions

1.2. How To Install JDK on Windows: Steps 5-8

Step 5: Write a Hello-World Java Program

  1. Create a directory to keep your works, e.g., "d:\myProject" or "c:\myProject ". Do NOT save your works in "Desktop" or "Documents" as they are hard to locate. The directory name shall not contain blank or special characters. Use meaningful but short name as it is easier to type.
  2. Launch a programming text editor (such as TextPadNotePad++, Sublime Text, Atom). Begin with a new file and enter the following source code. Save the file as "Hello.java ", under your work directory (e.g., d:\myProject).
    /*
     * First Java program to say Hello
     */
    public class Hello {   // Save as "Hello.java" under "d:\myProject"
       public static void main(String[] args) {
          System.out.println("Hello, world!");
       }
    }

Step 6: Compile and Run the Hello-World Java Program

To compile the source code "Hello.java":

  1. Start a CMD Shell (Search ⇒ enter "cmd" ⇒ select "Command Prompt").
  2. Set the Current Drive to the drive where you saved your source file "Hello.java ".
    If you use drive "c", skip this step.
    Else if you use drive "d ", enter "d:" as follow:
  3. d:
    D:\xxx>    
  4. Set the Current Working Directory to the directory that you saved your source file via the cd  (Change Directory) command. For example, suppose that your source file is saved in directory "myProject
    cd \myProject
    D:\myProject>        
  5. Issue a dir  (List Directory) command to confirm that your source file is present in the current directory.
    dir
    ......
    xx-xxx-xx  xx:xx PM               277 Hello.java
    ......     
  6. Invoke the JDK compiler "javac " to compile the source code "Hello.java
    javac Hello.java       
    ". The compilation is successful if the command prompt returns. Otherwise, error messages would be shown. Correct the errors in your source file and re-compile. Check "Common JDK Installation Errors", if you encounter problem compiling your program.
  7. The output of the compilation is a Java class called "Hello.class ". Issue a dir (List Directory ) command again to check for the output.
    dir
    ......
    xx-xxx-xx  xx:xx PM               416 Hello.class
    xx-xxx-xx  xx:xx PM               277 Hello.java
    ......       
Java Basics_Getting Started

To run the program, invoke the Java Runtime "java
java Hello
Hello, world!

Everything that can possibly go wrong will go wrong: Read "JDK Installation Common Errors".

Step 7: (Optional) Download JDK API Documentation, Demos and Samples

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 11 Documentation".

To install JDK API documentation:

  1. From the Java SE download page (@ http://www.oracle.com/technetwork/java/javase/downloads/index.html), under "Additional Resources", look for "Java SE 11 Documentation" ⇒ Click "Download" ⇒ Check "Accept the license agreement" ⇒ Download the zip-file (e.g., "jdk-11.0.{x}_doc-all.zip " - about 50MB).
  2. Unzip into the JDK installed directory <JAVA_HOME>. The documentation will be unzipped into "<JAVA_HOME>\docs ". Browse the JDK documentation by opening "<JAVA_HOME>\docs\index.html".

You should also download the "JDK x Samples and Demos", and study these samples.


Step 8: (For Advanced Users Only) JDK's Source Code

Source code for JDK is provided and kept in "<JAVA_HOME>\lib\src.zip" (or "<JAVA_HOME>\src.zip " prior to JDK 9). 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