A Comprehensive Guide to Java Fundamentals
Course: 4343203 - Java Programming
Java is a high-level, class-based, object-oriented programming language designed to have as few implementation dependencies as possible.
Write Once, Run Anywhere (WORA)
Java strictly follows OOP principles:
Built-in support for concurrent programming
JIT compilation and optimization techniques
Comprehensive standard library
Runtime memory allocation and class loading
Full-featured software development kit for Java applications
Minimum requirements to run Java applications
Abstract computing machine that enables platform independence
Recommended: Use latest LTS (Long Term Support) version
Default locations:
# Windows
set JAVA_HOME=C:\Program Files\Java\jdk-11
# Linux/macOS
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk
# Windows
set PATH=%JAVA_HOME%\bin;%PATH%
# Linux/macOS
export PATH=$JAVA_HOME/bin:$PATH
# Check Java version
java -version
# Check compiler version
javac -version
Expected output:
java version "11.0.12" 2021-07-20 LTS
Java(TM) SE Runtime Environment (build 11.0.12+8-LTS-237)
Java HotSpot(TM) 64-Bit Server VM (build 11.0.12+8-LTS-237)
public class MyFirstProgram {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Key Points:
public class MyFirstProgram {
// Class body
}
public static void main(String[] args) {
// Program logic goes here
}
System.out.println("Hello, World!");
System.out.println(42);
System.out.println(3.14);
System.out.print("Hello ");
System.out.print("World!");
// Output: Hello World!
Difference: println() adds a new line, print() doesn't
// This is a single-line comment
System.out.println("Hello World"); // Comment at end of line
/* This is a multi-line comment
that spans multiple lines
and explains complex code */
System.out.println("Hello World");
Create a file with .java extension
// HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Important: Filename must match the public class name
javac HelloWorld.java
java HelloWorld
Note: JRE must be installed to run Java programs
Source Code (.java)
↓
javac compiler
↓
Bytecode (.class)
↓
JVM
↓
Machine Code
↓
Output
Bytecode is platform-independent intermediate code generated by Java compiler
Garbage Collection is automatic memory management in Java
Next: Data Types and Variables
Ready to dive deeper into Java programming!