Clean • Professional
Java is a high-level, object-oriented, platform-independent programming language designed to build secure and portable applications.
Java was developed by James Gosling at Sun Microsystems in 1995.
Because Java programs are converted into bytecode, which runs on any OS where a JVM is installed.
Example:
Compile on Windows → Run on Linux
class Test {
public static void main(String[] args) {
System.out.println("Platform Independent");
}
}
JDK (Java Development Kit) is used to develop Java applications.
It includes:
Example:
To compile a program:
javac Hello.java
JRE (Java Runtime Environment) provides libraries and JVM required to run Java programs.
Example:
To run compiled bytecode:
java Hello
JVM executes the bytecode and provides platform independence.
Yes, JVM is platform dependent. Java bytecode is platform independent.
Example:
Write the code once → compile → run anywhere that has a JVM.
Bytecode is the intermediate code (.class file) generated after compilation.
It is executed by the JVM.
Example:
Test.java → javac → Test.class (bytecode)
Bytecode makes Java portable, fast, and secure.
.java filejavac → .class bytecodeExample Summary:
Hello.java → javac → Hello.class → JVM → Output
It loads class files into JVM at runtime.
It checks bytecode for:
JIT (Just-In-Time) compiler improves performance by converting bytecode into machine code at runtime.
Because it provides:
Example:
When typing:
System.
IDE shows suggestions: out, err, in etc.
Commands:
java -version
javac -version
class Hello {
public static void main(String[] args) {
System.out.println("Hello Java");
}
}
Explanation:
class → blueprintmain() → entry pointSystem.out.println → prints outputOutput:
Hello Java
So JVM can call it without creating an object.
If a class is public, the filename must match the class name, or compilation fails.
Hello Java
.javajavac Hello.java
3. Run →
java Hello
Compiler checks:
Example of compile-time error:
System.out.println("Hello" // missing parenthesis
JVM executes bytecode using:
Example of runtime error:
int x = 10 / 0; // ArithmeticException
Example - Maven dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Includes:
Built-in library packages like:
java.langjava.utiljava.iojava.timeExample using java.util:
import java.util.ArrayList;
ArrayList<String> list = new ArrayList<>();
list.add("Java");
Languages that run on JVM:
Build automation tools used for:
Example - Gradle build snippet:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
}