banner



How To Check If Jdk Is Installed

How to Install JDK 17 (on Windows, macOS & Ubuntu) and Get Started with Java Programming

The Java 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:

  1. OpenJDK: Currently, the "OpenJDK" adult by Oracle and the Java community (@ https://openjdk.java.net/) provides a free and open-source JDK official reference implementation.
  2. 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 complimentary for commercial use.
JDK Versions

Reference: "Java Version History" @ https://en.wikipedia.org/wiki/Java_version_history.

  1. JDK Alpha and Beta (1995): Sun Microsystem announced Coffee in September 23, 1995.
  2. JDK 1.0 (January 1996): Originally called Oak (named after the oak tree outside James Gosling's function). Renamed to Java 1 in JDK ane.0.2.
  3. JDK one.1 (Feb 1997): Introduced AWT upshot model, inner form, JavaBean, JDBC, and RMI.
  4. J2SE 1.two (JDK i.ii) (December 1998): Re-branded every bit "Java 2" and renamed JDK to J2SE (Java 2 Standard Edition). Also released J2EE (Coffee 2 Enterprise Edition) and J2ME (Java two Micro Edition). Included JFC (Coffee Foundation Classes - Swing, Accessibility API, Coffee 2nd, Pluggable Look & Feel, and Drag & Drop). As well introduced Collection Framework and JIT compiler.
  5. J2SE 1.three (JDK 1.iii) (May 2000): Introduced Hotspot JVM.
  6. J2SE 1.four (JDK 1.4) (February 2002): Introduced assert argument, not-blocking IO (nio), logging API, image IO, Java webstart, regular expression (regex) support.
  7. J2SE 5.0 (JDK v) (September 2004): Officially called 5.0 instead of i.5 (by dropping the 1.). Introduced generics, autoboxing/unboxing, notation, enum, varargs, for-each loop, static import. See "JDK 5 New Features".
  8. Java SE six (JDK 6) (Dec 2006): Renamed J2SE to Java SE (Java Platform Standard Edition). No new language features. See "JDK six New Features".
  9. Coffee SE 7 (JDK vii) (July 2022): First version subsequently Oracle purchased Sun Microsystem - aslo called OracleJDK. Introduced Strings in switch statement, 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 type checking. Run into "JDK 7 New Features".
  10. Coffee SE viii LTS (JDK 8) (March 2022): Included support for Lambda expressions, default and static methods in interfaces, improved collection, and JavaScript runtime. Also integrated JavaFX graphics subsystem. Run across "JDK viii New Features".
  11. Coffee SE 9 (JDK 9) (September 21, 2022): Introduced modularization of the JDK (module) under project Jigsaw, the Coffee Shell (jshell), and more. Meet "JDK 9 New Features".
  12. Java SE ten (18.three) (JDK 10) (March 2022): Introduced 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 x New Features".
  13. Java SE 11 LTS (xviii.9) (JDK eleven) (September 2022): Extended var to lambda expression. Standardize HTTP client in java.net.http. Support TLS one.three. Make 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, but OpenJDK is even so free. See "JDK 11 New Features".
  14. Java SE 12 (xix.3) (JDK 12) (March 2022): Switch Expression (preview). See "JDK 12 New Features".
  15. Java SE thirteen (nineteen.ix) (JDK 13) (September 2022): Switch Expression (preview), Multi-line Text Block (preview). See "JDK 13 New Features".
  16. Java SE xiv (20.iii) (JDK 14) (March 2022): Records (preview)
  17. Coffee SE fifteen LTS (twenty.ix) (JDK 15) (September 2022):
  18. Java SE xvi (JDK 16) (March 2022):
  19. Java SE 17 LTS (JDK 17) (September 2022):
  20. Java SE eighteen (JDK xviii) (March 2022):
"JDK" or "JRE"?

JRE (Java Runtime), which include a Java Virtual Motorcar and core libraries, is needed for running Java programs. JDK (Java Development Kit), which includes JRE plus the development tools (such equally compiler and debugger), is demand for writing as well as running Java programs. In other words, JRE is a subset of JDK. Since you are supposed to write Coffee Programs instead of but running Java programs, you lot should install JDK, which includes JRE.

How To Install JDK on Windows

Step 0: Un-Install Older Version(s) of JDK/JRE

I recommend that yous install only the latest JDK. Although you can install multiple versions of JDK/JRE concurrently, it is messy.

If you take previously installed older version(due south) of JDK/JRE, un-install ALL of them. Goto "Control Panel" ⇒ (optional) "Programs" ⇒ "Programs and Features" ⇒ Un-install ALL programs brainstorm with "Java", such as "Java SE Development Kit ...", "Coffee SE Runtime ...", "Java 10 Update ...", and etc.

Step 1: Download JDK
  1. Goto JDK (or Coffee SE) download site @ https://www.oracle.com/java/technologies/javase-downloads.html.
  2. Under "Coffee SE Evolution Kit 17.0.{ten} downloads".
  3. Select "Windows" ⇒ Download the "x64 Installer" (east.g., "jdk-17_windows-x64_bin.exe" - about 152MB).
Step 2: Install JDK

Run the downloaded installer. Have the defaults and follow the screen instructions to complete the installation. By default, JDK is installed in directory "C:\Program Files\Java\jdk-17.0.{x} ", where {10} denotes the running "update number" starting from i.

Launch "File Explorer". Navigate to "C:\Program Files\Java" to inspect this directories. Have note 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 commodity (corresponding to environment variable %JAVA_HOME% in Windows or $JAVA_HOME in Unix/macOS).

Step 3: (SKIP for JDK 17, 16, 16 - kept for completeness) 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'due south programs (such as Java compiler "javac.exe" and Coffee runtime "coffee.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'southward "bin" into the PATH. Starting from JDK xv, 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 contains a copy of the following JDK programs:

  • java.exe: Java Runtime
  • javac.exe: Java Compiler
  • javaw.exe: Java Runtime for Windows Console-less
  • jshell.exe: Java Control-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:

  1. Launch "Command Panel" ⇒ (Optional) "Organisation and Security" ⇒ "System" ⇒ Click "Advanced system settings" on the left pane.
  2. Switch to "Advanced" tab ⇒ Click "Environs Variables" button.
  3. Under "System Variables" (the bottom pane), curl down to select variable "Path" ⇒ Click "Edit...".
  4. For Newer Windows 10:
    You shall see a TABLE listing all the existing PATH entries (if not, goto side by side step). Click "New" ⇒ Click "Browse" and navigate to your JDK's "bin" directory, i.eastward., "c:\Plan Files\Java\jdk-15.0.{x}\bin ", where {10} is your installation update number ⇒ Select "Move Upwardly" to movement this entry all the style to the TOP.
  5. For Older Windows ten (Time to change your reckoner!):
    (Circumspection: Read this paragraph 3 times earlier doing this pace! Don't push "Apply" or "OK" until you are 101% sure. There is no Disengage!!!)
    (To be Prophylactic, re-create the content of the "Variable value" to Notepad earlier changing it!!!)
    In "Variable value" field, Append "c:\Plan Files\Java\jdk-15.0.{ten}\bin" (where {x} is your installation update number) IN FRONT of all the existing directories, followed by a semi-colon (;) to split the JDK's bin directory from the residue of the existing directories. Exercise Not DELETE any existing entries; otherwise, some existing applications may non run.
    Variable name  :                              PATH                            Variable value :                              c:\Programme Files\Coffee\jdk-15.0.{x}\bin;                            [do non delete exiting entries...]            

Yous need to re-started CMD for the new environment settings to have event.

Pace 4: Verify the JDK Installation

Launch a CMD via one of the following means:

  1. Click "Search" button ⇒ Type "cmd" ⇒ Choose "Command Prompt", or
  2. Correct-click "Beginning" button ⇒ run... ⇒ enter "cmd", or
  3. Click "Start" button ⇒ Windows System ⇒ Control Prompt

Issue the following commands to verify your JDK installation:

  1. (Skip for JDK 17, 16, 15) Issue "path" command to listing the contents of the PATH surroundings variable. Check to make sure that your JDK'southward "bin" is listed in the PATH.
                  path              PATH=c:\Program Files\Java\jdk-{xx.y.z}\bin;other entries...            
  2. Upshot the following commands to verify that JDK/JRE are properly installed and display their version:
                    javac -version              javac                17.0.1                                          java -version              java version "17.0.1" 2022-x-19 LTS Coffee(TM) SE Runtime Environment (build 17.0.1+12-LTS-39) Java HotSpot(TM) 64-Bit Server VM (build 17.0.i+12-LTS-39, mixed mode, sharing)            
Step five: Write a Hullo-Globe Java Programme
  1. Create a directory to continue your works, due east.grand., "d:\myProject" or "c:\myProject". Exercise NOT salve 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 brusque proper name every bit information technology is easier to type.
  2. Launch a programming text editor (such as TextPad, NotePad++, Sublime Text, Atom). Begin with a new file and enter the following source lawmaking. Salve the file as "Hi.java", nether your work directory (e.yard., d:\myProject).
                    public class Hullo {      public static void main(String[] args) {       System.out.println("Hello, world!");    } }
Step half-dozen: Compile and Run the Hello-Globe Coffee Program

JavaBasics_GettingStarted.png

To compile the source code "Hi.java":

  1. Start a CMD Shell (Search ⇒ enter "cmd" ⇒ select "Command Prompt").
  2. Set the Electric current Drive to the drive where you saved your source file "Howdy.java".
    If you utilise drive "c", skip this pace.
    Else if you use bulldoze "d", enter " d: " as follow:
                  d:              D:\30>            
  3. Set the Current Working Directory to the directory that you saved your source file via the cd (Change Directory) command. For case, suppose that your source file is saved in directory "myProject".
                  cd \myProject              D:\myProject>            
  4. Effect a dir (Listing Directory) command to confirm that your source file is present in the current directory.
                  dir              ...... 20-30-20  twenty:xx PM               277                Howdy.java                ......            
  5. Invoke the JDK compiler " javac " to compile the source lawmaking "Hello.java".
                  javac How-do-you-do.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. Cheque "Mutual JDK Installation Errors", if you lot run into trouble compiling your program.
  6. The output of the compilation is a Java course called "Hello.class". Upshot a dir (Listing Directory) command again to check for the output.
                  dir              ...... xx-xxx-xx  twenty:xx PM               416                Hullo.class                xx-xxx-xx  xx:xx PM               277 Hi.java ......            

To run the program, invoke the Java Runtime " java ":

          java How-do-you-do          Hello, world!        

Everything that can peradventure go incorrect will go wrong: Read "JDK Installation Common Errors".

Stride 7: (For Advanced Users Just) JDK'south Source Code

Source code for JDK is provided and kept in "<JAVA_HOME>\lib\src.zip" (or "<JAVA_HOME>\src.zip" prior to JDK nine). I strongly recommend that you to go through some of the source files such as "String.java", "Math.java", and "Integer.coffee", under "java\lang", to learn how experts program.

How to Install JDK on macOS

Step 1: Bank check if JDK has been Pre-Installed

To check if JDK has been installed, open a "Concluding" (Search "Terminal"; or Finder ⇒ Go ⇒ Utilities ⇒ Terminal) and issue this control:

          javac -version        
  • If a JDK version number is returned (e.m., JDK 10.x.x), then JDK has already been installed. If the JDK version is prior to 11, proceed to Step ii to install the latest JDK; otherwise, continue to "Pace 3: Write a Hello-world Java program".
  • If message "command non found" appears, JDK is Non installed. Continue 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, continue to "Footstep three: Write a Hello-world Java programme".
Step 2: Download JDK
  1. Goto JDK (or Java SE) download site @ https://world wide web.oracle.com/java/technologies/javase-downloads.html.
  2. Under "Java SE Development Kit 17.0.{10} downloads".
  3. Select "macOS" ⇒ Download the "x64 Installer" (eastward.g., "jdk-17_windows-x64_bin.exe" - virtually 152MB).
  4. Nether "Oracle JDK", click "JDK Download".
  5. Download the "x64 DMG installer" (e.g, jdk-17_macos-x64_bin. dmg - about 168MB (I am assuming that you are using Intel processor, not ARM processor. Mac is moving to ARM processor.)
Step 3: Install JDK/JRE
  1. Double-click the downloaded Disk Paradigm (DMG) file. Follow the screen instructions to install JDK/JRE.
  2. Squirt the DMG file.
  3. To verify your installation, open up a "Last" and result these commands.
                    javac -version              javac 17.0.{x}                            coffee -version              java version "17.0.{10}" ......                            which javac              /usr/bin/javac                            which java              /usr/bin/coffee            
Footstep 3: Write a Hello-World Java Program
  1. Create a directory called "myProject" under your "home" directory (Launch "Finder" ⇒ "Go" ⇒ "Dwelling"; Select "File" ⇒ "New Binder" ⇒ "myProject").
    In macOS/Unix, the "abode" directory of the current user tin can exist referenced as "~". Hence, this new directory tin can be referenced as "~/myProject".
  2. Use a programming text editor (such as Sublime Text or Cantlet) to input the following source code and save as "Hello.coffee" under the directory "~/myProject".
    (If you use macOS's default text editor "TextEdit" (NOT recommended), you demand to open a new file ⇒ choose "Format" ⇒ "Make Manifestly Text" ⇒ Enter the source code ⇒ Save as "Hello.java".)
                    public class Hi {       public static void master(String[] args) {       Arrangement.out.println("Hello, world from Mac!");    } }
Stride 4: Compile and Run the Howdy-Earth Coffee Program

MacJavaCompile.png

  1. To compile the source code "Hello.java", open up a new "Terminal" ("Go" ⇒ "Utilities" ⇒ "Terminal") and issue these commands (as illustrated):
                    cd ~/myProject                            ls              Hello.java   ......                            javac Howdy.java                               ls              Hello.class   Hello.java   ......            
  2. To run the Howdy-world, invoke the Java Runtime "java" every bit follows:
                  java Hullo              Hi, world from Mac!            

How to Install JDK (15) on Ubuntu

Nosotros shall try both the OpenJDK (costless and open-source) and the Oracle JDK (free for personal and development, merely not free for product).

Step 0: Cheque if JDK has already been Installed

Open a Final and issue this control:

$          javac -version        

If a JDK version number (eastward.one thousand., "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, consequence command:

$          sudo apt-get purge openjdk-\*        
Step 1b: Install Oracle JDK
  1. Goto Oracle JDK (Coffee SE) download site @ https://www.oracle.com/java/technologies/javase-downloads.html ⇒ Nether "Oracle JDK", click "JDK Download" ⇒ Select "Linux x64 Compressed Annal" packet (due east.g., "jdk-xv.0.{10}-linux-x64_bin.tar.gz" - 179MB). The tarball will be downloaded in directory "~/Downloads", by default.
  2. We shall install JDK under "/usr/local/java" (or Ubuntu's default JDK directory /usr/lib/jvm; or /opt/coffee). First, create a directory "java" under "/usr/local". Open a Terminal and upshot these commands:
    $              cd /usr/local              $              sudo mkdir java            
    Extract the downloaded bundle (Bank check your downloaded filename!)
    $              cd /usr/local/java              $              sudo tar xzvf ~/Downloads/jdk-xv.0.{x}-linux-x64_bin.tar.gz            
    JDK shall be extracted in a folder "/usr/local/java/jdk-15.0.{x}", where {ten} is the update number.
  3. Inform the Ubuntu to use this JDK/JRE:
                    $              sudo update-alternatives --install "/usr/bin/coffee" "coffee" "/usr/local/coffee/jdk-15.0.{x}/bin/java" 1               $              sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk-fifteen.0.{x}/bin/javac" 1              $              sudo update-alternatives --install "/usr/bin/jshell" "java/usr/local/java/jdk-15.0.{x}/bin/jshell" 1               $              sudo update-alternatives --set coffee /usr/local/java/jdk-15.0.{x}/bin/java               $              sudo update-alternatives --gear up javac /usr/local/coffee/jdk-15.0.{ten}/bin/javac              $              sudo update-alternatives --set jshell /usr/local/java/jdk-15.0.{x}/bin/jshell            
    The above steps ready upwards symlinks java, javac, jshell at /usr/bin (which is in the PATH), that link to /etc/alternatives then to JDK bin directory.
    The "alternatives" organisation 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 exist used.
    $              ls -ld /usr/bin/coffee*              lrwxrwxrwx 1 root root twenty xxx xx xx:xx /usr/bin/java -> /etc/alternatives/java ......              $              ls -ld /etc/alternatives/java*              lrwxrwxrwx ane root root xx xxx xx twenty:twenty /etc/alternatives/java -> /usr/local/java/jdk-15.0.{x}/bin/java ......               java -> /usr/bin/java (thru PATH) -> /etc/alternatives/coffee -> /usr/local/java/jdk-15.0.{x}/bin/java (bodily program)
    Alternatively, yous can include the JDK's bin into the PATH directly.
  4. To verify the JDK installation, result these commands:
                    $              javac -version              javac 15.0.{10}               $              java -version              java version "15.0.{x}" ......               $              which javac              /usr/bin/javac              $              which java              /usr/bin/java            
  5. (Don't Practice this step - Information technology is taken care by "alternatives" in Step 3. Keep here to show yous how to set PATH.)
    Add 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", supersede "{10}" with the bodily number:
    consign JAVA_HOME=/usr/local/coffee/jdk-15.0.{ten} export PATH=$JAVA_HOME/bin:$PATH
    Rerun the configuration file by:
                    $              source /etc/profile               $              echo $JAVA_HOME              /usr/local/java/jdk-15.0.{10}              $              echo $PATH              /usr/local/coffee/jdk-15.0.{x}/bin:......            
Step 2: Compile and Run a Hullo-globe Java Programme
  1. File Explorer ⇒ Home ⇒ Create a new folder chosen "myProject" to go on our works.
  2. Open up "Text Editor" (gedit). Enter the following source lawmaking and save every bit "Hello.java" under the "~/myProject" directory created earlier.
    public class Hi {       public static void principal(String[] args) {       Organization.out.println("Hello, world from Ubuntu!");    } }
  3. To compile the Hi-world Java program, launch a Final and issue these commands:
                    $              cd ~/myProject               $              ls              ...... Howdy.java ......               $              javac How-do-you-do.java               $              ls              ...... Hullo.course ......            
  4. Run the Howdy-world Coffee program:
                    $              java Hello              Hello, earth from Ubuntu!            

Notes: Starting from JDK 11, you can compile and run the hello-world in one single step via:

            $          java Hullo.java          Howdy, earth from Ubuntu!        

Source-Code Editors & IDEs for Java Programming

Eclipse IDE

  1. You demand to first install Eclipse. Read "How to Install Eclipse".
  2. javaan then go along to write your get-go Java program. Read "Writing your first Java Program with Eclipse".
  3. Eclipse let you to debug program graphically. Read "Debugging program in Eclipse".

NetBeans IDE

  1. You need to showtime install NetBeans. Read "How to Install NetBeans".
  2. You can then continue to write your first Java programme. Read "Writing your first Coffee programme with NetBeans".
  3. NetBeans allow y'all to debug program graphically. Read "Debugging plan in NetBeans".

Visual Studio (VS) Code IDE

Click Hither, expect for "VS Lawmaking for Java Programming"

Sublime Text (for Windows, macOS, Linux)

Click HERE, look for "Sublime Text for Java Programming"

Atom (for Windows, macOS, Linux)

[TODO]

TextPad (for Windows only)

Click Here, await 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, yous tin "compile and run" a single-file program in one step, without explicit compilation.

  1. Write a "Hello.java" (encounter previous section).
  2. Delete "Hello.grade", if it exists.
  3. Y'all can compile/run "Hello.coffee" in i command as follows:
                                  java Howdy.java              Hello, world!            

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 .grade file), and run.
  • This feature is introduced for beginners to acquire Java, and for professionals to test a Java feature.
  • The filename and classname demand not be the aforementioned.

How To Set JAVA_HOME Environment Variable

Many Java applications (such as Tomcat) require the environment variable JAVA_HOME to exist set to the JDK installed directory.

Come across "How to set JAVA_HOME for Windows" or "How to set JAVA_HOME for macOS/Linux".

Common Errors in installing JDK

JavaErrorPath.png

          SYMPTOM:          Cannot compile Java programme from the CMD vanquish (e.g., "javac Hi.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 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) Start a CMD shell (click "Start" push button ⇒ "run..." ⇒ enter "cmd") and issue a          path          command:          prompt>          path          PATH=.......    2) Check if information technology includes your JDK's "bin" directory. For example, suppose that your JDK is installed        in "c:\program files\coffee\jdk-15.0.ane", then PATH should include "c:\plan files\coffee\jdk-15.0.ane\bin".       Otherwise, include JDK's bin directory in the PATH surround variable.       Read "Footstep 3 of How to install JDK".

JavaErrorClasspathJDK7.png JavaErrorClasspath.png

          SYMPTOM:          Can compile but cannot run Coffee programme from the CMD shell (e.thou., "java Howdy" does non work!)          Fault Message (Post JDK 1.vii):          Mistake: Could not find or load master course Xxx          ERROR MESSAGE (Pre JDK 1.7):          Exception in thread "principal" java.lang.NoClassDefFoundError: Xxx          Likely CAUSES:          ane) The Java course (in this example, Hello.course) is NOT in the current directory.    2) The CLASSPATH environment variable is prepare, but does not include the current directory ".".          POSSIBLE SOLUTIONS:          1) Effect a "dir" command to list the contents of the current directory.        Check that information technology contains the Java course to be run (e.grand., Hello.class).        You need to compile the source program (".java") to get the class file (".course").    ii) If the Coffee form is nowadays in the current directory, issue a "set classpath" control       to check its settings:             prompt>          set classpath          CLASSPATH=.......       If you receive the message "Environment variable CLASSPATH not defined" and          your program is right, I can't help y'all here.       Otherwise, if the CLASSPATH is defined, for beginner, I suggest that you remove         the CLASSPATH environs variable.          From "Control Console"         ⇒ System         ⇒ (Vista only) Advanced system settings          ⇒ Switch to "Avant-garde" tab          ⇒ Environment Variables          ⇒ Organization 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 gear up, information technology is defaulted to the current directory.       Nonetheless, if CLASSPATH is gear up, the current  directory is NOT implicitly included.       You can include the current  directory (denoted past a single dot ".") in front of the        existing class-paths.        Read "Coffee Applications and Environment Variable" for more give-and-take on CLASSPATH.

JavaErrorMain.png

          SYMPTOM:          Can compile simply cannot run the Hello-world plan (e.yard., "coffee Howdy" does not work!)          ERROR MESSAGE (Mail service JDK 1.seven):          Fault: Chief method not constitute in class Hello.          POSSIBLE SOLUTIONS:          Check whether there is a primary() method in your program, and the signature of your main()   as shown in the error bulletin.

(Advanced) External JAR Files and Native Libraries

Notes: This department is applicative to JDK prior to JDK 9. JDK 9 introduces a new level called "module" on meridian of package, and "jmod" files for Java modules. Demand to revise this department for JDK nine.

External Java API packages (such as Servlet API, MySQL Connector/J, JOGL, JUnit) are oft distributed in JAR files (Java Archive - a single-file bundle of many Coffee classes like to ZIP or TAR), with perchance Native Libraries (".lib" and ".dll" in Windows, or ".a" and ".then" in Linux/macOS).

External JAR Files (".jar")

If external JAR files are not properly included:

  • During the compilation, you volition receive compilation error "cannot find symbol" for classes belonging to the external packages.
  • During execution, you will get a runtime error "Could not find or load master class thirty" or "NoClassDefFoundError".

To include external JAR files, yous tin either:

  1. (Prior to JDK 9) Copy all the JAR files of the external packages to the Coffee's Extension Directories (Not applicable from JDK 9).
    • For Windows, the JDK extension directory is located at "<JAVA_HOME>\jre\lib\ext" (due east.g., "c:\Programme Files\Java\jdk1.viii.0_xx\jre\lib\ext").
    • For macOS, the JDK extension directories are "/Library/Coffee/Extensions" and "/Arrangement/Library/Java/Extensions".
    • For Ubuntu, the JDK extension directories are "<JAVA_HOME>/jre/lib/ext" (due east.g., "/usr/user/coffee/jdk1.viii.0_xx/jre/lib/ext") and "/usr/java/packages/lib/ext".
    The location of JDK'south extension directories is kept in Coffee'due south System Holding "java.ext.dirs". Y'all can print its contents via System.out.println(System.getProperty("java.ext.dirs")).
  2. You lot tin can also include all the JAR files in the CLASSPATH surround variable. CLASSPATH may contain directories (of Coffee classes) or JAR files (unmarried-file archive of Java classes). If you set the CLASSPATH, you must likewise include the electric current directory (denoted equally ".").
    • For Windows, ready the CLASSPATH in Control Panel ⇒ Organisation ⇒ Advanced organisation settings ⇒ Advanced ⇒ Surroundings Variables ⇒ Arrangement Variables ⇒ New ⇒ In "Variable 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 ~/.profile or ~/.bash_profile (or /etc/contour for system-broad setting) to include the following line at the end of the file:
      consign CLASSPATH=.:path1/thirty.jar:path2/yyy.jar
      The entries are separated by colon (:).
  3. Y'all can likewise set the CLASSPATH in the javac/java control-line via the option -cp <paths> (or -classpath <paths>), for example,
                     javac              -cp .;path1\xxx.jar;path2\yyy.jar              ClassName.coffee  coffee              -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", ".and then")

Some external packet may provide static or shared native libraries in the class of ".lib" (Windows' static LIBrary), ".dll" (Windows' Dynamically Link Library), ".a" (Unix's static (Archive) library), or ".and then" (Unix's Shared Object library).

Native Libraries are to be kept in a directory accessible via JRE'south Holding "coffee.library.path", which commonly just not necessarily includes all the directories in the PATH surround variable.

Native libraries are not involved in the compilation. But if they are not properly included during runtime fourth dimension, you will become a runtime fault "coffee.lang.UnsatisfiedLinkError: no xxx in java.library.path".

To include external native libraries:

  1. Copy the native libraries into a arrangement library directory, e.one thousand., c:\windows\system32 (Windows), /usr/lib or /usr/local/lib (macOS/Unix). You can verify that the directory is included in Coffee's System Property "java.library.path", via System.out.println(Organisation.getProperty("java.library.path")).
  2. You can also set the native library path via the coffee'southward control-line option -Djava.library.path=30 , for example,
                    java              -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 & Resource

Source: https://www3.ntu.edu.sg/home/ehchua/programming/howto/jdk_howto.html

Posted by: bowmanearthey.blogspot.com

0 Response to "How To Check If Jdk Is Installed"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel