How To Install Java Programming Language
How to Install JDK 17 (on Windows, macOS & Ubuntu) and Go Started with Java Programming
The Java Development Kit (JDK), officially named "Java Platform Standard Edition" or "Java SE", is needed for writing and running Coffee programs.
JDK Variants
At that place are few variants of JDK:
- OpenJDK: Currently, the "OpenJDK" developed past Oracle and the Java community (@ https://openjdk.coffee.net/) provides a gratis and open-source JDK official reference implementation.
- OracleJDK: This article is based on the "OracleJDK" (@ https://www.oracle.com/java/) (due to legacy), which is complimentary for personal and development use simply 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 announced Java in September 23, 1995.
- JDK i.0 (January 1996): Originally called Oak (named later on the oak tree exterior James Gosling's office). Renamed to Coffee one in JDK one.0.ii.
- JDK one.1 (February 1997): Introduced AWT event model, inner class, JavaBean, JDBC, and RMI.
- J2SE 1.two (JDK i.2) (December 1998): Re-branded as "Java 2" and renamed JDK to J2SE (Java 2 Standard Edition). Also released J2EE (Java ii Enterprise Edition) and J2ME (Java 2 Micro Edition). Included JFC (Coffee Foundation Classes - Swing, Accessibility API, Java 2D, Pluggable Expect & Feel, and Elevate & Driblet). Too introduced Collection Framework and JIT compiler.
- J2SE 1.3 (JDK 1.three) (May 2000): Introduced Hotspot JVM.
- J2SE 1.iv (JDK 1.4) (Feb 2002): Introduced
assertstatement, not-blocking IO (nio), logging API, epitome IO, Java webstart, regular expression (regex) support. - J2SE v.0 (JDK 5) (September 2004): Officially called v.0 instead of 1.5 (by dropping the i.). Introduced generics, autoboxing/unboxing, annotation, enum, varargs, for-each loop, static import. Run into "JDK 5 New Features".
- Coffee SE 6 (JDK half-dozen) (Dec 2006): Renamed J2SE to Coffee SE (Java Platform Standard Edition). No new linguistic communication features. See "JDK 6 New Features".
- Java SE 7 (JDK seven) (July 2022): Showtime version after Oracle purchased Dominicus Microsystem - aslo called OracleJDK. Introduced Strings in
switchstatement, Binary integer literals, allowing underscores in numeric literals, improved type inference for generic case creation (or diamond operator<>), Catching multiple exception types and rethrowing exceptions with improved type checking. Run into "JDK 7 New Features". - Java SE viii LTS (JDK eight) (March 2022): Included back up for Lambda expressions, default and static methods in interfaces, improved collection, and JavaScript runtime. Too integrated JavaFX graphics subsystem. Meet "JDK 8 New Features".
- Java SE 9 (JDK nine) (September 21, 2022): Introduced modularization of the JDK (
module) nether projection Jigsaw, the Java Shell (jshell), and more. See "JDK 9 New Features". - Coffee SE x (18.3) (JDK ten) (March 2022): Introduced
varfor type inference local variable (similar to JavaScript). Introduced time-based release versioning with two releases each twelvemonth, in March and September, denoted asYY.M.Removed native-header generation tooljavah. See "JDK 10 New Features". - Java SE 11 LTS (18.9) (JDK 11) (September 2022): Extended
varto lambda expression. Standardize HTTP client injava.net.http. Support TLS i.three. Clean upwards the JDK and the installation package (removed JavaFX, JavaEE, CORBA modules, deprecated Nashorn JavaScript engine). OracleJDK is no longer gratuitous for commercial use, only OpenJDK is notwithstanding gratuitous. See "JDK xi New Features". - Coffee SE 12 (xix.3) (JDK 12) (March 2022): Switch Expression (preview). See "JDK 12 New Features".
- Java SE 13 (xix.9) (JDK xiii) (September 2022): Switch Expression (preview), Multi-line Text Block (preview). See "JDK xiii New Features".
- Java SE xiv (20.3) (JDK 14) (March 2022): Records (preview)
- Coffee SE 15 LTS (20.9) (JDK fifteen) (September 2022):
- Java SE xvi (JDK xvi) (March 2022):
- Java SE 17 LTS (JDK 17) (September 2022):
- Java SE 18 (JDK 18) (March 2022):
"JDK" or "JRE"?
JRE (Java Runtime), which include a Coffee Virtual Car and core libraries, 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 instead of just running Coffee programs, you lot should install JDK, which includes JRE.
How To Install JDK on Windows
Footstep 0: Un-Install Older Version(southward) of JDK/JRE
I recommend that you install merely the latest JDK. Although you tin can install multiple versions of JDK/JRE concurrently, it is messy.
If you accept previously installed older version(s) of JDK/JRE, united nations-install ALL of them. Goto "Control Console" ⇒ (optional) "Programs" ⇒ "Programs and Features" ⇒ Un-install ALL programs begin with "Java", such as "Java SE Development Kit ...", "Java SE Runtime ...", "Coffee Ten Update ...", and etc.
Step one: Download JDK
- Goto JDK (or Java SE) download site @ https://www.oracle.com/coffee/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" - about 152MB).
Step 2: Install JDK
Run the downloaded installer. Accept the defaults and follow the screen instructions to consummate the installation. By default, JDK is installed in directory "C:\Program Files\Java\jdk-17.0.{ten} ", where {x} denotes the running "update number" starting from i.
Launch "File Explorer". Navigate to "C:\Plan Files\Coffee" to inspect this directories. Take notation 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, xvi - kept for abyss) 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 for executable programs.
JDK'southward programs (such as Coffee compiler "javac.exe" and Java runtime "java.exe") reside in the sub-directory "bin" of the JDK installed directory. JDK's "bin" needs to exist added into the PATH.
Prior to JDK fifteen, yous need to explicitly add JDK's "bin" into the PATH. Starting from JDK 15, the installation process adds the directory "C:\Plan Files\Common Files\Oracle\Coffee\javapath" to the PATH. The "javapath" directory is a link to "javapath_target_xxxxxx", which contains a copy of the post-obit JDK programs:
-
java.exe: Java Runtime -
javac.exe: Java Compiler -
javaw.exe: Java Runtime for Windows Panel-less -
jshell.exe: Java Command-line Trounce (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 environs variable in Windows 10:
- Launch "Control Console" ⇒ (Optional) "Organization and Security" ⇒ "Arrangement" ⇒ Click "Avant-garde organisation 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:
Yous shall meet a TABLE listing all the existing PATH entries (if not, goto next step). Click "New" ⇒ Click "Scan" and navigate to your JDK's "bin" directory, i.e., "c:\Program Files\Java\jdk-15.0.{x}\bin", where{x}is your installation update number ⇒ Select "Move Upward" to move this entry all the way to the TOP. - For Older Windows 10 (Fourth dimension to alter your reckoner!):
(CAUTION: Read this paragraph 3 times earlier doing this step! Don't push button "Apply" or "OK" until you are 101% sure. There is no Disengage!!!)
(To be SAFE, copy the content of the "Variable value" to Notepad before irresolute it!!!)
In "Variable value" field, Append "c:\Program Files\Coffee\jdk-fifteen.0.{x}\bin" (where{ten}is your installation update number) IN Front end of all the existing directories, followed past a semi-colon (;) to separate the JDK's bin directory from the rest of the existing directories. Exercise Not DELETE whatever existing entries; otherwise, some existing applications may not run.Variable name : PATH Variable value : c:\Program Files\Java\jdk-15.0.{x}\bin; [do not delete exiting entries...]
You need to re-started CMD for the new environs settings to take effect.
Step 4: Verify the JDK Installation
Launch a CMD via ane of the following means:
- Click "Search" push button ⇒ Type "cmd" ⇒ Choose "Command Prompt", or
- Right-click "Beginning" button ⇒ run... ⇒ enter "cmd", or
- Click "Start" push ⇒ Windows System ⇒ Command Prompt
Consequence the following commands to verify your JDK installation:
- (Skip for JDK 17, 16, xv) Outcome "
path" command to list the contents of thePATHenvironment variable. 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 coffee -version coffee version "17.0.1" 2022-10-19 LTS Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39) Java HotSpot(TM) 64-Bit Server VM (build 17.0.ane+12-LTS-39, mixed mode, sharing)
Step five: Write a Hello-World Coffee Program
- Create a directory to keep your works, east.thousand., "
d:\myProject" or "c:\myProject". Practice Not save your works in "Desktop" or "Documents" as they are hard to locate. The directory name shall not comprise blank or special characters. Use meaningful but short proper noun as it is easier to blazon. - Launch a programming text editor (such as TextPad, NotePad++, Sublime Text, Atom). Brainstorm with a new file and enter the following source code. Save the file as "
Hi.java", under your piece of work directory (eastward.yard.,d:\myProject).public course Hello { public static void main(String[] args) { Organization.out.println("How-do-you-do, world!"); } }
Footstep vi: Compile and Run the Howdy-World Java Program
To compile the source code "Howdy.java":
- Starting time a CMD Shell (Search ⇒ enter "cmd" ⇒ select "Control Prompt").
- Set the Electric current Drive to the drive where you saved your source file "
Hi.java".
If you use drive "c", skip this step.
Else if you use drive "d", enter "d:" as follow:d: D:\30> - Ready 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> - Effect a
dir(List Directory) command to ostend that your source file is present in the current directory.dir ...... xx-thirty-xx twenty:xx PM 277 Hello.java ...... - Invoke the JDK compiler "
javac" to compile the source code "Hello.java".javac Hello.coffee
The compilation is successful if the command prompt returns. Otherwise, mistake letters would exist shown. Correct the errors in your source file and re-compile. Check "Common JDK Installation Errors", if yous see problem compiling your program. - The output of the compilation is a Java class called "
Hello.class". Issue adir(List Directory) command once more to check for the output.dir ...... xx-30-xx xx:twenty PM 416 Hello.class xx-xxx-twenty 20:xx PM 277 Hello.java ......
To run the plan, invoke the Java Runtime " coffee ":
java Hullo Hello, globe! Everything that can possibly go wrong will become wrong: Read "JDK Installation Common Errors".
Footstep 7: (For Avant-garde Users Simply) 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 y'all to get through some of the source files such as "Cord.java", "Math.java", and "Integer.java", under "java\lang", to learn how experts program.
How to Install JDK on macOS
Stride 1: Bank check if JDK has been Pre-Installed
To check if JDK has been installed, open up a "Last" (Search "Concluding"; or Finder ⇒ Go ⇒ Utilities ⇒ Terminal) and effect this command:
javac -version
- If a JDK version number is returned (e.g.,
JDK x.x.10), so JDK has already been installed. If the JDK version is prior to eleven, proceed to Footstep 2 to install the latest JDK; otherwise, go on to "Step iii: Write a Hello-world Java program". - If message "control not found" appears, JDK is NOT installed. Proceed to the "Stride 2: Install JDK".
- If message "To open javac, yous need a Java runtime" appears, select "Install" and follow the instructions to install JDK. Then, go along to "Step iii: Write a Howdy-world Java plan".
Stride 2: Download JDK
- Goto JDK (or Java SE) download site @ https://www.oracle.com/java/technologies/javase-downloads.html.
- Under "Java SE Development Kit 17.0.{x} downloads".
- Select "macOS" ⇒ Download the "x64 Installer" (e.g., "
jdk-17_windows-x64_bin.exe" - virtually 152MB). - Nether "Oracle JDK", click "JDK Download".
- Download the "x64 DMG installer" (e.g,
jdk-17_macos-x64_bin. dmg- well-nigh 168MB (I am assuming that you are using Intel processor, not ARM processor. Mac is moving to ARM processor.)
Pace 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 up a "Terminal" and issue these commands.
javac -version javac 17.0.{x} coffee -version java version "17.0.{x}" ...... which javac /usr/bin/javac which coffee /usr/bin/java
Step 3: Write a Hello-Earth Java Plan
- Create a directory chosen "
myProject" nether your "home" directory (Launch "Finder" ⇒ "Go" ⇒ "Home"; Select "File" ⇒ "New Folder" ⇒ "myProject").
In macOS/Unix, the "habitation" directory of the current user tin can exist referenced as "~". Hence, this new directory tin can exist referenced as "~/myProject". - Use a programming text editor (such as Sublime Text or Cantlet) to input the post-obit source code and salve as "
Hi.java" under the directory "~/myProject".
(If you use macOS's default text editor "TextEdit" (NOT recommended), you demand to open a new file ⇒ cull "Format" ⇒ "Make Plain Text" ⇒ Enter the source code ⇒ Salvage as "Hello.java".)public class Hello { public static void main(Cord[] args) { Arrangement.out.println("Hello, globe from Mac!"); } }
Stride 4: Compile and Run the Hello-World Java Programme
- To compile the source code "
Hi.java", open a new "Last" ("Go" ⇒ "Utilities" ⇒ "Concluding") and issue these commands (as illustrated):cd ~/myProject ls Hello.java ...... javac Hello.java ls Hello.class Hello.coffee ......
- To run the Hi-globe, invoke the Java Runtime "
java" as follows:coffee Hi Hello, globe from Mac!
How to Install JDK (15) on Ubuntu
Nosotros shall effort both the OpenJDK (free and open-source) and the Oracle JDK (costless for personal and development, simply non free for production).
Footstep 0: Check if JDK has already been Installed
Open up a Concluding and issue this command:
$ javac -version
If a JDK version number (e.g., "javac 10.x.x") appears, JDK has already been installed. You can skia the installation and goto Open2.
Step 1a: Install OpenJDK
[TODO]
To remove OpenJDK, event command:
$ sudo apt-get purge openjdk-\*
Step 1b: Install Oracle JDK
- Goto Oracle JDK (Java SE) download site @ https://www.oracle.com/coffee/technologies/javase-downloads.html ⇒ Under "Oracle JDK", click "JDK Download" ⇒ Select "Linux x64 Compressed Archive" bundle (due east.g., "
jdk-15.0.{ten}-linux-x64_bin.tar.gz" - 179MB). The tarball volition be downloaded in directory "~/Downloads", past 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:$ cd /usr/local $ sudo mkdir java
Extract the downloaded packet (Cheque your downloaded filename!)$ cd /usr/local/java $ sudo tar xzvf ~/Downloads/jdk-fifteen.0.{x}-linux-x64_bin.tar.gzJDK shall be extracted in a folder "/usr/local/java/jdk-15.0.{10}", where{x}is the update number. - Inform the Ubuntu to employ this JDK/JRE:
$ sudo update-alternatives --install "/usr/bin/coffee" "java" "/usr/local/java/jdk-15.0.{x}/bin/java" 1 $ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk-15.0.{10}/bin/javac" 1 $ sudo update-alternatives --install "/usr/bin/jshell" "coffee/usr/local/java/jdk-xv.0.{x}/bin/jshell" 1 $ sudo update-alternatives --set coffee /usr/local/java/jdk-15.0.{x}/bin/java $ sudo update-alternatives --fix javac /usr/local/java/jdk-xv.0.{10}/bin/javac $ sudo update-alternatives --set jshell /usr/local/java/jdk-15.0.{x}/bin/jshellThe above 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 aforementioned function (e.one thousand., different version of JDKs). It sets up symlinks thru/etc/alternativesto refer to the actual programs to be used.
$ ls -ld /usr/bin/java* lrwxrwxrwx 1 root root twenty xxx xx xx:xx /usr/bin/java -> /etc/alternatives/java ...... $ ls -ld /etc/alternatives/java* lrwxrwxrwx 1 root root 20 xxx 20 twenty:xx /etc/alternatives/java -> /usr/local/java/jdk-15.0.{ten}/bin/java ...... java -> /usr/bin/coffee (thru PATH) -> /etc/alternatives/java -> /usr/local/java/jdk-15.0.{x}/bin/java (bodily programme)
Alternatively, you can include the JDK's bin into the PATH directly. - To verify the JDK installation, event these commands:
$ javac -version javac fifteen.0.{x} $ java -version java version "15.0.{x}" ...... $ which javac /usr/bin/javac $ which java /usr/bin/java
- (Don't Do this footstep - It is taken care by "alternatives" in Step 3. Go along hither to show you lot how to gear up PATH.)
Add JDK's binary directory ("bin") to the "PATH" by editing "/etc/contour":$ 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.{x} export PATH=$JAVA_HOME/bin:$PATHRerun the configuration file by:$ source /etc/profile $ echo $JAVA_HOME /usr/local/java/jdk-xv.0.{ten} $ echo $PATH /usr/local/coffee/jdk-15.0.{x}/bin:......
Stride 2: Compile and Run a Hello-earth Java Program
- File Explorer ⇒ Habitation ⇒ Create a new binder called "
myProject" to keep our works. - Open up "Text Editor" (gedit). Enter the following source code and save as "
How-do-you-do.java" under the "~/myProject" directory created earlier.public class Hullo { public static void principal(String[] args) { System.out.println("Hello, globe from Ubuntu!"); } } - To compile the Hello-world Coffee program, launch a Terminal and issue these commands:
$ cd ~/myProject $ ls ...... Hullo.coffee ...... $ javac How-do-you-do.java $ ls ...... Hello.form ......
- Run the How-do-you-do-world Java program:
$ java Hello Hello, world from Ubuntu!
Notes: Starting from JDK 11, you can compile and run the how-do-you-do-world in one single step via:
$ coffee Howdy.java Hello, globe from Ubuntu! Source-Code Editors & IDEs for Coffee Programming
Eclipse IDE
- You lot need to first install Eclipse. Read "How to Install Eclipse".
- javaan then keep to write your first Java program. Read "Writing your first Coffee Programme with Eclipse".
- Eclipse allow you to debug program graphically. Read "Debugging plan in Eclipse".
NetBeans IDE
- You need to first install NetBeans. Read "How to Install NetBeans".
- You can then proceed to write your commencement Java program. Read "Writing your first Coffee plan with NetBeans".
- NetBeans allow you to debug plan graphically. Read "Debugging program in NetBeans".
Visual Studio (VS) Code IDE
Click HERE, look for "VS Code for Java Programming"
Sublime Text (for Windows, macOS, Linux)
Click Hither, await for "Sublime Text for Java Programming"
Atom (for Windows, macOS, Linux)
[TODO]
TextPad (for Windows just)
Click Hither, await for "TextPad for Coffee Programming".
NotePad++ (for Windows but)
Click HERE, look for "NotePad++ for Coffee Programming".
(JDK eleven New Feature) Launch Single-Source-File
From JDK 11, you lot tin "compile and run" a unmarried-file program in i stride, without explicit compilation.
- Write a "
Hello.java" (see previous section). - Delete "
Hello.form", if it exists. - You tin can compile/run "
Hello.coffee" in i command as follows:java Hello.java Hello, world!
Notes:
- This is applicative to single source-file only.
- No demand to employ
javacto compile the program. - It compiles in memory (without producing a
.gradefile), and run. - This feature is introduced for beginners to learn Coffee, and for professionals to test a Java feature.
- The filename and classname need not be the same.
How To Fix JAVA_HOME Surroundings Variable
Many Java applications (such as Tomcat) require the environment variable JAVA_HOME to exist set to the JDK installed directory.
See "How to set JAVA_HOME for Windows" or "How to prepare JAVA_HOME for macOS/Linux".
Common Errors in installing JDK
SYMPTOM: Cannot compile Coffee program from the CMD shell (e.one thousand., "javac Hello.java" does not work!) ERROR Bulletin: 'javac' is not recognized as an internal or external control, operable program or batch file. Likely CAUSES: The PATH surround variable, which maintains a list of search paths for executable programs (including "javac.exe"), does not include JDK'south bin directory. POSSIBLE SOLUTIONS: 1) Start a CMD shell (click "Start" button ⇒ "run..." ⇒ enter "cmd") and event a path command: prompt> path PATH=....... 2) Check if it includes your JDK's "bin" directory. For case, suppose that your JDK is installed in "c:\plan files\coffee\jdk-fifteen.0.1", then PATH should include "c:\program files\java\jdk-fifteen.0.1\bin". Otherwise, include JDK'southward bin directory in the PATH surroundings variable. Read "Footstep 3 of How to install JDK".
SYMPTOM: Can compile just cannot run Java program from the CMD shell (e.k., "java Hello" does non work!) ERROR MESSAGE (Post JDK 1.vii): Error: Could not find or load primary class Xxx Fault Bulletin (Pre JDK 1.vii): Exception in thread "master" java.lang.NoClassDefFoundError: Thirty Probable CAUSES: ane) The Java course (in this example, Hello.course) is Non in the current directory. ii) The CLASSPATH environment variable is set, but does non include the electric current directory ".". POSSIBLE SOLUTIONS: one) Result a "dir" command to list the contents of the current directory. Check that it contains the Java class to be run (e.g., How-do-you-do.class). You need to compile the source program (".java") to become the grade file (".class"). 2) If the Coffee class is nowadays in the current directory, event a "set up classpath" command to cheque its settings: prompt> fix classpath CLASSPATH=....... If yous receive the message "Environment variable CLASSPATH not defined" and your program is right, I can't help you hither. Otherwise, if the CLASSPATH is defined, for beginner, I advise that you lot remove the CLASSPATH surroundings variable. From "Command Panel" ⇒ System ⇒ (Vista only) Advanced arrangement settings ⇒ Switch to "Advanced" tab ⇒ Environment Variables ⇒ System variables (and likewise User variables) ⇒ Select variable "CLASSPATH" ⇒ Delete (Delete from both the System variables and User variables) 3) (For Advanced Users Only) If CLASSPATH is non set, it is defaulted to the current directory. However, if CLASSPATH is set, the current directory is Not implicitly included. Yous can include the current directory (denoted by a single dot ".") in front of the existing class-paths. Read "Coffee Applications and Environment Variable" for more discussion on CLASSPATH.
SYMPTOM: Tin compile but cannot run the Hello-world program (e.g., "java Hello" does non work!) ERROR MESSAGE (Mail JDK ane.seven): Fault: Main method non found in class Hello. POSSIBLE SOLUTIONS: Check whether there is a main() method in your program, and the signature of your master() as shown in the error bulletin. (Avant-garde) External JAR Files and Native Libraries
Notes: This section is applicable to JDK prior to JDK 9. JDK nine introduces a new level called "module" on superlative of package, and "jmod" files for Java modules. Need to revise this department for JDK 9.
External Java API packages (such every bit Servlet API, MySQL Connector/J, JOGL, JUnit) are often distributed in JAR files (Coffee Archive - a single-file bundle of many Java classes similar to Zippo or TAR), with perchance Native Libraries (".lib" and ".dll" in Windows, or ".a" and ".and so" in Linux/macOS).
External JAR Files (".jar")
If external JAR files are not properly included:
- During the compilation, you will receive compilation mistake "cannot observe symbol" for 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:
- (Prior to JDK 9) Copy all the JAR files of the external packages to the Java'due south Extension Directories (Not applicable from JDK nine).
- For Windows, the JDK extension directory is located at "
<JAVA_HOME>\jre\lib\ext" (e.chiliad., "c:\Programme Files\Java\jdk1.eight.0_xx\jre\lib\ext"). - For macOS, 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.one thousand., "/usr/user/coffee/jdk1.viii.0_xx/jre/lib/ext") and "/usr/java/packages/lib/ext".
coffee.ext.dirs". You tin 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
CLASSPATHenvironment variable.CLASSPATHmay contain directories (of Java classes) or JAR files (single-file archive of Coffee classes). If y'all set theCLASSPATH, you must also include the current directory (denoted as ".").- For Windows, set the
CLASSPATHin Command Panel ⇒ System ⇒ Avant-garde system settings ⇒ Advanced ⇒ Environment Variables ⇒ System Variables ⇒ New ⇒ In "Variable proper name", enter "CLASSPATH" ⇒ In "Variable value", enter ".;path1\30.jar;path2\yyy.jar", where the entries are separated by a semi-colon (;). - For Linux and macOS: Edit
~/.contouror~/.bash_profile(or/etc/profilefor system-broad setting) to include the following line at the stop of the file:consign CLASSPATH=.:path1/thirty.jar:path2/yyy.jar
The entries are separated by colon (:).
- For Windows, set the
- You can also set the
CLASSPATHin thejavac/javacommand-line via the option-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.coffee java -cp .:path1/thirty.jar:path2/yyy.jar ClassName
External Native Libraries (".lib", ".dll", ".a", ".and then")
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'southward static (Archive) library), or ".then" (Unix'southward Shared Object library).
Native Libraries are to be kept in a directory attainable via JRE'due south Belongings "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, yous volition become a runtime mistake "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:\windows\system32(Windows),/usr/libor/usr/local/lib(macOS/Unix). You can verify that the directory is included in Java's System Property "java.library.path", viaOrganisation.out.println(System.getProperty("java.library.path")). - You can besides set the native library path via the
java's command-line selection-Djava.library.path=xxx, for example,java -Djava.library.path=xxx ClassName
Eclipse/NetBeans
Using an IDE can profoundly 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: craftpaided.blogspot.com

0 Response to "How To Install Java Programming Language"
Post a Comment