JDK as the name implies is a kit (a toolkit or set of tools) that is used to develop Java apps. TIP: To check to see if you have the environment variables set correctly and the JDK installed, open up the Command Prompt (Window) or the Terminal app (Mac) and type javac -version or java -version at the prompt.
Information and system requirements for installing and using Oracle Java on Mac OS X
Mac® OS X® 10.10 (Yosemite) or higher, up to 10.14 (macOS Mojave) 4 GB RAM minimum, 8 GB RAM recommended 2 GB of available disk space minimum, 4 GB Recommended (500 MB for IDE + 1.5 GB for Android SDK and emulator system image) 1280 x 800 minimum screen resolution. Java is a great platform and a great language to program. Oracle is a lame company but I am happy that, starting with 1.7, mac version of the JDK and JRE is out of Apple's hands. 1.7 was about dynamic languages, 1.8 is about lambda functions, 1.9 will be about modularity and maybe parallelisation - should be great for big data programming. I have Windows installed on my Mac through Parallels. I have to use eclipse for windows and also want to use IntelliJ on Mac. Do I need to have separate jdk installed for windows and MacOS,. The JDK is a development environment for building applications, applets, and components using the Java programming language. The JDK includes tools useful for developing and testing programs written in the Java programming language and running on the Java platform. Important Oracle JDK License Update.
This article applies to: - Platform(s): Mac OS X
- Java version(s): 7.0, 8.0
Oracle's Java version 7u25 and below have been disabled by Apple on OS X. Updating to the latest release will allow Java to be run on Mac OS X.
» Download latest Java
» Download latest Java
» After I updated to Sierra, Yosemite or El Capitan, why am I told to install Java after I already installed the latest Java?
» Can I restore Apple Java 6 after uninstalling Oracle Java?
» What are the system requirements for Java on my Mac?
» Why can't I find Java 6 for Mac OS X on java.com?
» Can I use Chrome with Oracle Java on my Mac?
» How do I get Java for my Mac?
» How do I know if I have Java installed on my Mac?
» How do I install Java for my Mac?
» How do I find out what version of Java I have on my Mac?
» How do I enable Java on my Mac?
» How do I clear the Java cache on my Mac?
» How do I update Java on my Mac?
» How do I uninstall Java from my Mac?
» I do not have Mac version 10.7.3 (Lion) or higher. How do I get Java for other Mac versions?
» Is it safe to install previous or older versions of Java?
» Why will applets not run after getting Java through Apple Software Update?
» Why is Oracle Java available only for Mac OS X 10.7.3 and above?
» Can I install Java on Mac 10.10 (Yosemite)?
» The installation hangs during an auto-update, what can I do to get the latest Java?
» When I try to use Java from the command line, why doesn't it work?
» How do I get support or provide feedback on Java?
After I updated to macOS Sierra 10.12, El Capitan (OS X 10.11), or Yosemite (OS X 10.10), why am I told to install Java after I already installed the latest Java?
See information about Apple Java messages.
Can I restore Apple Java 6 after uninstalling Oracle Java?
Yes, see the instructions on the Apple website Restore Apple Java 6. If you have JDK 7 or later versions installed on your system and you want to restore Apple Java 6, then those JDK versions need to be uninstalled first. See the instructions to Uninstall JDK.
What are the system requirements for Java on my Mac?
Operating system requirements: For Java 7 and later versions, you will need an Intel-based Mac running Mac OS X version 10.7.3 (Lion) and above. Installing Java on a Mac is performed on a system wide basis, for all users, and administrator privileges are required. Java can not be installed on a per-user basis.Browser requirements: A 64-bit browser (Safari, for example) is required to run Oracle Java on Mac.
Why can't I find Java 6 for Mac OS X on java.com?
For Java versions 6 and below, Apple supplies their own version of Java. For Mac OS X 10.6 and below, use the Software Update feature (available on the Apple menu) to check that you have the most up-to-date version of Java 6 for your Mac. For issues related to Apple Java 6 on Mac, contact Apple Support. Oracle and Java.com only support Java 7 and later, and only on 64 bit systems. Is kodi safe for mac.
Mac OS X and Apple Java 6 End of Life
Apple has posted notice that Mac OS X 10.11 (El Capitan) will be the last OS X release that supports Java 6, and as such, recommends developers whose applications depend on Java 6 to migrate their apps to a newer Java version provided by Oracle. » More info (apple.com)
Can I use Chrome with Oracle Java on my Mac?
Chrome browser versions 42 and above. Starting with Chrome version 42, Chrome has disabled the standard way in which browsers support plugins. More info
How do I get Java for my Mac?
You can download Java from java.com.
How do I know if I have Java installed on my Mac?
Mac OS X 10.6 and below: Apple's Java comes pre-installed with your Mac OS.
Mac OS X 10.7 (Lion) and above: Java is not pre-installed with Mac OS X versions 10.7 and above. To get the latest Java from Oracle, you will need Mac OS X 10.7.3 and above.
If you have Java 7 or later versions, you will see a Java icon under System Preferences.
Java versions 6 and below are listed in the Java Preferences.app located in the Applications > Utilities folder on your Mac.
Mac OS X 10.7 (Lion) and above: Java is not pre-installed with Mac OS X versions 10.7 and above. To get the latest Java from Oracle, you will need Mac OS X 10.7.3 and above.
If you have Java 7 or later versions, you will see a Java icon under System Preferences.
Java versions 6 and below are listed in the Java Preferences.app located in the Applications > Utilities folder on your Mac.
How do I install Java for my Mac?
See Mac Java installation instructions.
How do I find out what version of Java I have on my Mac?
Mac OS X 10.7.3 and above: Under System Preferences click on the Java icon to access the Java Control Panel which will list your Java version.
If you do not see a Java icon under System Preferences, Java 7 or later versions is not installed.
If you do not see a Java icon under System Preferences, Java 7 or later versions is not installed.
How do I enable Java on my Mac?
When you install Oracle Java on your Mac (Lion and above), Java will be enabled by default.
If you are running a Java application in the browser, you will need to also check that Java is enabled in your browser.
For earlier versions of Java, check the Apple Support site.
If you are running a Java application in the browser, you will need to also check that Java is enabled in your browser.
For earlier versions of Java, check the Apple Support site.
How do I clear the Java cache on my Mac?
See How to clear the Java cache on Mac.
How do I update Java on my Mac?
See How to update Java on Mac.
How do I uninstall Java from my Mac?
See Mac Java uninstall instructions.
I do not have Mac version 10.7.3 (Lion) or higher. How do I get Java for other Mac versions?
For Java versions 6 and below, Apple supplies their own version of Java. Use the Software Update feature (available on the Apple menu) to check that you have the most up-to-date version of Apple's Java for your Mac.
Users of Lion Mac OS X 10.7.1 and 10.7.2 should upgrade to 10.7.3 or later versions, so you can get the latest Java version from Oracle.
Users of Lion Mac OS X 10.7.1 and 10.7.2 should upgrade to 10.7.3 or later versions, so you can get the latest Java version from Oracle.
Is it safe to install previous or older versions of Java?
Oracle highly discourages users from using older versions of Java. Installing old and supported versions of Java on your system presents a serious security risk. Upgrading to the latest version of Java ensures that Java applications will run with the most up-to-date security and performance improvements on your system. You can confirm that you have the latest version on the verification page. If installing an older version of Java is absolutely required, you must first uninstall the current version. See the instructions on the Mac uninstall Java FAQ.
Why will applets not run after getting Java through Apple Software Update?
Apple disables the Java plug-in and Webstart applications when the Java update is done using Software Update. Also, if the Java plug-in detects that no applets have been run for an extended period of time it will again disable the Java plug-in.
Why is Oracle Java available only for Mac OS X 10.7.3 and above?
The Java Runtime depends on the availability of an Application programming interface (API). Some of the API were added in Mac OS X 10.7.3. Apple has no plans to make those API available on older versions of the Mac OS.
Can I install Java on Mac OS X 10.10 (Yosemite)?
Yes. See Mac OS X 10.10 FAQ.
The installation hangs during an auto-update, what can I do to get the latest Java?
During an auto-update, Mac OS X 10.9 (Mavericks) users might see the installation stall. Download the latest Java from the java.com web site.
When I try to use java
from the command line, why doesn't it work? I have Oracle's version of the JRE installed.
Installing a JRE from Oracle does not update
java -version
symlinks or add java to your path. For this functionality, you must install the full JDK. See Mac command line info. How do I get support or provide feedback on Java?
Provide us details on Feedback form for reporting issues or providing feedback for Java.
You might also be interested in:
- How do I install Java for my Mac?
- How do I uninstall Java on my Mac?
- Where is the Java Control Panel on Mac?
- How do I clear Java cache on my Mac?
- How do I Update Java for my Mac?
- How do I disable Java in my web browser?
The Java Development Kit (JDK), officially named 'Java Platform Standard Edition' or 'Java SE', is needed for writing Java programs. The JDK is freely available from Sun Microsystems (now part of Oracle). The mother site for JDK (Java SE) is http://www.oracle.com/technetwork/java/javase/overview/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
Reference: 'Java Version History' @ https://en.wikipedia.org/wiki/Java_version_history.
- JDK Alpha and Beta (1995): Sun Microsystem announced Java in September 23, 1995.
- JDK 1.0 (January 1996): Originally called Oak (named after the oak tree outside James Gosling's office). Renamed to Java 1 in JDK 1.0.2.
- JDK 1.1 (February 1997): Introduced AWT event model, inner class, JavaBean, JDBC, and RMI.
- J2SE 1.2 (JDK 1.2) (December 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 & Feel, and Drag & Drop). Also introduced Collection Framework and JIT compiler.
- J2SE 1.3 (JDK 1.3) (May 2000): Introduced Hotspot JVM.
- J2SE 1.4 (JDK 1.4) (February 2002): Introduced
assert
statement, non-blocking IO (nio
), logging API, image IO, Java webstart, regular expression (regex) support. - J2SE 5.0 (JDK 5) (September 2004): Officially called 5.0 instead of 1.5. Introduced generics, autoboxing/unboxing, annotation, enum, varargs, for-each loop, static import.
- Java SE 6 (JDK 6) (December 2006): Renamed J2SE to Java SE (Java Platform Standard Edition).
- Java SE 7 (JDK 7) (July 2011): First version after Oracle purchased Sun Microsystem - aslo called Oracle JDK.
- Java SE 8 (JDK 8) (LTS) (March 2014): Included support for Lambda expressions, default and static methods in interfaces, improved collection, and JavaScript runtime. Also integrated JavaFX graphics subsystem.
- Java SE 9 (JDK 9) (September 21, 2017): Introduced modularization of the JDK (
module
) under project Jigsaw, the Java Shell (jshell
), and more. - Java SE 10 (18.3) (JDK 10) (March 2018): Introduced
var
for type inference local variable (similar to JavaScript). Introduced time-based release versioning with 2 releases each year, in March and September, denoted asYY.M.
Removed native-header generation tooljavah
. - Java SE 11 (18.9) (LTS) (JDK 11) (September 2018): Extended
var
to lambda expression. Standardize HTTP client injava.net.http
. Support TLS 1.3. Clean up the JDK and the installation package (removed JavaFX, JavaEE, CORBA modules, deprecated Nashorn JavaScript engine). - Java SE 12 (19.3) (JDK 12) (March 2019)
Jdk For Mac Os X
How To Install JDK on Windows
Step 0: Un-Install Older Version(s) of JDK/JRE
I recommend that you install only the latest JDK. Although you can install multiple versions of JDK/JRE concurrently, it is messy.
If you have previously installed older version(s) of JDK/JRE, un-install ALL of them. Goto 'Control Panel' ⇒ (optional) '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.
Step 1: Download JDK
- Goto Java SE download site @ http://www.oracle.com/technetwork/java/javase/downloads/index.html.
- Under 'Java Platform, Standard Edition' ⇒ 'Java SE 11.0.{x}', where {x} denotes a fast running security-update number ⇒ Click the 'Oracle JDK' 'Download' button.
- Under 'Java SE Development Kit 11.0.{x}' ⇒ Check 'Accept License Agreement'.
- Choose the JDK for your operating system, i.e., 'Windows'. Download the 'exe' installer (e.g., '
jdk-11.0.{x}_windows-x64_bin.exe
' - about 150MB).
Step 2: Install JDK
Run the downloaded installer (e.g., '
jdk-11.0.{x}_windows-x64_bin.exe
'), which installs both the JDK and JRE.By default, JDK is installed in directory '
C:Program FilesJavajdk-11.0.{x}
', where {x}
denotes the update number. Accept the defaults and follow the screen instructions to install JDK.Use your 'File Explorer', navigate to
'C:Program FilesJava'
to inspect the sub-directories. Take note of your JDK installed directory, in particular, the update number {x}
, which you will need in the next step.External gpu for mac. In the following diagram, the JDK installed directory is '
C:Program FilesJavajdk-11.0.1
', where {x}=1
.I shall refer to the JDK installed directory as
<JAVA_HOME>
, hereafter, in this article.Step 3: Include JDK's 'bin' Directory in the PATH
Windows' Command Prompt (
CMD
) searches the current directory and the directories listed in the PATH
environment variable (or system variable) for executable programs. JDK's programs (such as Java compiler 'javac.exe
' and Java runtime 'java.exe
') reside in the sub-directory 'bin
' of the JDK installed directory. You need to include JDK's 'bin
' in the PATH
to run the JDK programs.To edit the
PATH
environment variable in Windows 10:- Launch 'Control Panel' ⇒ (Optional) 'System and Security' ⇒ 'System' ⇒ Click 'Advanced system settings' on the left pane.
- Switch to 'Advanced' tab ⇒ Click 'Environment Variables' button.
- Under 'System Variables' (the bottom pane), scroll down to select variable 'Path' ⇒ Click 'Edit..'.
- For Newer Windows 10:
You shall see a TABLE listing all the existing PATH entries (if not, goto next step). Click 'New' ⇒ Click 'Browse' and navigate to your JDK's 'bin
' directory, i.e., 'c:Program FilesJavajdk-11.0.{x}bin
', where{x}
is your installation update number ⇒ Select 'Move Up' to move this entry all the way to the TOP.
Skip the next step. - For Older Windows 10:
(CAUTION: Read this paragraph 3 times before doing this step! Don't push 'Apply' or 'OK' until you are 101% sure. There is no UNDO!!!)
(To be SAFE, copy the content of the 'Variable value' to Notepad before changing it!!!)
In 'Variable value' field, APPEND 'c:Program FilesJavajdk-11.0.{x}bin
' (where{x}
is your installation update number) IN FRONT of all the existing directories, followed by a semi-colon (;
) to separate the JDK's bin directory from the rest of the existing directories. DO NOT DELETE any existing entries; otherwise, some existing applications may not run.
Step 4: Verify the JDK Installation
Launch a
CMD
via one of the following means:- Click 'Search' button ⇒ Enter 'cmd' ⇒ Choose 'Command Prompt', or
- Right-click 'Start' button ⇒ run.. ⇒ enter 'cmd', or
- Click 'Start' button ⇒ Windows System ⇒ Command Prompt
Issue the following commands to verify your JDK installation:
- Issue '
path
' command to list the contents of thePATH
environment variable. Check to make sure that your JDK's 'bin
' is listed in thePATH
. - Issue the following commands to verify that JDK/JRE are properly installed and display their version:
Step 5: Write a Hello-World Java Program
![For For](/uploads/1/3/4/1/134143551/882715697.png)
- 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. - Launch a programming text editor (such as TextPad, NotePad++, 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
).
Step 6: Compile and Run the Hello-World Java Program
To compile the source code '
Hello.java
':- Start a CMD Shell (Search ⇒ enter 'cmd' ⇒ select 'Command Prompt').
- 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: - 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
'. - Issue a
dir
(List Directory) command to confirm that your source file is present in the current directory. - Invoke the JDK compiler '
javac
' to compile the source code '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. - The output of the compilation is a Java class called '
Hello.class
'. Issue adir
(List Directory) command again to check for the output.
To run the program, invoke the Java Runtime '
java
':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'.
Virtualbox for mac. To install JDK API documentation:
- 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). - 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>docsindex.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>libsrc.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 'javalang
'.Using TextPad for Java Programming (on Windows)
TextPad (@ 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.
TextPad Tips and Configuration
Check HERE!
Using NotePad++ for Java Programming (on Windows)
Notepad++ (@ http://notepad-plus-plus.org) is a free and open-source programming editor.
You can use NotePad++ to write your Java source code. But you need to use CMD shell to compile and run the Java program.
NotePad++ Customization and Tips
You can customize Notepad++ to compile and run Java programs with hot-keys. Read 'NotePad++'.
How To Set the Environment Variable JAVA_HOME
Many Java applications (such as Tomcat) require the environment variable
JAVA_HOME
to be set to the JDK installed directory.To set the
JAVA_HOME
environment variable:- First, find your JDK installed directory. For JDK 11, the default is '
c:Program FilesJavajdk-11.0.{x}
', where '{x}
is the update number. Use your 'File Explorer' to find this directory and take note of your update number{x}
. - Check if
JAVA_HOME
is already set. Start a CMD and issue: If you get a message 'Environment variableJAVA_HOME
not defined', proceed to the next step.
If you get 'JAVA_HOME=C:Program FilesJavajdk-11.0.{x}
', verify that it is set correctly to your JDK directory. If not, proceed to the next step. - To set the environment variable
JAVA_HOME
in Windows 10:- Launch 'Control Panel' ⇒ (Optional) 'System and Security' ⇒ 'System' ⇒ Click 'Advanced system settings' on the left pane.
- Switch to 'Advanced' tab ⇒ Click 'Environment Variables'
- Under 'System Variables' (the bottom pane) ⇒ Click 'New' (or Look for '
JAVA_HOME
' and 'Edit' if it is already set) ⇒ In 'Variable Name', enter 'JAVA_HOME
' ⇒ In 'Variable Value', enter your JDK installed directory you noted in Step 1. (In the latest Windows 10: you can push the 'Browse Directory' button and navigate to the JDK installed directory to avoid typo error.)
- To verify, RE-START a CMD (restart is needed to refresh the environment variables) and issue:
Notes: Windows' environment variables (such as
JAVA_HOME
, PATH
) are NOT case-sensitive.How to Install JDK on Mac OS X
Step 1: Check if JDK has been Pre-Installed
https://newrss869.weebly.com/cool-screensavers-for-mac.html. To check if JDK has been installed, open a 'Terminal' (Search 'Terminal'; or Finder ⇒ Go ⇒ Utilities ⇒ Terminal) and issue this command:
- If a JDK version number is returned (e.g.,
JDK x.x.x
), then JDK has already been installed. If the JDK version is prior to 1.8, 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'.
Step 2: Download JDK
- Goto Java SE download site @ http://www.oracle.com/technetwork/java/javase/downloads/index.html.
- Under 'Java Platform, Standard Edition' ⇒ 'Java SE 11.0.{x}', where {x} denotes a fast running security-update number ⇒ Click the 'Oracle JDK' 'Download' button.
- Under 'Java SE Development Kit 11.0.{x}' ⇒ Check 'Accept License Agreement'.
- Choose the JDK for your operating platform, i.e., MacOS. Download the DMG installer (e.g,
jdk-11.0.{x}_osx-x64_bin.dmg
- about 166MB).
Step 3: Install JDK/JRE
- Double-click the downloaded Disk Image (DMG) file. Follow the screen instructions to install JDK/JRE.
- Eject the DMG file.
- To verify your installation, open a 'Terminal' and issue these commands.
Step 3: Write a Hello-World Java Program
- Create a directory called '
myProject
' under your home directory (Launch 'Finder' ⇒ 'Go' ⇒ 'Home'; Select 'File' ⇒ 'New Folder' ⇒ 'myProject
').
In Mac OS X, the home directory of the current user can be referenced as '~
'. Hence, this new directory can be referenced as '~/myProject
'. - Use a programming text editor (such as Sublime Text or Atom) to input the following source code and save as '
Hello.java
' under the directory '~/myProject
'.
(If you use Mac OS X's default text editor 'TextEdit' (NOT recommended), you need to open a new file ⇒ choose 'Format' ⇒ 'Make Plain Text' ⇒ Enter the source code ⇒ Save as 'Hello.java
'.)
Step 4: Compile and Run the Hello-World Java Program
- To compile the source code '
Hello.java
', open a new 'Terminal' ('Go' ⇒ 'Utilities' ⇒ 'Terminal') and issue these commands (as illustrated): - To run the Hello-world, invoke the Java Runtime '
java
' as follows:
How to Install JDK on Ubuntu
There are several JDK implementations available for Linux, such as Oracle JDK, OpenJDK, Sun JDK, IBM JDK and GNU Java Compiler. We shall choose the Oracle JDK 8. Ubuntu chooses OpenJDK as its default JDK, which is not 100% compatible with Oracle JDK.
Step 0: Check if JDK has already been Installed
Open a Terminal and issue this command:
If a JDK version number (e.g., '
javac x.x.x
') appears, JDK has already been installed. You can skip the installation and goto step 2.To remove OpenJDK, issue command:
Step 1: Download and Install JDK
- Goto JDK (Java SE) download site @ http://www.oracle.com/technetwork/java/javase/downloads/index.html. Under 'Java Platform, Standard Edition' ⇒ 'Java SE 11.0.{x}' ⇒ Click JDK's 'Download' ⇒ Under 'Java SE Development Kit 11.0.{x}' ⇒ Check 'Accept License Agreement' ⇒ Select 'Linux', '
tar.gz
' package, (e.g., 'jdk-11.0.{x}-linux-x64_bin.tar.gz
' - 171MB).
The tarball will be downloaded in directory '~/Downloads
', by default. - We shall install JDK under '
/usr/local/java
' (or Ubuntu's default JDK directory/usr/lib/jvm
; or/opt/java
). First, create a directory 'java
' under '/usr/local
'. Open a Terminal and issue these commands: Extract the downloaded package (Check your downloaded filename!) JDK shall be extracted in a folder '/usr/local/java/jdk-11.0.{x}
', where{x}
is the update number. - Inform the Ubuntu to use this JDK/JRE: 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.
Alternatively, you can include the JDK's bin and JRE's bin into the PATH directly. - To verify the JDK installation, issue these commands:
- [Don't Do this step - It is taken care by 'alternative' in Step 3. Keep here to show you how to set PATH.]
Add JDK's binary directory ('bin
') to the 'PATH' by editing '/etc/profile
': Add these lines at the end of the file '/etc/profile
', replace '{x}
' with the actual number: Rerun the configuration file by:
Step 2: Compile and Run a Hello-world Java Program
- File Explorer ⇒ Home ⇒ Create a new folder called '
myProject
' to keep our works. - Open 'Text Editor' (gedit). Enter the following source code and save as '
Hello.java
' under the '~/myProject
' directory created earlier. - To compile the Hello-world Java program, launch a Terminal and issue these commands:
- Run the Hello-world Java program:
Common Errors in installing JDK
Jdk For Mac Free
JDK 11 Launch Single-Source-File New Feature
In JDK 11, you can compile/run a single-file program in one step, without explicit compliation.
- Write a '
Hello.java
' (see previous section). - Delete '
Hello.class
', if it exists. - You can compile/run '
Hello.java
' in one command as follows:
Notes:
- This is applicable to single source-file only.
- No need to use
javac
to compile the program. - It compiles in memory (without producing a
.class
file), and run. - This feature is introduced for beginners to learn Java, and for professionals to test a Java feature.
- The filename and classname need not be the same.
First Java Program with Eclipse IDE
- You need to first install Eclipse. Read 'How to Install Eclipse'.
- You can then proceed to write your first Java program. Read 'Writing your first Java Program with Eclipse'.
- Eclipse allow you to debug program graphically. Read 'Debugging program in Eclipse'.
First Java Program with NetBeans IDE
- You need to first install NetBeans. Read 'How to Install NetBeans'.
- You can then proceed to write your first Java program. Read 'Writing your first Java program with NetBeans'.
- NetBeans allow you to debug program graphically. Read 'Debugging program in NetBeans'.
(Advanced) External JAR Files and Native Libraries
Notes: This section is applicable to JDK prior to JDK 9. JDK 9 introduces a new level called 'module' on top of package, and '
jmod
' files for Java modules. Need to revise this section for JDK 9.External Java packages (such as Servlet, MySQL Connector/J, JOGL, JUnit) are often distributed in JAR files (Java Archive - a single-file package of many Java classes), with possibly Native Libraries ('
.lib
' and '.dll
' in Windows, or '.a
' and '.so
' in Linux/Mac).External JAR Files ('.jar')
If external JAR files are not properly included:
- During the compilation, you will receive compilation error 'cannot find symbol' on classes belonging to the external packages.
- During execution, you will get a runtime error 'Could not find or load main class xxx' or '
NoClassDefFoundError
'.
To include external JAR files, you can either:
- Copy all the JAR files of the external packages to the Java's Extension Directories (NOT applicable to JDK 9).
- For Windows, the JDK extension directory is located at '
<JAVA_HOME>jrelibext
' (e.g., 'c:Program FilesJavajdk1.8.0_xxjrelibext
'). - For Mac, the JDK extension directories are '
/Library/Java/Extensions
' and '/System/Library/Java/Extensions
'. - For Ubuntu, the JDK extension directories are '
<JAVA_HOME>/jre/lib/ext
' (e.g., '/usr/user/java/jdk1.8.0_xx/jre/lib/ext
') and '/usr/java/packages/lib/ext
'.
java.ext.dirs
'. You can print its contents viaSystem.out.println(System.getProperty('java.ext.dirs'))
. - For Windows, the JDK extension directory is located at '
- You can also include all the JAR files in the
CLASSPATH
environment variable.CLASSPATH
may contain directories (of Java classes) or JAR files (single-file archive of Java classes). If you set theCLASSPATH
, you must also include the current directory (denoted as '.
').- 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 '.;path1xxx.jar;path2yyy.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: The entries are separated by colon (:
).
- For Windows, set the
- You can also set the
CLASSPATH
in thejavac
/java
command-line via the option-cp <paths>
(or-classpath <paths>
), for example,
External Native Libraries ('.lib', '.dll', '.a', '.so')
Some external package may provide static or shared native libraries in the form of '
.lib
' (Windows' static LIBrary), '.dll
' (Windows' Dynamically Link Library), '.a
' (Unix's static (Archive) library), or '.so
' (Unix's Shared Object library).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
'.To include external native libraries:
- Copy the native libraries into a system library directory, e.g.,
c:windowssystem32
(Windows),/usr/lib
or/usr/local/lib
(Mac OS X / Unix). You can verify that the directory is included in Java's System Property 'java.library.path
', viaSystem.out.println(System.getProperty('java.library.path'))
. - You can also set the native library path via the
java
's command-line option-Djava.library.path=xxx
, for example,
Eclipse/NetBeans
Jdk For Mac High Sierra
Using an IDE can greatly simplifies inclusion of external packages. Read 'Eclipse How-To' or 'NetBeans How-To'.