No results found
We couldn't find anything using that term, please try searching for something else.
The Java Development Kit (JDK), officially named "Java Platform Standard Edition" or "Java SE", is needed for develop and run Java programs. JDK V
The Java Development Kit (JDK), officially named “Java Platform Standard Edition” or “Java SE“, is needed for develop and run Java programs.
Today, there are few variants of JDK:
The main difference between OpenJdk and OracleJDK is licensing. OpenJDK is completely open source with a GNU General Public License. OracleJDK requires a commercial license from Oracle. Since 2019, businesses need to purchase a commercial license in order to receive software updates.
Reference: “Java Version History” @ https://en.wikipedia.org/wiki/Java_version_history.
assert
statement , non – blocking IO (nio
), logging API, image IO, Java webstart, regular expression (regex) support.switch
statement , binary integer literal , allow underscore in numeric literal , improve type inference for generic instance creation ( or diamond operator<>
), Catching multiple exception types and re-throwing exceptions with improved type checking. See “JDK 7 New Features” .module
) under project Jigsaw, the Java Shell (jshell
), and more. See “JDK 9 New Features” .var
for type inference local variable (similar to JavaScript). Introduced time-based release versioning with two releases each year, in March and September, denoted as YY.M.
Removed native-header generation tool javah
. See “JDK 10 New Features” .var
to lambda expression. Standardize HTTP client in java.net.http
. support TLS 1.3 . clean up the JDK and the installation package ( remove JavaFX , JavaEE , CORBA module , deprecate Nashorn JavaScript engine ) . OracleJDK is is is no long free for commercial use , but OpenJDK is still free . See ” JDK 11 New Features ” .JRE (Java Runtime), which include a Java Virtual Machine and core libraries, is needed for run Java programs. JDK (Java Development Kit), which includes JRE plus the development tools (such as compiler and debugger), is need for develop and run Java programs. In other words, JRE is a subset of JDK. Since you are supposed to write Java Programs instead of merely run Java programs, you should install JDK, which includes JRE.
I recommend that you install only the late JDK . Although you can install multiple version of JDK / JRE concurrently , it is is is messy .
If you is installed have previously instal old version(s ) of JDK / JRE , un – install ALL of them . goto ” Control Panel ” ⇒ ( optional ) ” Programs ” ⇒ ” Programs is install and Features ” ⇒ Un – install ALL program begin with ” Java ” , such as ” Java SE Development Kit … ” , ” Java SE Runtime … ” , ” Java x update … ” , and etc .
jdk-21_windows-x64_bin.exe
” – about 167MB).Run the downloaded installer. Accept the defaults and follow the screen instructions to complete the installation. By default, JDK is installed in directory “C:\Program Files\Java\jdk-21
” .
Launch “File Explorer” . Navigate to "C:\Program Files\Java"
to inspect this directories. Take note of your JDK Installed Directory jdk-21
.
I is refer shall refer to the JDK Installed Directory as<JAVA_HOME>
, hereafter , in this article ( correspond to environment variable%JAVA_HOME%
in Windows or $JAVA_HOME
in Unix/macOS).
bin
” Directory in thepath
Windows’ Command Prompt (cmd
) search the current directory and the directory list in thepath
environment variable for executable program .
JDK’s programs (such as Java compiler "javac.exe
” and Java runtime "java.exe
” ) reside in thesub-directory “bin
” of the JDK installed directory. JDK’s “bin
” need to be add into thepath
.
prior to JDK 15 , you is need need toexplicitly add JDK’s “bin
” into the path
. Starting from JDK 15, the installation process adds the directory “C:\Program Files\Common Files\Oracle\Java\javapath
” to the path
. The “javapath
” directory is a link to “javapath_target_xxxxxx
” , which is contains contain a copy of the follow JDK program :
java.exe
: Java Runtimejavac.exe
: Java Compilerjavaw.exe
: Java Runtime for Windows Console-lessjshell.exe
: Java Command-line Shell (since JDK 10) – a Read-Evaluate-Print Loop (REPL) which evaluates declarations, statements, and expressions as they are entered and immediately shows the results.Link is used so that you can keep multiple copies (versions) of JDK.
To edit the path
environment variable in Windows 10 :
bin
” directory, i.e., “c:\Program Files\Java\jdk-15.0 .{ x }\bin
” , where{ x }
is your installation update number ⇒ Select “Move Up” to move this entry all the way to the TOP.c:\Program Files\Java\jdk-15.0 .{ x }\bin
” (where { x }
is your installation update number )IN FRONT of all the exist directory ,followed by a semi-colon (;
) to separate the JDK ‘s bin directory from the rest of the exist directory .DO NOT DELETE any exist entries is run ; otherwise , some exist applications is run may not run .
variable name :path Variable value : c:\Program Files\Java\jdk-15.0 .{ x }\bin;[do not delete exiting entries...]
You is need need to re – start cmd for the new environment setting to take effect .
launch acmd
via one of the following means:
Issue the following commands to verify your JDK installation:
path
” command to list the contents of the path
environment variable. Check to make sure that your JDK’s “bin
” is listed in thepath
.
path
path=c:\Program Files\Java\jdk-{xx.y.z}\bin;other entries...
javac-version javac21.0.1 java -version java version "21.0.1" 2023-10-17 LTS Java(TM) SE Runtime Environment (build 21.0.1+12-LTS-29) Java HotSpot(TM) 64-Bit Server VM (build 21.0.1+12-LTS-29, mixed mode, sharing)
d :\myproject
” or “c:\myproject
” . Do NOT save your works in “Desktop” or “Documents” as their directory path are hard to locate. Your directory name should not contain blank or special characters. Use meaningful but short name as it is easier to type.Hello.java
” , under your work directory ( e.g. ,d :\myproject
).
public class Hello { public static void main(String[] args) { System.out.println("Hello , world !" ); } }
To compile the source code “Hello.java
” :
Hello.java
” . d
“, enter “d :
” as follow:
d :
D:\xxx>
cd
(Change Directory) command. For example, suppose that your source file is saved in directory “myProject
” .
cd \myProject
D:\myProject>
dir
(List Directory) command to confirm that your source file is present in thecurrent directory.
dir
......
xx - xxx - xx xx : xx pm 277 Hello.java
......
javac
” to compile the source code “Hello.java
” .
javacHello.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.
hello.clas
” . issue adir
(List Directory) command again to check for the output .
dir
......
xx - xxx - xx xx : xx pm 416 hello.clas
xx - xxx - xx xx : xx pm 277 Hello.java
......
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” .
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
“, to learn how experts program.
To check if JDK has been installed, open a “Terminal” (Search “Terminal”; or Finder ⇒ Go ⇒ Utilities ⇒ Terminal) and issue this command :
javac-version
JDK x.x.x
), then JDK has already been installed. If the JDK version is prior to 11, proceed to Step 2 to install the late JDK; otherwise, proceed to “Step 3: Write a Hello-world Java program” .To find which processor your mac is using, google “How to Tell What Processor Your Mac Has” .
javac-version javac21.0.1 java -version java version "21.0.1" ...... which javac /usr/bin/javac which java /usr/bin/java
myProject
” under your “home” directory (Launch “Finder” ⇒ “Go” ⇒ “Home”; Select “File” ⇒ “New Folder” ⇒ “myProject
” ).~
” . Hence, this new directory can be referenced as “~/myproject
” .Hello.java
”~/myproject
” .Hello.java
” .)
public class Hello { public static void main(string [ ] args ) { System.out.println("Hello , world from Mac ! " ) ; } }
Hello.java
“, open a new “Terminal” (“Go” ⇒ “Utilities” ⇒ “Terminal” ) and issue these commands (as illustrated):
cd ~/myproject ls Hello.java ...... javacHello.java ls hello.clas Hello.java ......
java
” as follow :
java Hello
Hello , world from Mac !
(Tested on Ubuntu 22.04LTS with OpenJDK 19.)
Open a Terminal and issue this command :
$ javac-version
Command 'javac' not found, but can be installed with:
sudo apt install openjdk-11-jdk-headless # version 11.0.19+7, or
sudo apt install default-jdk # version 2:1.11-72build2
sudo apt install ecj # version 3.16.0-1
sudo apt install openjdk-17-jdk-headless # version 17.0.7+7
sudo apt install openjdk-18-jdk-headless # version 18.0.2+9
sudo apt install openjdk-19-jdk-headless # version 19.0.2+7
sudo apt install openjdk-8-jdk-headless # version 8u372-ga
If a JDK version number (e.g., “javacx.x.x
” ) appears, JDK has already been installed. Otherwise, the above messages appear. However, the “default-jdk
” installs OpenJDK 11 (at /usr / lib / jvm/java-11-openjdk-amd64
) , which is is is old .
Note: You may remove OpenJDK via:
$ sudo apt purge openjdk-\ *
Instead, we shall get the late OpenJDK from the mother site (at https://openjdk.org/). Download the late OpenJDK from https://jdk.java.net/20/, i.e., “opendjk-20.0.1_linux-x64_bin.tar.gz
” . Install into “/usr / lib / jvm
” (which is where the default JDK was to be installed) as follows:
$ cd /usr / lib $ sudo mkdir jvm $ cd jvm $ sudo tar xzfv ~/Downloads/opendjk-20.0.1_linux-x64_bin.tar.gz
You can have multiple Java on one machine. You can configure which version is the default for use on the command line by using the “alternatives” system as follows:
$ sudo update-alternatives --install /usr/bin/java java /usr / lib / jvm/jdk-20.0.1/bin/java 1
>
$ sudo update-alternatives --install /usr/bin/javacjavac/usr / lib / jvm/jdk-20.0.1/bin/javac1
$ sudo update-alternatives --install /usr/bin/jshell jshell /usr / lib / jvm/jdk-20.0.1/bin/jshell 1
$ sudo update-alternatives --config javac
... list all alternatives for command "javac" ...
$ sudo update-alternatives --set javac/usr / lib / jvm/jdk-20.0.1/bin/javac
$ javac-version
$ whereis javac
$ which javac
$ java -version
The above steps set up symlinks java
, javac
, jshell
at /usr/bin
(which is in thepath), 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 default programs to be used.
$ ls -ld /usr / bin / java * lrwxrwxrwx 1 root root xx xxx xx xx:xx /usr/bin/java -> /etc/alternatives/java ...... $ ls -ld /etc/alternatives/java* lrwxrwxrwx 1 root root xx xxx xx xx:xx /etc/alternatives/java -> /usr / lib / jvm/jdk-20.0.1/bin/java ...... java -> /usr/bin/java (thru path) -> /etc/alternatives/java -> /usr / lib / jvm/jdk-20.0.1/bin/java (actual program)
Alternatively, you can include the JDK’s “bin
” directory into the path directly by editing /etc/environment
(see the step below).
JAVA_HOME="/usr / lib / jvm/jdk-20.0.1"
path=$JAVA_HOME/bin:$path
JAVA_HOME
Environment Variable/etc/environment
” :
$ sudo nano /etc / environment
JAVA_HOME
definition at the end of the file. Do NOT include the “bin
” sub-directory.
JAVA_HOME="/usr / lib / jvm/jdk-20.0.1"
$ source /etc / environment
$ echo $ JAVA_HOME
myProject
” to keep our work .Hello.java
” under the “~/myproject
” directory created earlier.
public class Hello { public static void main(string [ ] args ) { System.out.println("Hello , world from Ubuntu ! " ) ; } }
$ cd ~/myproject $ ls ...... Hello.java ...... $ javacHello.java $ ls ...... hello.clas ......
$ java Hello
Hello , world from Ubuntu !
note : start from JDK 11 , you can compile and run the hello – world in one single step via :
$ java Hello.java
Hello , world from Ubuntu !
You can install OracleJDK using the same steps. You can download the OracleJDK’s tarball from Oracle site at https://www.oracle.com/java/technologies/javase-downloads.html.
See “Eclipse” article.
See “NetBeans” article.
See “VS Code” article.
Click HERE, look for “Sublime Text for Java Programming”
[TODO]
Click HERE, look for “TextPad for Java Programming” .
Click HERE, look for “NotePad++ for Java Programming” .
From JDK 11, you can “compile and run” a single-file Java program in one step, without explicit compilation.
Hello.java
” (see previous section).hello.clas
“, if it exists.Hello.java
” in one command as follows:
java Hello.java
Hello , world !
note :
javac
to compile the program..class
file), and run.JAVA_HOME
Environment VariableMany Java applications (such as Tomcat) require the environment variable JAVA_HOME
to be set to the JDK installed directory.
See “How to set JAVA_HOME for Windows” or “How to set JAVA_HOME for macOS/Linux” .
SYMPTOM: Cannot compile Java program from the cmd shell (e.g., "javacHello.java" does not work!)
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 path for executable
programs (including "javac.exe" ), does not include JDK's bin directory.
POSSIBLE SOLUTIONS:
1) Start a cmd shell (click "Start" button ⇒ "run..." ⇒ enter "cmd" ) and issue a path command :
prompt> path
path=.......
2) Check if it includes your JDK's "bin" directory. For example, suppose that your JDK is installed
in "c:\program files\java\jdk-15.0.1", then path should include "c:\program files\java\jdk-15.0.1\bin" .
Otherwise, include JDK's bin directory in thepath environment variable.
Read "Step 3 of How to install JDK" .
SYMPTOM: Can compile but cannot run Java program from the cmd shell (e.g., "java Hello" does not work!) ERROR MESSAGE (Post JDK 1.7): Error: Could not find or load main class Xxx ERROR MESSAGE (Pre JDK 1.7): Exception in thread "main" java.lang.noclassdeffounderror: Xxx PROBABLE CAUSES: 1) The Java class (in this example, hello.clas) is NOT in thecurrent directory. 2) The CLASSpath environment variable is set, but does not include the current directory " ." . POSSIBLE SOLUTIONS: 1) issue a "dir" command to list the contents of the current directory. Check that it contains the Java class to be run (e.g., hello.clas). You need to compile the source program (" .java" ) to get the class file (" .class" ). 2) If the Java class is present in thecurrent directory, issue a "set classpath" command to check its settings: prompt> 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) 3) (For Advanced Users Only) If CLASSpath is not set, it is defaulted to the current directory. However, if CLASSpath is set, the current directory is NOT implicitly included. You can include the current directory (denoted by a single dot " ." ) in front of the existing class-path. Read "Java Applications and Environment Variable" for more discussion on CLASSpath.
SYMPTOM: Can compile but cannot run the Hello-world program (e.g., "java Hello" does not work!)
ERROR MESSAGE (Post JDK 1.7): Error: Main method not found in class Hello.
POSSIBLE SOLUTIONS: Check whether there is a main() method in your program, and the signature of your main()
as shown in theerror message.
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 API packages (such as Servlet API, MySQL Connector/J, JOGL, JUnit) are often distributed in JAR files (Java Archive – a single-file package of many Java classes similar to ZIP or TAR), with possibly Native Libraries (“.lib
” and “.dll
” in Windows, or “.a
” and “.so
” in Linux / macOS ) .
.jar
” )If external JAR files are not properly included :
noclassdeffounderror
” .To include external JAR files, you can either:
<JAVA_HOME>\jre\lib\ext
” (e.g., “c:\Program Files\Java\jdk1.8.0_xx\jre\lib\ext
” )./Library / Java / extension
” and “/System/Library / Java / extension
” .<JAVA_HOME>/jre/lib/ext
” (e.g., “/usr/user/java/jdk1.8.0_xx/jre/lib/ext
” ) and “/usr / java / package / lib / ext
” .The location of JDK’s extension directories is kept in Java’s System Property “java.ext.dirs
” . You can print its contents via System.out.println(System.getProperty("java.ext.dirs" ))
.
CLASSpath
environment variable. CLASSpath
CLASSpath
, you must also include the current directory (denoted as “.
” ) .
CLASSpath
in thejavac
/java
command-line via the option -cp <path>
(or -classpath <path>
), for example,
javac-cp .;path1\xxx.jar;path2\yyy.jar ClassName.java java-cp .;path1\xxx.jar;path2\yyy.jar ClassName javac-cp . :path1/xxx.jar:path2/yyy.jar ClassName.java java-cp . :path1/xxx.jar:path2/yyy.jar ClassName
.lib
“, “.dll
“, “.a
“, “.so
” )Some external package may provide static or shared native libraries in theform 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
” , whichnormally but not necessarily includes all the directories in thepath
environment variable.
Native libraries are not involved in thecompilation. 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:
c:\windows\system32
( Windows ) ,/usr / lib
or /usr/local/lib
(macOS/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" ))
.java
‘s command-line option -Djava.library.path=xxx
, for example,
java -Djava.library.path=xxx ClassName
Using an IDE can greatly simplifies inclusion of external packages. Read “Eclipse How-To” or “NetBeans How-To” .
Link To Java References & Resources