How To Install JDK 8 (On Windows, Mac OS, Ubuntu) and Get Started With Java Programming
How To Install JDK 8 (On Windows, Mac OS, Ubuntu) and Get Started With Java Programming
| HOME
Java Development Kit (JDK), officially named "Java Platform Standard Edition (Java SE)", which is freely available from Sun
Microsystems (now part of Oracle), is needed for writing Java programs. The mother site for JDK (Java SE) is
http://www.oracle.com/technetwork/java/index.html.
"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 as well as running Java programs. In other words, JRE is a subset of JDK.
Since you are supposed to write Java Programs, you should install JDK, which includes JRE.
JDK Versions
The various JDK versions are:
1. JDK Alpha and Beta (1995): Sun announced Java in September 23, 1995.
2. JDK 1.0 (January 23, 1996): Originally called Oak (named after the oak tree outside James Gosling's office). Renamed to Java
1 in JDK 1.0.2.
3. JDK 1.1 (February 19, 1997): Introduced AWT event model, inner class, JavaBean, JDBC, and RMI.
4. J2SE 1.2 (JDK 1.2) (December 8, 1998): Re-branded as "Java 2" and renamed JDK to J2SE (Java 2 Standard Edition). Also
released J2EE (Java 2 Enterprise Edition) and J2ME (Java 2 Micro Edition). Included JFC (Java Foundation Classes - Swing,
Accessibility API, Java 2D, Pluggable Look and Feel and Drag and Drop). Introduced Collection Framework and JIT compiler.
9. Java SE 7 (JDK 1.7) (July 28, 2011): First version after Oracle purchased Sun (called Oracle JDK).
10. Java SE 8 (JDK 1.8) (March 18, 2014): included support for Lambda expressions, default and static methods in interfaces,
improved collection, and JavaScript runtime.
11. Java SE 9 : Expected in July 2017.
1.How To Install JDK on Windows
If you have previously installed older version(s) of JDK/JRE, un-install ALL of them. Goto "Control Panel" "Programs" "Programs
and Features" Un-install ALL programs begin with "Java", such as "Java SE Development Kit ...", "Java SE Runtime ...", "Java X
Update ...", and etc.
Accept the defaults and follow the screen instructions to install JDK and JRE.
Check the JDK installed directory by inspecting these folders using File Explorer. Take note of your JDK installed directory, in
particular, the upgrade number, which you will need in the next step.
I shall refer to the JDK installed directory as <JAVA_HOME>, hereafter, in this article.
My Notes: Starting from JDK 1.8, the installation created a directory "c:\ProgramData\Oracle\Java\javapath" and added to the
PATH. It contains only JRE executables (java.exe, javaw.exe, javaws.exe) but NOT the JDK executables (e.g., javac.exe).
2. Issue the following commands to verify that JDK/JRE are properly installed and display their version:
/*
* 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!");
}
}
prompt> d:
D:\xxx>
D:\xxx> cd \myProject
D:\myProject>
D:\myProject> dir
......
xx-xxx-xx 06:25 PM 277 Hello.java
......
D:\myProject> dir
......
xx-xxx-xx 01:53 PM 416 Hello.class
xx-xxx-xx 06:25 PM 277 Hello.java
......
Ever ything that can possibly go wrong will go wrong : Read "JDK Installation Common Errors".
You should also download the "JDK 8 Samples and Demos" from the Java SE download site.
www.textpad.com) is a lightweight programming text editor for writing toy Java programs. It can be configured to couple with the
JDK, hence, bypassing the CMD shell.
From the TextPad editor, you can invoke the JDK compiler/runtime directly via "Tools" menu External Tools "Compile Java" or
"Run Java Application". Take note of the keyboard shortcuts - Ctrl+1 for compile and Ctrl+2 for run.
If you cannot find these commands in the "Tools" menu, goto "Configure" Preferences... Tools Add JDK Commands.
You can use NotePad++ to write your Java source code. But you need to use CMD shell to compile and run the Java program.
javac -version
If a JDK version number is returned (e.g., JDK 1.x.x), then JDK has already been installed. If the JDK version is prior to 1.7,
proceed to Step 2 to install the latest JDK; otherwise, proceed to "Step 3: Write a Hello-world Java program".
If message "command not found" appears, JDK is NOT installed. Proceed to the "Step 2: Install JDK".
If message "To open javac, you need a Java runtime" appears, select "Install" and follow the instructions to install JDK. Then,
proceed to "Step 3: Write a Hello-world Java program".
/*
* My First Java program to say Hello
*/
public class Hello { // Save as "Hello.java" under "~/myProject"
public static void main(String[] args) {
System.out.println("Hello, world from Mac!");
}
}
// Run "Hello.class"
java Hello
Hello, world from Mac!
$ javac -version
If a JDK version number (e.g., "javac 1.x.x_xx") appears, JDK has already been installed. You can skip the installation and goto
step 2.
$ cd /usr/local/java
$ sudo tar xzvf ~/Downloads/jdk-8u{xx}-linux-x64.tar.gz
// x: extract, z: for unzipping gz, v: verbose, f: filename
JDK shall be extracted in a folder "/usr/local/java/jdk1.8.0_{xx}", where {xx} is the upgrade number.
The above steps set up symlinks java, javac, javaws at /usr/bin (which is in the PATH), that link to /etc/alternatives
and then to JDK bin directory.
The "alternatives" system aims to resolve the situation where several programs fulfilling the same function (e.g., different
version of JDKs). It sets up symlinks thru /etc/alternatives to refer to the actual programs to be used.
$ ls -ld /usr/bin/java*
lrwxrwxrwx 1 root root 22 Mar 31 20:41 /usr/bin/java -> /etc/alternatives/java
lrwxrwxrwx 1 root root 23 Mar 31 20:42 /usr/bin/javac -> /etc/alternatives/javac
lrwxrwxrwx 1 root root 24 Mar 31 20:42 /usr/bin/javaws -> /etc/alternatives/javaws
$ ls -ld /etc/alternatives/java*
lrwxrwxrwx 1 root root 40 Aug 29 18:18 /etc/alternatives/java -> /usr/local/java/jdk1.8.0_xx/jre/bin/java
lrwxrwxrwx 1 root root 37 Aug 29 18:18 /etc/alternatives/javac -> /usr/local/java/jdk1.8.0_xx/bin/javac
lrwxrwxrwx 1 root root 42 Aug 29 18:19 /etc/alternatives/javaws -> /usr/local/java/jdk1.8.0_xx/jre/bin/javaws
Alternatively, you can include the JDK's bin and JRE's bin into the PATH directly.
4. To verify the JDK installation, issue these commands:
5. (Optional) To use Java under Firefox, you need to enable the so-called "Java Plugin for web browser".
$ cd ~/.mozilla/plugins
// if this directory does not exist, create it
$ mkdir ~/.mozilla/plugins
Then, create a symbolic link to your Mozilla plugins folder, (check your JDK folder)
$ cd ~/.mozilla/plugins
$ sudo ln -s /usr/local/java/jdk1.8.0_{xx}/jre/lib/amd64/libnpjp2.so
To verify the installation, restart your Firefox and issue URL "about:plugins". Check for Java plugins with the correct version.
Starting from JDK 1.8, to run unsigned applets, you need to set security level to "high" add the sites to the "Exception List"
(under the Java Control Panel Security). To start the Java Control Panel:
$ cd /usr/local/java/jdk1.8.0_{xx}/jre/bin
$ ./ControlPanel // OR ./jcontrol
$ cd /etc
$ gksudo gedit profile // OR "sudo nano profile" to use the console-based nano editor
Add these lines at the end of the file "/etc/profile", replace "{xx}" with the actual number:
export JAVA_HOME=/usr/local/java/jdk1.8.0_{xx}
export PATH=$JAVA_HOME/bin:$PATH
// Refresh
$ source /etc/profile
$ echo $PATH
.....:/usr/local/java/jdk1.8.0_{xx}/bin
3. To compile the Hello-world Java program, launch a Terminal and issue these commands:
// Run "Hello.class"
$ java Hello
Hello, world from Ubuntu!
For Windows, set the CLASSPATH in Control Panel System Advanced system settings Advanced Environment
Variables System Variables New In "Variable name", enter "CLASSPATH" In "Variable value", enter
".;path1\xxx.jar;path2\yyy.jar", where the entries are separated by a semi-colon (;).
For Linux and Mac OS: Edit ~/.profile or ~/.bash_profile (or /etc/profile for system-wide setting) to include the
following line at the end of the file:
export CLASSPATH=.:path1/xxx.jar:path2/yyy.jar
3. You can also set the CLASSPATH in the javac/java command-line via the option -cp <paths> (or -classpath <paths>),
for example,
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 directories in the PATH environment variable.
Native libraries are not involved in the compilation. But if they are not properly included during runtime time, you will get a runtime
error "java.lang.UnsatisfiedLinkError: no xxx in java.library.path".
Eclipse/NetBeans
Using an IDE can greatly simplifies inclusion of external packages. Read "Eclipse How-To" or "NetBeans How-To".
Feedback, comments, corrections, and errata can be sent to Chua Hock-Chuan (ehchua@ntu.edu.sg) | HOME