← Back to Core Java Course | Chapter 1: Introduction & Basics | Lesson 3 of 12

Java Environment Setup

Setting up Java is like getting your workshop ready: you install the toolkit, write your instructions, turn them into something the computer can follow, and then run them.

What is the JDK?

The JDK bundles everything you need to build Java software: the javac compiler, the java launcher, debugging tools, and the JRE (which itself contains the JVM and core class libraries) needed just to run compiled programs.

Example: What is the JDK?

java
public class Main {
	// The JDK provides: javac (compiler), java (launcher), debugging tools, and the JRE/JVM
	public static void main(String[] args) {
		System.out.println("Built and run using tools bundled in the JDK.");
	}
}

Writing Your Code

Any plain text editor works, but IDEs like IntelliJ IDEA, Eclipse, or VS Code with the Java extension pack add real value here -- autocomplete, inline error highlighting, and one-click running that make catching typos far faster.

Example: Writing Your Code

java
public class Main {
	// Written in an IDE like IntelliJ IDEA, Eclipse, or VS Code (Java extension pack)
	public static void main(String[] args) {
		System.out.println("Code written with autocomplete and inline error highlighting.");
	}
}

Saving Your File

Java is strict about this: if your file declares public class Calculator, it must be saved as Calculator.java exactly, matching case, or the compiler will refuse to build it.

Example: Saving Your File

java
public class Calculator {
	// This file MUST be saved as Calculator.java, matching the class name exactly (case-sensitive)
	public static void main(String[] args) {
		System.out.println("Saved as Calculator.java to match 'public class Calculator'.");
	}
}

Compiling Your Code

Running javac filename.java from your terminal reads your source, checks it for syntax and type errors, and if it's clean, emits a matching filename.class file containing JVM bytecode in the same folder.

Example: Compiling Your Code

java
public class Main {
	// Terminal: javac Main.java
	// Checks syntax/types, then emits Main.class (JVM bytecode) in the same folder
	public static void main(String[] args) {
		System.out.println("Compiled with: javac Main.java");
	}
}

Running the Bytecode

The java ClassName command (note: no .java or .class extension here) loads that bytecode file and hands it to the JVM, which begins executing from your program's main method.

Example: Running the Bytecode

java
public class Main {
	// Terminal: java Main   (no .java or .class extension)
	public static void main(String[] args) {
		System.out.println("Executed by the JVM starting from main().");
	}
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Setting up only the JRE, so javac is not found because the compiler is in the JDK.
  2. Not adding the JDK bin folder to the PATH (or JAVA_HOME), so java and javac are not recognised.
  3. Running java Hello.class with the extension, when the command is java Hello.

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.