Java Environment Setup
In this page:
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?
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.");
}
}
Login to try C/C++/Java/PHP code in the editor
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
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.");
}
}
Login to try C/C++/Java/PHP code in the editor
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
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'.");
}
}
Login to try C/C++/Java/PHP code in the editor
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
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");
}
}
Login to try C/C++/Java/PHP code in the editor
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
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().");
}
}
Login to try C/C++/Java/PHP code in the editor
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: