Downloading and Installing JDK

This page shows how to download and install the latest version of the Java Development Kit (JDK). Read the instructions carefully to set the "classpath" mentioned in Step 3. Once JDK has been installed, you can write a simple Java program using an editor such as notepad and run it from a command prompt. Alternatively, Java programs can be written using an Integrated Development Environment (IDE) such as NetBeans, described below.

4. Common Errors in installing JDK

CMD Shell

SYMPTOM: Cannot compile Java program from the CMD shell (e.g., "javac" 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 paths for executable
   programs (including "javac.exe"), does not include JDK's bin directory.
   1) Start a CMD shell (click "Start" button ⇒ "run..." ⇒ enter "cmd") and issue a path command:
         prompt> 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-11.0.1", then PATH should include "c:\program files\java\jdk-11.0.1\bin".

      Otherwise, include JDK's bin directory in the PATH environment variable.
      Read "Step 3 of How to install JDK".

Load Main Class

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
   1) The Java class (in this example, Hello.class) is NOT in the current directory.
   2) The CLASSPATH environment variable is set, but does not include the current directory ".".
   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.class). 
      You need to compile the source program (".java") to get the class file (".class").
   2) If the Java class is present in the current directory, issue a "set classpath" command
      to check its settings:
            prompt> set 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-paths. 
      Read "Java Applications and Environment Variable" for more discussion on CLASSPATH.

Not found in class
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 the error message.