How To Install Java Se
How to Install JDK 17 (on Windows, macOS & Ubuntu) and Get Started with Coffee Programming
The Coffee Development Kit (JDK), officially named "Java Platform Standard Edition" or "Java SE", is needed for writing and running Java programs.
JDK Variants
At that place are few variants of JDK:
- OpenJDK: Currently, the "OpenJDK" developed by Oracle and the Java community (@ https://openjdk.coffee.internet/) provides a free and open up-source JDK official reference implementation.
- OracleJDK: This commodity is based on the "OracleJDK" (@ https://www.oracle.com/java/) (due to legacy), which is free for personal and development use but no longer free for commercial use.
JDK Versions
Reference: "Java Version History" @ https://en.wikipedia.org/wiki/Java_version_history.
- JDK Alpha and Beta (1995): Sun Microsystem appear Java in September 23, 1995.
- JDK one.0 (January 1996): Originally called Oak (named later the oak tree outside James Gosling's function). Renamed to Java 1 in JDK 1.0.2.
- JDK one.1 (Feb 1997): Introduced AWT event model, inner class, JavaBean, JDBC, and RMI.
- J2SE ane.2 (JDK 1.two) (December 1998): Re-branded as "Java ii" and renamed JDK to J2SE (Coffee 2 Standard Edition). Likewise released J2EE (Coffee 2 Enterprise Edition) and J2ME (Java 2 Micro Edition). Included JFC (Java Foundation Classes - Swing, Accessibility API, Java 2D, Pluggable Await & Feel, and Drag & Drib). As well introduced Collection Framework and JIT compiler.
- J2SE 1.3 (JDK 1.3) (May 2000): Introduced Hotspot JVM.
- J2SE ane.4 (JDK 1.4) (February 2002): Introduced
assertstatement, non-blocking IO (nio), logging API, image IO, Java webstart, regular expression (regex) back up. - J2SE five.0 (JDK 5) (September 2004): Officially called 5.0 instead of 1.5 (by dropping the 1.). Introduced generics, autoboxing/unboxing, annotation, enum, varargs, for-each loop, static import. Meet "JDK 5 New Features".
- Java SE 6 (JDK six) (December 2006): Renamed J2SE to Java SE (Java Platform Standard Edition). No new language features. See "JDK six New Features".
- Java SE 7 (JDK 7) (July 2022): Beginning version after Oracle purchased Sun Microsystem - aslo chosen OracleJDK. Introduced Strings in
switchstatement, Binary integer literals, allowing underscores in numeric literals, improved type inference for generic instance creation (or diamond operator<>), Catching multiple exception types and rethrowing exceptions with improved blazon checking. See "JDK seven New Features". - Java SE 8 LTS (JDK eight) (March 2022): Included support for Lambda expressions, default and static methods in interfaces, improved collection, and JavaScript runtime. Also integrated JavaFX graphics subsystem. Come across "JDK 8 New Features".
- Java SE ix (JDK 9) (September 21, 2022): Introduced modularization of the JDK (
module) nether project Jigsaw, the Java Shell (jshell), and more. Come across "JDK nine New Features". - Java SE 10 (18.3) (JDK 10) (March 2022): Introduced
varfor type inference local variable (similar to JavaScript). Introduced time-based release versioning with two releases each year, in March and September, denoted every bitYY.M.Removed native-header generation tooljavah. See "JDK 10 New Features". - Java SE 11 LTS (eighteen.9) (JDK xi) (September 2022): Extended
varto lambda expression. Standardize HTTP customer injava.net.http. Back up TLS ane.iii. Clean up the JDK and the installation package (removed JavaFX, JavaEE, CORBA modules, deprecated Nashorn JavaScript engine). OracleJDK is no longer free for commercial use, just OpenJDK is yet free. Run across "JDK 11 New Features". - Java SE 12 (19.3) (JDK 12) (March 2022): Switch Expression (preview). See "JDK 12 New Features".
- Coffee SE 13 (19.9) (JDK 13) (September 2022): Switch Expression (preview), Multi-line Text Cake (preview). See "JDK 13 New Features".
- Java SE xiv (20.3) (JDK 14) (March 2022): Records (preview)
- Java SE 15 LTS (20.9) (JDK 15) (September 2022):
- Coffee SE sixteen (JDK 16) (March 2022):
- Coffee SE 17 LTS (JDK 17) (September 2022):
- Java SE 18 (JDK xviii) (March 2022):
"JDK" or "JRE"?
JRE (Coffee Runtime), which include a Java Virtual Machine and core libraries, is needed for running Coffee programs. JDK (Java Evolution Kit), which includes JRE plus the development tools (such equally compiler and debugger), is demand for writing also equally running Java programs. In other words, JRE is a subset of JDK. Since yous are supposed to write Java Programs instead of merely running Java programs, y'all should install JDK, which includes JRE.
How To Install JDK on Windows
Pace 0: United nations-Install Older Version(s) of JDK/JRE
I recommend that you install merely the latest JDK. Although y'all can install multiple versions of JDK/JRE meantime, it is messy.
If you accept 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 ...", "Coffee 10 Update ...", and etc.
Step 1: Download JDK
- Goto JDK (or Coffee SE) download site @ https://www.oracle.com/java/technologies/javase-downloads.html.
- Nether "Java SE Development Kit 17.0.{x} downloads".
- Select "Windows" ⇒ Download the "x64 Installer" (east.g., "
jdk-17_windows-x64_bin.exe" - virtually 152MB).
Step 2: Install JDK
Run the downloaded installer. Take the defaults and follow the screen instructions to consummate the installation. By default, JDK is installed in directory "C:\Program Files\Coffee\jdk-17.0.{x} ", where {10} denotes the running "update number" starting from 1.
Launch "File Explorer". Navigate to "C:\Programme Files\Coffee" to inspect this directories. Accept annotation of your JDK Installed Directory jdk-17.0.{x} , in particular, the update number {x} .
I shall refer to the JDK Installed Directory as <JAVA_HOME> , hereafter, in this article (corresponding to environment variable %JAVA_HOME% in Windows or $JAVA_HOME in Unix/macOS).
Step 3: (SKIP for JDK 17, 16, 16 - kept for abyss) Include JDK'southward "bin" Directory in the PATH
Windows' Command Prompt (CMD) searches the electric current directory and the directories listed in the PATH surround variable for executable programs.
JDK'due south programs (such as Java compiler "javac.exe" and Java runtime "java.exe") reside in the sub-directory "bin" of the JDK installed directory. JDK's "bin" needs to be added into the PATH.
Prior to JDK 15, you need to explicitly add together JDK'due south "bin" into the PATH. Starting from JDK 15, the installation process adds the directory "C:\Plan Files\Mutual Files\Oracle\Java\javapath" to the PATH. The "javapath" directory is a link to "javapath_target_xxxxxx", which contains a copy of the following JDK programs:
-
java.exe: Java Runtime -
javac.exe: Coffee Compiler -
javaw.exe: Java Runtime for Windows Console-less -
jshell.exe: Java Control-line Beat out (since JDK 10) - a Read-Evaluate-Impress Loop (REPL) which evaluates declarations, statements, and expressions as they are entered and immediately shows the results.
Link is used so that you lot tin can go on multiple copies (versions) of JDK.
To edit the PATH environment variable in Windows 10:
- Launch "Control Console" ⇒ (Optional) "Organization and Security" ⇒ "System" ⇒ Click "Avant-garde system settings" on the left pane.
- Switch to "Advanced" tab ⇒ Click "Environment Variables" button.
- Under "System Variables" (the bottom pane), scroll downwards to select variable "Path" ⇒ Click "Edit...".
- For Newer Windows 10:
You shall see a Table list all the existing PATH entries (if non, goto adjacent step). Click "New" ⇒ Click "Browse" and navigate to your JDK's "bin" directory, i.east., "c:\Program Files\Java\jdk-fifteen.0.{10}\bin", where{x}is your installation update number ⇒ Select "Move Up" to movement this entry all the way to the TOP. - For Older Windows 10 (Time to change your figurer!):
(Circumspection: Read this paragraph 3 times before doing this step! Don't button "Apply" or "OK" until you are 101% sure. In that location is no Disengage!!!)
(To be Prophylactic, copy the content of the "Variable value" to Notepad before changing it!!!)
In "Variable value" field, APPEND "c:\Program Files\Java\jdk-xv.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'due south bin directory from the residue of the existing directories. DO NOT DELETE any existing entries; otherwise, some existing applications may not run.Variable name : PATH Variable value : c:\Program Files\Java\jdk-15.0.{x}\bin; [practice not delete exiting entries...]
You need to re-started CMD for the new environment settings to accept effect.
Step 4: Verify the JDK Installation
Launch a CMD via one of the post-obit ways:
- Click "Search" button ⇒ Type "cmd" ⇒ Choose "Command Prompt", or
- Correct-click "Kickoff" button ⇒ run... ⇒ enter "cmd", or
- Click "Start" push button ⇒ Windows System ⇒ Command Prompt
Event the following commands to verify your JDK installation:
- (Skip for JDK 17, 16, xv) Issue "
path" control to listing the contents of thePATHenvironment variable. Bank check to make sure that your JDK's "bin" is listed in thePATH.path PATH=c:\Program Files\Coffee\jdk-{xx.y.z}\bin;other entries... - Issue the following commands to verify that JDK/JRE are properly installed and display their version:
javac -version javac 17.0.1 java -version coffee version "17.0.1" 2022-10-19 LTS Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39) Coffee HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed fashion, sharing)
Step 5: Write a Hello-Globe Coffee Program
- Create a directory to proceed your works, e.g., "
d:\myProject" or "c:\myProject". Practice Not save your works in "Desktop" or "Documents" every bit they are difficult to locate. The directory name shall not contain bare or special characters. Use meaningful but short proper name every bit it is easier to blazon. - Launch a programming text editor (such every bit TextPad, NotePad++, Sublime Text, Atom). Begin with a new file and enter the following source code. Salve the file as "
Hello.java", under your work directory (e.m.,d:\myProject).public class Hullo { public static void chief(String[] args) { Arrangement.out.println("Hello, world!"); } }
Stride 6: Compile and Run the Hello-Earth Java Program
To compile the source code "Hello.coffee":
- Start a CMD Shell (Search ⇒ enter "cmd" ⇒ select "Command Prompt").
- Ready the Current Drive to the drive where you lot saved your source file "
Hello.coffee".
If you use drive "c", skip this pace.
Else if yous use bulldoze "d", enter "d:" equally follow:d: D:\thirty> - Set the Current Working Directory to the directory that y'all 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> - Outcome a
dir(List Directory) command to confirm that your source file is present in the current directory.dir ...... twenty-thirty-xx twenty:xx PM 277 Howdy.coffee ...... - Invoke the JDK compiler "
javac" to compile the source lawmaking "Hello.java".javac Hello.java
The compilation is successful if the control prompt returns. Otherwise, fault messages would be shown. Correct the errors in your source file and re-compile. Check "Mutual JDK Installation Errors", if y'all run into problem compiling your programme. - The output of the compilation is a Java class chosen "
Howdy.grade". Consequence adir(List Directory) command again to check for the output.dir ...... xx-xxx-20 xx:xx PM 416 Hello.course xx-xxx-xx 20:xx PM 277 Hello.java ......
To run the plan, invoke the Java Runtime " java ":
java Hello Hi, world! Everything that can possibly go wrong will go incorrect: Read "JDK Installation Common Errors".
Step vii: (For Avant-garde Users Just) 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 yous to go through some of the source files such as "Cord.java", "Math.java", and "Integer.java", under "java\lang", to acquire how experts program.
How to Install JDK on macOS
Step 1: Check if JDK has been Pre-Installed
To cheque if JDK has been installed, open a "Final" (Search "Last"; or Finder ⇒ Go ⇒ Utilities ⇒ Terminal) and effect this control:
javac -version
- If a JDK version number is returned (due east.chiliad.,
JDK x.x.x), then JDK has already been installed. If the JDK version is prior to xi, proceed to Stride ii to install the latest JDK; otherwise, continue to "Step three: Write a Howdy-earth Coffee program". - If message "control non found" appears, JDK is Not installed. Continue to the "Step 2: Install JDK".
- If message "To open javac, y'all demand a Coffee runtime" appears, select "Install" and follow the instructions to install JDK. Then, proceed to "Step 3: Write a Hello-world Java program".
Footstep ii: Download JDK
- Goto JDK (or Java SE) download site @ https://www.oracle.com/coffee/technologies/javase-downloads.html.
- Under "Java SE Evolution Kit 17.0.{ten} downloads".
- Select "macOS" ⇒ Download the "x64 Installer" (e.thou., "
jdk-17_windows-x64_bin.exe" - near 152MB). - Under "Oracle JDK", click "JDK Download".
- Download the "x64 DMG installer" (e.m,
jdk-17_macos-x64_bin. dmg- about 168MB (I am bold that you are using Intel processor, non ARM processor. Mac is moving to ARM processor.)
Step 3: Install JDK/JRE
- Double-click the downloaded Deejay Image (DMG) file. Follow the screen instructions to install JDK/JRE.
- Eject the DMG file.
- To verify your installation, open up a "Terminal" and consequence these commands.
javac -version javac 17.0.{ten} java -version coffee version "17.0.{10}" ...... which javac /usr/bin/javac which java /usr/bin/java
Pace 3: Write a Hullo-World Java Plan
- Create a directory called "
myProject" nether your "abode" directory (Launch "Finder" ⇒ "Become" ⇒ "Abode"; Select "File" ⇒ "New Folder" ⇒ "myProject").
In macOS/Unix, the "home" directory of the current user tin be referenced equally "~". Hence, this new directory can be referenced equally "~/myProject". - Employ a programming text editor (such as Sublime Text or Atom) to input the post-obit source code and save equally "
Hello.java" under the directory "~/myProject".
(If you lot use macOS's default text editor "TextEdit" (Non recommended), you need to open a new file ⇒ cull "Format" ⇒ "Make Plain Text" ⇒ Enter the source code ⇒ Relieve as "How-do-you-do.java".)public class Hi { public static void primary(String[] args) { System.out.println("Hello, world from Mac!"); } }
Step 4: Compile and Run the Howdy-World Java Program
- To compile the source lawmaking "
Hello.coffee", open a new "Last" ("Go" ⇒ "Utilities" ⇒ "Final") and outcome these commands (as illustrated):cd ~/myProject ls Hello.java ...... javac Hello.java ls Hullo.class How-do-you-do.java ......
- To run the Hello-world, invoke the Java Runtime "
coffee" as follows:java Hello Hello, world from Mac!
How to Install JDK (15) on Ubuntu
We shall try both the OpenJDK (costless and open-source) and the Oracle JDK (gratuitous for personal and evolution, only not costless for production).
Stride 0: Cheque if JDK has already been Installed
Open up a Final and issue this command:
$ javac -version
If a JDK version number (e.thousand., "javac x.x.x") appears, JDK has already been installed. You tin skia the installation and goto Open2.
Step 1a: Install OpenJDK
[TODO]
To remove OpenJDK, issue command:
$ sudo apt-get purge openjdk-\*
Pace 1b: Install Oracle JDK
- Goto Oracle JDK (Coffee SE) download site @ https://world wide web.oracle.com/java/technologies/javase-downloads.html ⇒ Under "Oracle JDK", click "JDK Download" ⇒ Select "Linux x64 Compressed Archive" package (e.thousand., "
jdk-15.0.{10}-linux-x64_bin.tar.gz" - 179MB). The tarball volition be downloaded in directory "~/Downloads", by default. - Nosotros shall install JDK under "
/usr/local/coffee" (or Ubuntu's default JDK directory/usr/lib/jvm; or/opt/java). First, create a directory "coffee" under "/usr/local". Open a Terminal and issue these commands:$ cd /usr/local $ sudo mkdir java
Extract the downloaded package (Cheque your downloaded filename!)$ cd /usr/local/java $ sudo tar xzvf ~/Downloads/jdk-15.0.{ten}-linux-x64_bin.tar.gzJDK shall exist extracted in a folder "/usr/local/java/jdk-fifteen.0.{x}", where{x}is the update number. - Inform the Ubuntu to use this JDK/JRE:
$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk-15.0.{ten}/bin/java" 1 $ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/coffee/jdk-15.0.{x}/bin/javac" 1 $ sudo update-alternatives --install "/usr/bin/jshell" "java/usr/local/coffee/jdk-15.0.{x}/bin/jshell" 1 $ sudo update-alternatives --set java /usr/local/coffee/jdk-15.0.{ten}/bin/coffee $ sudo update-alternatives --prepare javac /usr/local/java/jdk-15.0.{x}/bin/javac $ sudo update-alternatives --set jshell /usr/local/java/jdk-fifteen.0.{x}/bin/jshellThe in a higher place steps fix symlinksjava,javac,jshellat/usr/bin(which is in the PATH), that link to/etc/alternativesand then to JDK bin directory.
The "alternatives" system aims to resolve the situation where several programs fulfilling the same function (e.g., dissimilar version of JDKs). Information technology sets upward symlinks thru/etc/alternativesto refer to the actual programs to exist used.
$ ls -ld /usr/bin/java* lrwxrwxrwx 1 root root 20 xxx twenty twenty:20 /usr/bin/java -> /etc/alternatives/java ...... $ ls -ld /etc/alternatives/java* lrwxrwxrwx ane root root xx xxx 20 xx:twenty /etc/alternatives/java -> /usr/local/java/jdk-15.0.{x}/bin/coffee ...... coffee -> /usr/bin/java (thru PATH) -> /etc/alternatives/java -> /usr/local/coffee/jdk-15.0.{ten}/bin/java (actual program)
Alternatively, you can include the JDK's bin into the PATH directly. - To verify the JDK installation, issue these commands:
$ javac -version javac 15.0.{10} $ java -version java version "15.0.{ten}" ...... $ which javac /usr/bin/javac $ which java /usr/bin/java
- (Don't Do this step - It is taken intendance past "alternatives" in Step three. Keep here to show you lot how to set PATH.)
Add together JDK's binary directory ("bin") to the "PATH" by editing "/etc/profile":$ cd /etc $ sudo nano profile
Add together these lines at the end of the file "/etc/profile", replace "{x}" with the actual number:export JAVA_HOME=/usr/local/java/jdk-15.0.{ten} export PATH=$JAVA_HOME/bin:$PATHRerun the configuration file past:$ source /etc/profile $ echo $JAVA_HOME /usr/local/java/jdk-15.0.{10} $ echo $PATH /usr/local/java/jdk-15.0.{x}/bin:......
Step ii: Compile and Run a Hello-world Java Plan
- File Explorer ⇒ Domicile ⇒ Create a new folder chosen "
myProject" to continue our works. - Open up "Text Editor" (gedit). Enter the following source code and save as "
Hello.coffee" under the "~/myProject" directory created before.public class Hi { public static void chief(String[] args) { System.out.println("Hello, world from Ubuntu!"); } } - To compile the Hullo-world Java program, launch a Terminal and issue these commands:
$ cd ~/myProject $ ls ...... Hello.java ...... $ javac Hi.java $ ls ...... Hello.form ......
- Run the Hello-globe Java plan:
$ coffee Hi Hi, world from Ubuntu!
Notes: Starting from JDK 11, yous can compile and run the hello-world in ane unmarried step via:
$ java Hi.coffee Howdy, world from Ubuntu! Source-Lawmaking Editors & IDEs for Java Programming
Eclipse IDE
- You need to first install Eclipse. Read "How to Install Eclipse".
- javaan then continue to write your first Java program. Read "Writing your start Coffee Program with Eclipse".
- Eclipse allow you to debug program graphically. Read "Debugging program in Eclipse".
NetBeans IDE
- You lot demand to first install NetBeans. Read "How to Install NetBeans".
- You can then continue to write your first Coffee plan. Read "Writing your showtime Java program with NetBeans".
- NetBeans allow you to debug program graphically. Read "Debugging programme in NetBeans".
Visual Studio (VS) Code IDE
Click Hither, look for "VS Code for Java Programming"
Sublime Text (for Windows, macOS, Linux)
Click HERE, look for "Sublime Text for Java Programming"
Cantlet (for Windows, macOS, Linux)
[TODO]
TextPad (for Windows only)
Click Here, look for "TextPad for Java Programming".
NotePad++ (for Windows only)
Click Hither, await for "NotePad++ for Java Programming".
(JDK 11 New Characteristic) Launch Single-Source-File
From JDK 11, you lot can "compile and run" a single-file plan in one stride, without explicit compilation.
- Write a "
Hello.java" (see previous section). - Delete "
Hello.course", if it exists. - Y'all can compile/run "
Hello.coffee" in i command equally follows:java Howdy.coffee Hello, world!
Notes:
- This is applicable to single source-file only.
- No need to use
javacto compile the programme. - It compiles in memory (without producing a
.gradefile), and run. - This feature is introduced for beginners to learn Java, and for professionals to test a Coffee feature.
- The filename and classname need not exist the same.
How To Fix JAVA_HOME Surround Variable
Many Java applications (such as Tomcat) require the environment variable JAVA_HOME to exist set to the JDK installed directory.
See "How to gear up JAVA_HOME for Windows" or "How to gear up JAVA_HOME for macOS/Linux".
Common Errors in installing JDK
SYMPTOM: Cannot compile Java programme from the CMD vanquish (e.g., "javac Hello.java" does non work!) Mistake Message: 'javac' is not recognized as an internal or external command, operable program or batch file. PROBABLE CAUSES: The PATH surround variable, which maintains a list of search paths for executable programs (including "javac.exe"), does not include JDK's bin directory. POSSIBLE SOLUTIONS: i) First a CMD vanquish (click "Beginning" push button ⇒ "run..." ⇒ enter "cmd") and effect a path command: prompt> path PATH=....... 2) Cheque if it includes your JDK's "bin" directory. For instance, suppose that your JDK is installed in "c:\program files\java\jdk-xv.0.1", then PATH should include "c:\program files\java\jdk-15.0.i\bin". Otherwise, include JDK's bin directory in the PATH environs variable. Read "Step iii of How to install JDK".
SYMPTOM: Can compile but cannot run Java program from the CMD crush (e.g., "java Hello" does not work!) ERROR Bulletin (Mail JDK 1.7): Error: Could not find or load main class Xxx Mistake Message (Pre JDK i.seven): Exception in thread "main" coffee.lang.NoClassDefFoundError: Xxx PROBABLE CAUSES: 1) The Java class (in this case, Hello.class) is Non in the current directory. 2) The CLASSPATH environment variable is ready, but does not include the current directory ".". POSSIBLE SOLUTIONS: 1) Issue a "dir" command to list the contents of the electric current directory. Bank check that it contains the Coffee form to be run (east.chiliad., Hello.grade). Y'all need to compile the source program (".java") to become the class file (".class"). 2) If the Java course is nowadays in the current directory, consequence a "set classpath" command to check its settings: prompt> fix classpath CLASSPATH=....... If you receive the message "Environment variable CLASSPATH not defined" and your program is correct, I tin can't assistance y'all here. Otherwise, if the CLASSPATH is defined, for beginner, I suggest that you remove the CLASSPATH environment variable. From "Control Panel" ⇒ System ⇒ (Vista simply) Advanced arrangement settings ⇒ Switch to "Advanced" tab ⇒ Environment Variables ⇒ System variables (and also User variables) ⇒ Select variable "CLASSPATH" ⇒ Delete (Delete from both the Arrangement 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 lot can include the current directory (denoted past a single dot ".") in forepart of the existing form-paths. Read "Coffee Applications and Surround Variable" for more than discussion on CLASSPATH.
SYMPTOM: Can compile but cannot run the Hello-globe program (e.g., "java Hello" does not work!) ERROR Message (Post JDK 1.7): Fault: Chief method non found in class Hi. POSSIBLE SOLUTIONS: Check whether at that place is a main() method in your program, and the signature of your chief() every bit shown in the error message. (Advanced) External JAR Files and Native Libraries
Notes: This department is applicable to JDK prior to JDK 9. JDK 9 introduces a new level called "module" on top of packet, 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 Annal - 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).
External JAR Files (".jar")
If external JAR files are not properly included:
- During the compilation, y'all volition receive compilation fault "cannot find symbol" for classes belonging to the external packages.
- During execution, yous will get a runtime error "Could not find or load main course thirty" or "
NoClassDefFoundError".
To include external JAR files, y'all can either:
- (Prior to JDK ix) Copy all the JAR files of the external packages to the Java'due south Extension Directories (NOT applicable from JDK 9).
- For Windows, the JDK extension directory is located at "
<JAVA_HOME>\jre\lib\ext" (e.g., "c:\Program Files\Java\jdk1.eight.0_xx\jre\lib\ext"). - For macOS, the JDK extension directories are "
/Library/Java/Extensions" and "/Organization/Library/Java/Extensions". - For Ubuntu, the JDK extension directories are "
<JAVA_HOME>/jre/lib/ext" (east.g., "/usr/user/java/jdk1.viii.0_xx/jre/lib/ext") and "/usr/coffee/packages/lib/ext".
java.ext.dirs". You tin print its contents viaSystem.out.println(System.getProperty("coffee.ext.dirs")). - For Windows, the JDK extension directory is located at "
- Y'all can as well include all the JAR files in the
CLASSPATHenvironment variable.CLASSPATHmay comprise directories (of Java classes) or JAR files (single-file annal of Java classes). If you ready theCLASSPATH, you must as well include the current directory (denoted as ".").- For Windows, set the
CLASSPATHin Command Panel ⇒ Organization ⇒ Advanced organisation settings ⇒ Advanced ⇒ Environs 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 macOS: Edit
~/.profileor~/.bash_profile(or/etc/contourfor organisation-wide setting) to include the following line at the stop of the file:export CLASSPATH=.:path1/thirty.jar:path2/yyy.jar
The entries are separated past colon (:).
- For Windows, set the
- Yous can too set the
CLASSPATHin thejavac/javacommand-line via the selection-cp <paths>(or-classpath <paths>), 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
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 exist kept in a directory accessible via JRE's Property "java.library.path", which unremarkably but not necessarily includes all the directories in the PATH surroundings variable.
Native libraries are not involved in the compilation. But if they are not properly included during runtime fourth dimension, you will get a runtime error "coffee.lang.UnsatisfiedLinkError: no xxx in java.library.path".
To include external native libraries:
- Copy the native libraries into a organization library directory, e.g.,
c:\windows\system32(Windows),/usr/libor/usr/local/lib(macOS/Unix). You can verify that the directory is included in Coffee's System Property "java.library.path", viaSystem.out.println(System.getProperty("java.library.path")). - Yous tin can also set the native library path via the
java's command-line option-Djava.library.path=30, for example,coffee -Djava.library.path=30 ClassName
Eclipse/NetBeans
Using an IDE can greatly simplifies inclusion of external packages. Read "Eclipse How-To" or "NetBeans How-To".
Link to References & Resources
Source: https://www3.ntu.edu.sg/home/ehchua/programming/howto/jdk_howto.html
Posted by: wilsoncamerwas.blogspot.com

0 Response to "How To Install Java Se"
Post a Comment