Java Installation and Setup (JDK)
In this lesson: Download and install JDK, set JAVA_HOME and PATH, compile with javac and run with java — easy steps. Set up now. In Hindi & English.
What you need to install
To write and run Java, you install the JDK (Java Development Kit). It contains the compiler javac (to turn your code into bytecode) and the JVM (to run it). Once the JDK is installed and set up, you can compile and run Java programs from the command line.
Download the JDK
- Go to Oracle's Java download page, or get a free build like OpenJDK.
- Choose the version for your operating system (Windows, Mac or Linux).
- Run the installer and follow the steps.
Any recent long-term-support (LTS) version, like Java 17 or 21, is a good choice for learning.
Setting the PATH
On Windows, after installing, add the JDK's bin folder to the system PATH so the command line can find javac and java.
Check the version
Open the command line and run both commands:
java -version javac -version
javac 17.0.1
If both show a version number, the JDK is installed and your PATH is correct. If javac is not found, revisit the PATH step.
Compile and run a program
Save this as Hello.java:
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
Then in the command line, in that folder:
javac Hello.java // compile -> makes Hello.class java Hello // run (no .class)
javac compiles your code to bytecode (Hello.class), and java Hello runs it on the JVM. Note the file name must match the public class name.
Using an IDE
The command line is great for learning, but an IDE makes real work easier:
- IntelliJ IDEA — very popular, has a free Community edition.
- Eclipse — long-standing free IDE for Java.
- VS Code — lightweight, with a Java extension pack.
IDEs add autocomplete, error highlighting and one-click run, so start with one once you are comfortable with the basics.
Common mistakes
- Installing only the JRE. You need the JDK to compile with
javac. - Forgetting the PATH. Then
javac/javaare "not recognised". - File name mismatch. The file must match the public class name (
Hello.javaforclass Hello). - Adding
.classwhen running. Usejava Hello, notjava Hello.class.
Summary
- Install the JDK — it has the compiler and the JVM.
- Set the PATH so
javacandjavawork anywhere. - Check with
java -versionandjavac -version. - Compile with
javac File.java, run withjava File. - Use an IDE like IntelliJ or VS Code for real projects.
Next, write your first program in Hello World in Java, or learn the parts in JDK, JRE and JVM.
Frequently Asked Questions
What do I need to install to run Java?
javac) to build your code and the JVM/JRE to run it. Download it from Oracle or a free build like OpenJDK.Why do I need to set the PATH for Java?
javac and java from any folder in the command line. Without it, the terminal says "javac is not recognised", because it cannot find the Java tools.How do I check if Java is installed?
java -version and javac -version. If both show a version number, the JDK is installed and the PATH is set correctly.How do I compile and run a Java program?
javac Hello.java which creates Hello.class (bytecode), then run with java Hello (no .class extension). The two-step compile-then-run is normal for Java.