What is Java?
Java is a class-based, object-oriented programming language designed to have as few implementation dependencies as possible. Created by James Gosling at Sun Microsystems in 1995, Java follows the "write once, run anywhere" principle.
Key Features:
- Platform Independent: Compiles to bytecode that runs on the JVM
- Object-Oriented: Everything is an object (except primitives)
- Strongly Typed: Types are checked at compile time
- Automatic Memory Management: Garbage collection handles memory
- Multi-threaded: Built-in support for concurrent programming
Where Java is Used:
- Enterprise applications
- Android development
- Web backends (Spring, Jakarta EE)
- Big data (Hadoop, Spark)
- Scientific applications
Java Versions: Java follows a 6-month release cycle. LTS versions (8, 11, 17, 21) are recommended for production.
Code Examples
Hello Worldjava
// Every Java program needs a class
public class HelloWorld {
// Entry point of the program
public static void main(String[] args) {
// Print to console
System.out.println("Hello, World!");
// Variables must declare types
String name = "Java";
int version = 21;
System.out.println("Welcome to " + name + " " + version + "!");
// Using printf for formatted output
System.out.printf("Version: %d%n", version);
}
}Every Java application must have a main method as the entry point. The class name must match the filename (HelloWorld.java).
Quick Quiz
1. What does 'write once, run anywhere' mean for Java?
2. What must the Java class name match?
Was this lesson helpful?