Core Java Syntax and Theory: Basics to Advanced
🟢 1. Java Basics
Hello World Program:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Basic Syntax: - Java is case-sensitive - Class name = file name - Main method is the entry point
Data Types:
int age = 25;
double price = 99.99;
char grade = 'A';
boolean isPass = true;
String name = "Ayan";
Operators: - Arithmetic: + - * / % - Relational: == != > < >= <= - Logical: && || ! - Assignment:
= += -= *= /=
🟡 2. Control Structures
if-else:
if (age > 18) {
System.out.println("Adult");
} else {
System.out.println("Minor");
}
switch:
1
switch (day) {
case 1: System.out.println("Monday"); break;
default: System.out.println("Invalid day");
}
Loops:
for (int i = 0; i < 5; i++) {
System.out.println(i);
}
int i = 0;
while (i < 5) {
System.out.println(i);
i++;
}
do {
System.out.println(i);
i++;
} while (i < 5);
🟠 3. Object-Oriented Programming
Class and Object:
class Car {
String color;
void drive() {
System.out.println("Driving");
}
}
public class Main {
public static void main(String[] args) {
Car myCar = new Car();
myCar.drive();
}
}
Constructors:
2
Car(String color) {
this.color = color;
}
Inheritance:
class Animal {
void sound() {
System.out.println("Animal sound");
}
}
class Dog extends Animal {
void bark() {
System.out.println("Bark");
}
}
Polymorphism: - Overloading
void show(int a) {}
void show(String b) {}
- Overriding
@Override
void sound() {
System.out.println("Dog barks");
}
Encapsulation:
class Person {
private int age;
public void setAge(int a) { age = a; }
public int getAge() { return age; }
}
Abstraction:
3
abstract class Shape {
abstract void draw();
}
🔵 4. Advanced Concepts
Interfaces:
interface Animal {
void eat();
}
class Dog implements Animal {
public void eat() {
System.out.println("Dog eats");
}
}
Exception Handling:
try {
int a = 5 / 0;
} catch (ArithmeticException e) {
System.out.println("Can't divide by 0");
} finally {
System.out.println("Always executes");
}
File I/O:
import java.io.FileWriter;
FileWriter writer = new FileWriter("output.txt");
writer.write("Hello File");
writer.close();
🔸 5. Collections Framework
• List: ArrayList , LinkedList
4
• Set: HashSet
• Map: HashMap
import java.util.*;
ArrayList<String> list = new ArrayList<>();
list.add("Ayan");
HashMap<String, Integer> map = new HashMap<>();
map.put("Age", 21);
🔺 6. Threads & Concurrency
class MyThread extends Thread {
public void run() {
System.out.println("Thread running");
}
}
MyThread t = new MyThread();
t.start();
📂 7. Useful Java Keywords
• this , super , final , static , abstract , interface , implements , extends , try-
catch-finally , throw , throws , synchronized , instanceof
Let me know if you'd like: - Practice questions and mini-projects - PDF version of this guide - Weekly
roadmap for Java learning - Live code testing exercises