⚡ Java Quick Revision Notes
1. Hello World
public class Main {
public static void main(String[] args) {
[Link]("Hello, World!");
}
}
👉 Entry point is always
mainmethod.
2. Variables & Data Types
int x = 10;
double pi = 3.14;
boolean isActive = true;
char grade = 'A';
String name = "Aman";
👉 Primitive vs. Non-Primitive (String, Arrays, Objects).
3. Conditionals
if (x > 10) {
[Link]("Big");
} else if (x == 10) {
[Link]("Equal");
} else {
[Link]("Small");
}
4. Loops
for (int i = 0; i < 5; i++) [Link](i);
while (x > 0) { x--; }
for (String s : new String[]{"a","b"}) {
[Link](s);
}
5. Methods
public static int add(int a, int b) {
return a + b;
}
👉 Methods belong to a class.
6. Classes & Objects
class Person {
String name;
int age;
void greet() {
[Link]("Hello, " + name);
}
}
erson p = new Person();
P
[Link] = "Aman";
[Link]();
7. Constructors
class Person {
String name;
Person(String name) {
[Link] = name;
}
}
Person p = new Person("Aman");
👉 Special method to initialize objects.
8. Inheritance
class Animal {
void sound() { [Link]("Some sound"); }
}
class Dog extends Animal {
void sound() { [Link]("Bark"); }
}
👉
extends= inheritance,
super= parent call.
9. Polymorphism
nimal a = new Dog();
A
[Link](); // "Bark"
👉 Parent reference can point to child object.
10. Abstract Classes & Interfaces
abstract class Shape {
abstract void draw();
}
interface Drawable {
void draw();
}
class Circle implements Drawable {
public void draw() { [Link]("Circle"); }
}
👉
abstract= partially defined,
interface= contract.
11. Encapsulation
class Bank {
private int balance = 1000;
public int getBalance() { return balance; }
public void deposit(int amount) { balance += amount; }
}
👉 Use
private+ getters/setters.
12. Exception Handling
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
[Link]("Error: " + [Link]());
} finally {
[Link]("Always runs");
}
👉 Use
throwfor custom exceptions.
13. Collections
import [Link].*;
ist<String> list = new ArrayList<>();
L
[Link]("Aman");
ap<String, Integer> map = new HashMap<>();
M
[Link]("age", 21);
[Link]([Link]("age"));
👉
List Set
, Mapare common interfaces.
,
14. Generics
class Box<T> {
private T value;
public void set(T value) { [Link] = value; }
public T get() { return value; }
}
ox<String> b = new Box<>();
B
[Link]("Hello");
15. Streams (Java 8+)
ist<Integer> nums = [Link](1,2,3,4);
L
[Link]()
.filter(n -> n % 2 == 0)
.map(n -> n * n)
.forEach([Link]::println);
👉 Functional-style operations on collections.
16. Lambda Expressions
unnable r = () -> [Link]("Running...");
R
new Thread(r).start();
17. File I/O
import [Link].*;
tring data = [Link]([Link]("[Link]"));
S
[Link]([Link]("[Link]"), "Hello Java");
18. Multithreading
class MyThread extends Thread {
public void run() { [Link]("Thread running"); }
}
new MyThread().start();
👉 Or use
Runnable
.
19. Packages
ackage myapp;
p
import [Link];
👉 Organize code into namespaces.
20. Important Best Practices
● FollowOOP principles: Encapsulation, Inheritance,Polymorphism, Abstraction.
interfaceswhen multiple implementations possible.
● Use
List
● Prefer /
Mapover arrays for flexibility.
● Handle exceptions properly (
try-catch-finally
).
● Use streams & lambdas for concise code.