Java Basics & OOP - Full Guide
PART 1: JAVA BASICS
1. Program Structure
Every Java program starts with:
public class Main {
public static void main(String[] args) {
// code
}
}
2. Variables & Data Types
int x = 5;
double price = 10.5;
char letter = 'A';
boolean isTrue = true;
String name = "Yahya";
3. Operators
+ - * / %
4. Input / Output
[Link]("Hello");
Scanner:
import [Link];
Scanner sc = new Scanner([Link]);
5. If / Else
if (x > 0) {
[Link]("Positive");
} else {
[Link]("Negative");
}
6. Switch
switch(day) {
case 1: break;
default: break;
}
7. Loops
for(int i=0;i<5;i++){}
while(i<5){}
do{}while(condition);
8. Arrays
int[] arr = {1,2,3};
9. Strings
String s = "Hello";
10. Random
Random r = new Random();
11. Date
Date d = new Date();
----------------------------
PART 2: OOP
1. Class & Object
class Student { String name; }
2. Constructor
Student(String n){ name=n; }
3. Methods
void sayHello(){}
4. Encapsulation
private + getters/setters
5. Inheritance
class Dog extends Animal
6. Polymorphism
method overriding
7. Abstraction
abstract class
8. Interface
interface Flyable
class Bird implements Flyable
9. this keyword
[Link] = name;
10. static
shared variable
----------------------------
ROADMAP:
Variables -> If -> Loops -> Arrays -> Strings -> OOP