Java
Write Once, Run Anywhere – Enterprise-Grade OOP
What is Java?
Java is a high-level, class-based, object-oriented programming language designed to have as few
implementation dependencies as possible. It runs on the Java Virtual Machine (JVM), making it
platform-independent. Java is widely used in enterprise applications, Android development, and
backend systems.
Hello World
public class HelloWorld {
public static void main(String[] args) {
[Link]("Hello, World!");
}
}
Data Types & Variables
int age = 25;
double price = 9.99;
boolean isActive = true;
char grade = 'A';
String name = "Alice";
Object-Oriented Programming (OOP)
Java is built around four OOP pillars:
• Encapsulation – Bundling data and methods in a class
• Inheritance – A class can extend another class
• Polymorphism – Same method, different behavior
• Abstraction – Hiding complexity behind interfaces
public class Animal {
String name;
void speak() { [Link]("..."); }
}
public class Dog extends Animal {
void speak() { [Link]("Woof!"); }
}
Control Flow
// If-else
if (age >= 18) {
[Link]("Adult");
} else {
[Link]("Minor");
}
// For loop
for (int i = 0; i < 5; i++) {
[Link](i);
}
// While loop
while (count > 0) { count--; }
Collections
import [Link].*;
List<String> list = new ArrayList<>();
[Link]("Java");
[Link](0);
Map<String, Integer> map = new HashMap<>();
[Link]("score", 100);
[Link]("score");
Exception Handling
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
[Link]("Error: " + [Link]());
} finally {
[Link]("Always runs");
}
Key Tips
• Java is statically typed – declare variable types explicitly
• Every Java program needs a main() method as entry point
• Use Maven or Gradle for dependency management
• Java 8+ features: Streams, Lambdas, Optional are essential
• The JDK includes the compiler (javac) and runtime (java)