Data Analytics
27.2K subscribers
1.17K photos
24 videos
31 files
988 links
Dive into the world of Data Analytics – uncover insights, explore trends, and master data-driven decision making.

admin: @HusseinSheikho
Download Telegram
πŸ“š Functional, Object-Oriented, and Concurrent Programming (2023)

πŸ”— Download Link: https://shts.me/qaKO

πŸ’¬ Tags: #OOP

βœ… By: @DataScience_Books - @DataScience4 - @EBooks2023
❀1
πŸ“š Object-Oriented Analysis and Design for Information Systems (2024)

1⃣ Join Channel Download:
https://t.iss.one/+MhmkscCzIYQ2MmM8

2⃣ Download Book: https://t.iss.one/c/1854405158/1419

πŸ’¬ Tags: #OOP

πŸ‘‰ BEST DATA SCIENCE CHANNELS ON TELEGRAM πŸ‘ˆ
πŸ‘3
# πŸ“š Java Programming Language – Part 1/10: Introduction to Java
#Java #Programming #OOP #Beginner #Coding

Welcome to this comprehensive 10-part Java series! Let’s start with the basics.

---

## πŸ”Ή What is Java?
Java is a high-level, object-oriented, platform-independent programming language. It’s widely used in:
- Web applications (Spring, Jakarta EE)
- Mobile apps (Android)
- Enterprise software
- Big Data (Hadoop)
- Embedded systems

Key Features:
βœ”οΈ Write Once, Run Anywhere (WORA) – Thanks to JVM
βœ”οΈ Strongly Typed – Variables must be declared with a type
βœ”οΈ Automatic Memory Management (Garbage Collection)
βœ”οΈ Multi-threading Support

---

## πŸ”Ή Java vs. Other Languages
| Feature | Java | Python | C++ |
|---------------|--------------|--------------|--------------|
| Typing | Static | Dynamic | Static |
| Speed | Fast (JIT) | Slower | Very Fast |
| Memory | Managed (GC) | Managed | Manual |
| Use Case | Enterprise | Scripting | System/Game |

---

## πŸ”Ή How Java Works?
1. Write code in .java files
2. Compile into bytecode (.class files) using javac
3. JVM (Java Virtual Machine) executes the bytecode

HelloWorld.java β†’ (Compile) β†’ HelloWorld.class β†’ (Run on JVM) β†’ Output


---

## πŸ”Ή Setting Up Java
1️⃣ Install JDK (Java Development Kit)
- Download from [Oracle] :https://www.oracle.com/java/technologies/javase-downloads.html
- Or use OpenJDK (Free alternative)

2️⃣ Verify Installation
java -version
javac -version


3️⃣ Set `JAVA_HOME` (For IDE compatibility)

---

## πŸ”Ή Your First Java Program
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}


### πŸ“Œ Explanation:
- public class HelloWorld β†’ Class name must match the filename (HelloWorld.java)
- public static void main(String[] args) β†’ Entry point of any Java program
- System.out.println() β†’ Prints output

### ▢️ How to Run?
javac HelloWorld.java  # Compiles to HelloWorld.class
java HelloWorld # Runs the program

Output:
Hello, World!


---

## πŸ”Ή Java Syntax Basics
βœ… Case-Sensitive β†’ myVar β‰  MyVar
βœ… Class Names β†’ PascalCase (MyClass)
βœ… Method/Variable Names β†’ camelCase (myMethod)
βœ… Every statement ends with `;`

---

## πŸ”Ή Variables & Data Types
Java supports primitive and non-primitive types.

### Primitive Types (Stored in Stack Memory)
| Type | Size | Example |
|-----------|---------|----------------|
| int | 4 bytes | int x = 10; |
| double | 8 bytes | double y = 3.14; |
| boolean | 1 bit | boolean flag = true; |
| char | 2 bytes | char c = 'A'; |

### Non-Primitive (Reference Types, Stored in Heap)
- String β†’ String name = "Ali";
- Arrays β†’ int[] nums = {1, 2, 3};
- Classes & Objects

---

### πŸ“Œ What’s Next?
In Part 2, we’ll cover:
➑️ Operators & Control Flow (if-else, loops)
➑️ Methods & Functions

Stay tuned! πŸš€

#LearnJava #JavaBasics #CodingForBeginners
❀4
# πŸ“š Java Programming Language – Part 2/10: Operators & Control Flow
#Java #Programming #OOP #ControlFlow #Coding

Welcome to Part 2 of our Java series! Today we'll explore operators and control flow structures.

---

## πŸ”Ή Java Operators Overview
Java provides various operators for:
- Arithmetic calculations
- Logical decisions
- Variable assignments
- Comparisons

### 1. Arithmetic Operators
int a = 10, b = 3;
System.out.println(a + b); // 13 (Addition)
System.out.println(a - b); // 7 (Subtraction)
System.out.println(a * b); // 30 (Multiplication)
System.out.println(a / b); // 3 (Division - integer)
System.out.println(a % b); // 1 (Modulus)
System.out.println(a++); // 10 (Post-increment)
System.out.println(++a); // 12 (Pre-increment)


### 2. Relational Operators
System.out.println(a == b); // false (Equal to)
System.out.println(a != b); // true (Not equal)
System.out.println(a > b); // true (Greater than)
System.out.println(a < b); // false (Less than)
System.out.println(a >= b); // true (Greater or equal)
System.out.println(a <= b); // false (Less or equal)


### 3. Logical Operators
boolean x = true, y = false;
System.out.println(x && y); // false (AND)
System.out.println(x || y); // true (OR)
System.out.println(!x); // false (NOT)


### 4. Assignment Operators
int c = 5;
c += 3; // Equivalent to c = c + 3
c -= 2; // Equivalent to c = c - 2
c *= 4; // Equivalent to c = c * 4
c /= 2; // Equivalent to c = c / 2


---

## πŸ”Ή Control Flow Statements
Control the execution flow of your program.

### 1. if-else Statements
int age = 18;
if (age >= 18) {
System.out.println("Adult");
} else {
System.out.println("Minor");
}


### 2. Ternary Operator
String result = (age >= 18) ? "Adult" : "Minor";
System.out.println(result);


### 3. switch-case Statement
int day = 3;
switch(day) {
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
// ... other cases
default:
System.out.println("Invalid day");
}


### 4. Loops
#### while Loop
int i = 1;
while (i <= 5) {
System.out.println(i);
i++;
}


#### do-while Loop
int j = 1;
do {
System.out.println(j);
j++;
} while (j <= 5);


#### for Loop
for (int k = 1; k <= 5; k++) {
System.out.println(k);
}


#### Enhanced for Loop (for-each)
int[] numbers = {1, 2, 3, 4, 5};
for (int num : numbers) {
System.out.println(num);
}


---

## πŸ”Ή Break and Continue
Control loop execution flow.

// Break example
for (int i = 1; i <= 10; i++) {
if (i == 5) {
break; // Exit loop
}
System.out.println(i);
}

// Continue example
for (int i = 1; i <= 10; i++) {
if (i % 2 == 0) {
continue; // Skip even numbers
}
System.out.println(i);
}


---

## πŸ”Ή Practical Example: Number Guessing Game
import java.util.Scanner;
import java.util.Random;

public class GuessingGame {
public static void main(String[] args) {
Random rand = new Random();
int secretNumber = rand.nextInt(100) + 1;
Scanner scanner = new Scanner(System.in);
int guess;

do {
System.out.print("Guess the number (1-100): ");
guess = scanner.nextInt();

if (guess < secretNumber) {
System.out.println("Too low!");
} else if (guess > secretNumber) {
System.out.println("Too high!");
}
} while (guess != secretNumber);

System.out.println("Congratulations! You guessed it!");
scanner.close();
}
}


---

### πŸ“Œ What's Next?
In Part 3, we'll cover:
➑️ Methods and Functions
➑️ Method Overloading
➑️ Recursion

#JavaProgramming #ControlFlow #LearnToCode πŸš€
Please open Telegram to view this post
VIEW IN TELEGRAM
❀3
Data Analytics
# πŸ“š Java Programming Language – Part 2/10: Operators & Control Flow #Java #Programming #OOP #ControlFlow #Coding Welcome to Part 2 of our Java series! Today we'll explore operators and control flow structures. --- ## πŸ”Ή Java Operators Overview Java provides…
# πŸ“š Java Programming Language – Part 3/10: Methods & Functions
#Java #Programming #Methods #Functions #OOP

Welcome to Part 3 of our Java series! Today we'll dive into methods - the building blocks of Java programs.

---

## πŸ”Ή What are Methods in Java?
Methods are blocks of code that:
βœ”οΈ Perform specific tasks
βœ”οΈ Can be reused multiple times
βœ”οΈ Help organize code logically
βœ”οΈ Can return a value or perform actions without returning

// Method structure
[access-modifier] [static] return-type methodName(parameters) {
// method body
return value; // if not void
}


---

## πŸ”Ή Method Components
### 1. Simple Method Example
public class Calculator {

// Method without return (void)
public static void greet() {
System.out.println("Welcome to Calculator!");
}

// Method with return
public static int add(int a, int b) {
return a + b;
}

public static void main(String[] args) {
greet(); // Calling void method
int sum = add(5, 3); // Calling return method
System.out.println("Sum: " + sum);
}
}


### 2. Method Parameters
public static void printUserInfo(String name, int age) {
System.out.println("Name: " + name);
System.out.println("Age: " + age);
}


### 3. Return Values
public static boolean isAdult(int age) {
return age >= 18;
}


---

## πŸ”Ή Method Overloading
Multiple methods with same name but different parameters.

public class MathOperations {

// Version 1: Add two integers
public static int add(int a, int b) {
return a + b;
}

// Version 2: Add three integers
public static int add(int a, int b, int c) {
return a + b + c;
}

// Version 3: Add two doubles
public static double add(double a, double b) {
return a + b;
}

public static void main(String[] args) {
System.out.println(add(2, 3)); // 5
System.out.println(add(2, 3, 4)); // 9
System.out.println(add(2.5, 3.7)); // 6.2
}
}


---

## πŸ”Ή Recursion
A method that calls itself.

### 1. Factorial Example
public static int factorial(int n) {
if (n == 0 || n == 1) {
return 1;
}
return n * factorial(n - 1);
}


### 2. Fibonacci Sequence
public static int fibonacci(int n) {
if (n <= 1) {
return n;
}
return fibonacci(n-1) + fibonacci(n-2);
}


---

## πŸ”Ή Variable Scope
Variables have different scope depending on where they're declared.

public class ScopeExample {
static int classVar = 10; // Class-level variable

public static void methodExample() {
int methodVar = 20; // Method-level variable
System.out.println(classVar); // Accessible
System.out.println(methodVar); // Accessible
}

public static void main(String[] args) {
int mainVar = 30; // Block-level variable
System.out.println(classVar); // Accessible
// System.out.println(methodVar); // ERROR - not accessible
System.out.println(mainVar); // Accessible
}
}


---

## πŸ”Ή Practical Example: Temperature Converter
public class TemperatureConverter {

public static double celsiusToFahrenheit(double celsius) {
return (celsius * 9/5) + 32;
}

public static double fahrenheitToCelsius(double fahrenheit) {
return (fahrenheit - 32) * 5/9;
}

public static void main(String[] args) {
System.out.println("20Β°C to Fahrenheit: " + celsiusToFahrenheit(20));
System.out.println("68Β°F to Celsius: " + fahrenheitToCelsius(68));
}
}


---

## πŸ”Ή Best Practices for Methods
1. Single Responsibility Principle - Each method should do one thing
2. Descriptive Names - Use verbs (calculateTotal, validateInput)
3. Limit Parameters - Ideally 3-4 parameters max
4. Proper Indentation - Keep code readable
5. Documentation - Use JavaDoc comments
❀1
Data Analytics
# πŸ“š Java Programming Language – Part 2/10: Operators & Control Flow #Java #Programming #OOP #ControlFlow #Coding Welcome to Part 2 of our Java series! Today we'll explore operators and control flow structures. --- ## πŸ”Ή Java Operators Overview Java provides…
/**
* Calculates the area of a rectangle
* @param length the length of rectangle
* @param width the width of rectangle
* @return area of the rectangle
*/
public static double calculateRectangleArea(double length, double width) {
return length * width;
}


---

### **πŸ“Œ What's Next?
In **Part 4
, we'll cover:
➑️ Object-Oriented Programming (OOP) Concepts
➑️ Classes and Objects
➑️ Constructors

#JavaMethods #OOP #LearnProgramming πŸš€
Please open Telegram to view this post
VIEW IN TELEGRAM
Data Analytics
# πŸ“š Java Programming Language – Part 3/10: Methods & Functions #Java #Programming #Methods #Functions #OOP Welcome to Part 3 of our Java series! Today we'll dive into methods - the building blocks of Java programs. --- ## πŸ”Ή What are Methods in Java? Methods…
# πŸ“š Java Programming Language – Part 4/10: Object-Oriented Programming (OOP) Basics
#Java #OOP #Programming #Classes #Objects

Welcome to Part 4 of our Java series! Today we'll explore the fundamentals of Object-Oriented Programming in Java.

---

## πŸ”Ή What is OOP?
Object-Oriented Programming is a paradigm based on:
- Objects (instances of classes)
- Classes (blueprints for objects)
- 4 Main Principles:
- Encapsulation
- Inheritance
- Polymorphism
- Abstraction

---

## πŸ”Ή Classes and Objects

### 1. Class Definition
public class Car {
// Fields (attributes)
String brand;
String model;
int year;

// Method
public void startEngine() {
System.out.println("Engine started!");
}
}


### 2. Creating Objects
public class Main {
public static void main(String[] args) {
// Creating an object
Car myCar = new Car();

// Accessing fields
myCar.brand = "Toyota";
myCar.model = "Corolla";
myCar.year = 2022;

// Calling method
myCar.startEngine();
}
}


---

## πŸ”Ή Constructors
Special methods called when an object is instantiated.

### 1. Default Constructor
public class Car {
// Default constructor (created automatically if none exists)
public Car() {
}
}


### 2. Parameterized Constructor
public class Car {
String brand;
String model;
int year;

public Car(String brand, String model, int year) {
this.brand = brand;
this.model = model;
this.year = year;
}
}

// Usage:
Car myCar = new Car("Toyota", "Corolla", 2022);


### 3. Constructor Overloading
public class Car {
// Constructor 1
public Car() {
this.brand = "Unknown";
}

// Constructor 2
public Car(String brand) {
this.brand = brand;
}
}


---

## πŸ”Ή Encapsulation
Protecting data by making fields private and providing public getters/setters.

public class BankAccount {
private double balance; // Private field

// Public getter
public double getBalance() {
return balance;
}

// Public setter with validation
public void deposit(double amount) {
if (amount > 0) {
balance += amount;
}
}
}


---

## πŸ”Ή 'this' Keyword
Refers to the current object instance.

public class Person {
private String name;

public Person(String name) {
this.name = name; // 'this' distinguishes field from parameter
}
}


---

## πŸ”Ή Practical Example: Student Management System
public class Student {
private String id;
private String name;
private double gpa;

public Student(String id, String name) {
this.id = id;
this.name = name;
}

// Getters and setters
public String getId() { return id; }
public String getName() { return name; }
public double getGpa() { return gpa; }

public void updateGpa(double newGpa) {
if (newGpa >= 0 && newGpa <= 4.0) {
this.gpa = newGpa;
}
}

public void printInfo() {
System.out.printf("ID: %s, Name: %s, GPA: %.2f\n",
id, name, gpa);
}
}

// Usage:
Student student1 = new Student("S1001", "Ahmed");
student1.updateGpa(3.75);
student1.printInfo();


---

## πŸ”Ή Static vs Instance Members

| Feature | Static | Instance |
|---------------|---------------------------|---------------------------|
| Belongs to | Class | Object |
| Memory | Once per class | Each object has its own |
| Access | ClassName.member | object.iss.onember |
| Example | Math.PI | student.getName() |

public class Counter {
static int count = 0; // Shared across all instances
int instanceCount = 0; // Unique to each object

public Counter() {
count++;
instanceCount++;
}

public static void printCount() {
System.out.println("Total count: " + count);
}
}


---
Data Analytics
# πŸ“š Java Programming Language – Part 4/10: Object-Oriented Programming (OOP) Basics #Java #OOP #Programming #Classes #Objects Welcome to Part 4 of our Java series! Today we'll explore the fundamentals of Object-Oriented Programming in Java. --- ## πŸ”Ή What…
# πŸ“š Java Programming Language – Part 5/10: Inheritance & Polymorphism
#Java #OOP #Inheritance #Polymorphism #Programming

Welcome to Part 5 of our Java series! Today we'll explore two fundamental OOP concepts: Inheritance and Polymorphism.

---

## πŸ”Ή Inheritance in Java
Inheritance allows a class to acquire properties and methods of another class.

### 1. Basic Inheritance Syntax
// Parent class (Superclass)
class Vehicle {
String brand;

public void start() {
System.out.println("Vehicle starting...");
}
}

// Child class (Subclass)
class Car extends Vehicle { // 'extends' keyword
int numberOfDoors;

public void honk() {
System.out.println("Beep beep!");
}
}

// Usage:
Car myCar = new Car();
myCar.brand = "Toyota"; // Inherited from Vehicle
myCar.start(); // Inherited method
myCar.honk(); // Child's own method


### 2. Inheritance Types
Java supports:
- Single Inheritance (One parent β†’ one child)
- Multilevel Inheritance (Grandparent β†’ parent β†’ child)
- Hierarchical Inheritance (One parent β†’ multiple children)

*Note: Java doesn't support multiple inheritance with classes*

---

## πŸ”Ή Method Overriding
Subclass can provide its own implementation of an inherited method.

class Vehicle {
public void start() {
System.out.println("Vehicle starting...");
}
}

class ElectricCar extends Vehicle {
@Override // Annotation (optional but recommended)
public void start() {
System.out.println("Electric car starting silently...");
}
}


---

## πŸ”Ή super Keyword
Used to access superclass members from subclass.

### 1. Accessing Superclass Methods
class ElectricCar extends Vehicle {
@Override
public void start() {
super.start(); // Calls Vehicle's start()
System.out.println("Battery check complete");
}
}


### 2. Superclass Constructor
class Vehicle {
String brand;

public Vehicle(String brand) {
this.brand = brand;
}
}

class Car extends Vehicle {
int doors;

public Car(String brand, int doors) {
super(brand); // Must be first statement
this.doors = doors;
}
}


---

## πŸ”Ή Polymorphism
"Many forms" - ability of an object to take many forms.

### 1. Compile-time Polymorphism (Method Overloading)
class Calculator {
// Same method name, different parameters
int add(int a, int b) { return a + b; }
double add(double a, double b) { return a + b; }
}


### 2. Runtime Polymorphism (Method Overriding)
Vehicle v1 = new Vehicle();  // Parent reference, parent object
Vehicle v2 = new Car(); // Parent reference, child object

v1.start(); // Calls Vehicle's start()
v2.start(); // Calls Car's start() if overridden


---

## πŸ”Ή final Keyword
Restricts inheritance and overriding.

final class CannotBeExtended { }  // Cannot be inherited

class Parent {
final void cannotOverride() { } // Cannot be overridden
}


---

## πŸ”Ή Object Class
All classes implicitly extend Java's Object class.

Important methods:
- toString() - String representation
- equals() - Compare objects
- hashCode() - Hash code value

class MyClass { }  // Automatically extends Object

MyClass obj = new MyClass();
System.out.println(obj.toString()); // Outputs something like MyClass@1dbd16a6


---
Data Analytics
# πŸ“š Java Programming Language – Part 5/10: Inheritance & Polymorphism #Java #OOP #Inheritance #Polymorphism #Programming Welcome to Part 5 of our Java series! Today we'll explore two fundamental OOP concepts: Inheritance and Polymorphism. --- ## πŸ”Ή Inheritance…
# πŸ“š Java Programming Language – Part 6/10: Interfaces & Abstract Classes
#Java #OOP #Interfaces #AbstractClasses #Programming

Welcome to Part 6 of our Java series! Today we'll explore two crucial concepts for achieving abstraction in Java: Interfaces and Abstract Classes.

---

## πŸ”Ή Interfaces in Java
Interfaces define contracts that classes must implement (100% abstraction).

### 1. Interface Declaration (Pre-Java 8)
interface Drawable {
// Constant fields (implicitly public static final)
String COLOR = "Black";

// Abstract methods (implicitly public abstract)
void draw();
double calculateArea();
}


### 2. Implementing Interfaces
class Circle implements Drawable {
private double radius;

public Circle(double radius) {
this.radius = radius;
}

@Override
public void draw() {
System.out.println("Drawing a circle");
}

@Override
public double calculateArea() {
return Math.PI * radius * radius;
}
}


### 3. Modern Interfaces (Java 8+) Features
interface Vehicle {
// Traditional abstract method
void start();

// Default method (with implementation)
default void honk() {
System.out.println("Beep beep!");
}

// Static method
static void printType() {
System.out.println("I'm a vehicle");
}
}


---

## πŸ”Ή Abstract Classes
Classes that can't be instantiated and may contain abstract methods.

### 1. Abstract Class Example
abstract class Animal {
// Concrete method
public void breathe() {
System.out.println("Breathing...");
}

// Abstract method (no implementation)
public abstract void makeSound();
}


### 2. Extending Abstract Classes
class Dog extends Animal {
@Override
public void makeSound() {
System.out.println("Woof woof!");
}
}

// Usage:
Animal myPet = new Dog();
myPet.breathe(); // Inherited concrete method
myPet.makeSound(); // Implemented abstract method


---

## πŸ”Ή Key Differences

| Feature | Interface | Abstract Class |
|------------------------|-----------------------------------|------------------------------------|
| Instantiation | Cannot be instantiated | Cannot be instantiated |
| Methods | All abstract (pre-Java 8) | Can have both abstract & concrete |
| Variables | Only constants | Any variables |
| Multiple Inheritance | Class can implement many interfaces | Class extends only one abstract class |
| Default Methods | Supported (Java 8+) | Not applicable |
| Constructor | No constructors | Can have constructors |
| When to Use | Define contracts/APIs | Share code among related classes |

---
# πŸ“š 100 Essential Java Interview Questions
#Java #Interview #Programming #OOP #Collections #Multithreading

---

## πŸ”Ή Core Java (20 Questions)
1. What is JVM, JRE, and JDK?
2. Explain public static void main(String[] args)
3. Difference between == and .equals()?
4. What are Java primitives? List all 8.
5. Explain autoboxing/unboxing
6. What are varargs?
7. Difference between String, StringBuilder, and StringBuffer
8. What are immutable objects? How to create them?
9. Explain final, finally, and finalize
10. What are annotations? Common built-in annotations?
11. Difference between throw and throws
12. What is static keyword?
13. Can we override static methods?
14. What is method overloading vs overriding?
15. What is this and super keywords?
16. Explain pass-by-value in Java
17. What are wrapper classes? Why needed?
18. What is enum? When to use?
19. Difference between instanceof and getClass()
20. What is type casting? Implicit vs explicit

---

## πŸ”Ή OOP Concepts (15 Questions)
21. 4 Pillars of OOP with examples
22. What is abstraction vs encapsulation?
23. Difference between abstract class and interface (Java 8+)
24. Can an interface have constructors?
25. What is polymorphism? Runtime vs compile-time
26. What is method hiding?
27. What is composition vs inheritance?
28. What is the Liskov Substitution Principle?
29. How to achieve multiple inheritance in Java?
30. What is a singleton? Thread-safe implementation
31. What is a factory pattern?
32. What is a marker interface?
33. What is a POJO?
34. What is the instanceof operator used for?
35. What is object cloning? Shallow vs deep copy

---

## πŸ”Ή Collections Framework (15 Questions)
36. Collections hierarchy diagram explanation
37. Difference between List, Set, and Map
38. ArrayList vs LinkedList
39. HashSet vs TreeSet
40. HashMap vs HashTable vs ConcurrentHashMap
41. How HashMap works internally?
42. What is hashing? Hashcode/equals contract
43. What is Comparable vs Comparator?
44. Fail-fast vs fail-safe iterators
45. How to make collections immutable?
46. What is PriorityQueue?
47. Difference between Iterator and ListIterator
48. What are Java 8 stream APIs?
49. map() vs flatMap()
50. What are collectors? Common collectors

---

## πŸ”Ή Exception Handling (10 Questions)
51. Exception hierarchy in Java
52. Checked vs unchecked exceptions
53. What is try-with-resources?
54. Can we have try without catch?
55. What is exception propagation?
56. Difference between throw and throws
57. How to create custom exceptions?
58. What is Error vs Exception?
59. Best practices for exception handling
60. What is @SuppressWarnings?

---

## πŸ”Ή Multithreading (15 Questions)
61. Process vs thread
62. Ways to create threads
63. Runnable vs Callable
64. Thread lifecycle states
65. What is synchronization?
66. synchronized keyword usage
67. What are volatile variables?
68. What is deadlock? How to avoid?
69. What is thread starvation?
70. wait(), notify(), notifyAll() methods
71. What is thread pool? Executor framework
72. What is Future and CompletableFuture?
73. What is atomic variable?
74. What is ThreadLocal?
75. Concurrent collections in Java

---

## πŸ”Ή Java 8+ Features (10 Questions)
76. What are lambda expressions?
77. Functional interfaces in Java
78. Method references types
79. Optional class purpose
80. Stream API operations
81. map() vs flatMap()
82. What are default methods?
83. What are static methods in interfaces?
84. New Date/Time API benefits
85. Records and sealed classes

---

## πŸ”Ή JVM & Performance (10 Questions)
86. JVM architecture overview
87. What is classloader?
88. What is bytecode?
89. What is JIT compiler?
90. Heap memory structure
91. What is garbage collection? Types of GC
92. String pool concept
93. How to handle memory leaks?
94. What is OutOfMemoryError? Common causes
95. JVM tuning parameters

---
Data Analytics
## πŸ”Ή Modern Browser APIs ### 1. Web Components class MyElement extends HTMLElement { connectedCallback() { this.innerHTML = `<h2>Custom Element</h2>`; } } customElements.define('my-element', MyElement); ### 2. Intersection Observer const observer…
# πŸ“š JavaScript Tutorial - Part 7/10: Object-Oriented JavaScript & Prototypes
#JavaScript #OOP #Prototypes #Classes #DesignPatterns

Welcome to Part 7 of our JavaScript series! This comprehensive lesson will take you deep into JavaScript's object-oriented programming (OOP) system, prototypes, classes, and design patterns.

---

## πŸ”Ή JavaScript OOP Fundamentals
### 1. Objects in JavaScript
JavaScript objects are dynamic collections of properties with a hidden [[Prototype]] property.

// Object literal (most common)
const person = {
name: 'Ali',
age: 25,
greet() {
console.log(`Hello, I'm ${this.name}`);
}
};

// Properties can be added dynamically
person.country = 'UAE';
delete person.age;


### 2. Factory Functions
Functions that create and return objects.

function createPerson(name, age) {
return {
name,
age,
greet() {
console.log(`Hi, I'm ${this.name}`);
}
};
}

const ali = createPerson('Ali', 25);


### 3. Constructor Functions
The traditional way to create object blueprints.

function Person(name, age) {
// Instance properties
this.name = name;
this.age = age;

// Method (created for each instance)
this.greet = function() {
console.log(`Hello, I'm ${this.name}`);
};
}

const ali = new Person('Ali', 25);


The `new` keyword does:
1. Creates a new empty object
2. Sets this to point to the new object
3. Links the object's prototype to constructor's prototype
4. Returns the object (unless constructor returns something else)

---

## πŸ”Ή Prototypes & Inheritance
### 1. Prototype Chain
Every JavaScript object has a [[Prototype]] link to another object.

// Adding to prototype (shared across instances)
Person.prototype.introduce = function() {
console.log(`My name is ${this.name}, age ${this.age}`);
};

// Prototype chain lookup
ali.introduce(); // Checks ali β†’ Person.prototype β†’ Object.prototype β†’ null


### 2. Manual Prototype Inheritance
function Student(name, age, grade) {
Person.call(this, name, age); // "Super" constructor
this.grade = grade;
}

// Set up prototype chain
Student.prototype = Object.create(Person.prototype);
Student.prototype.constructor = Student;

// Add methods
Student.prototype.study = function() {
console.log(`${this.name} is studying hard!`);
};


### 3. Object.create()
Pure prototypal inheritance.

const personProto = {
greet() {
console.log(`Hello from ${this.name}`);
}
};

const ali = Object.create(personProto);
ali.name = 'Ali';


---

## πŸ”Ή ES6 Classes
Syntactic sugar over prototypes.

### 1. Class Syntax
class Person {
// Constructor (called with 'new')
constructor(name, age) {
this.name = name;
this.age = age;
}

// Instance method
greet() {
console.log(`Hello, I'm ${this.name}`);
}

// Static method
static compareAges(a, b) {
return a.age - b.age;
}
}


### 2. Inheritance with `extends`
class Student extends Person {
constructor(name, age, grade) {
super(name, age); // Must call super first
this.grade = grade;
}

study() {
console.log(`${this.name} is studying`);
}

// Override method
greet() {
super.greet(); // Call parent method
console.log(`I'm in grade ${this.grade}`);
}
}


### 3. Class Features (ES2022+)
class ModernClass {
// Public field (instance property)
publicField = 1;

// Private field (starts with #)
#privateField = 2;

// Static public field
static staticField = 3;

// Static private field
static #staticPrivateField = 4;

// Private method
#privateMethod() {
return this.#privateField;
}
}


---

## πŸ”Ή Property Descriptors
Advanced control over object properties.

### 1. Property Attributes
const obj = {};

Object.defineProperty(obj, 'readOnlyProp', {
value: 42,
writable: false, // Can't be changed
enumerable: true, // Shows up in for...in
configurable: false // Can't be deleted/reconfigured
});
Data Analytics
## πŸ”Ή Modern Browser APIs ### 1. Web Components class MyElement extends HTMLElement { connectedCallback() { this.innerHTML = `<h2>Custom Element</h2>`; } } customElements.define('my-element', MyElement); ### 2. Intersection Observer const observer…
### 2. Getters & Setters
class Temperature {
constructor(celsius) {
this.celsius = celsius;
}

get fahrenheit() {
return this.celsius * 1.8 + 32;
}

set fahrenheit(value) {
this.celsius = (value - 32) / 1.8;
}
}

const temp = new Temperature(25);
console.log(temp.fahrenheit); // 77
temp.fahrenheit = 100;


---

## πŸ”Ή Design Patterns in JavaScript
### 1. Singleton Pattern
class AppConfig {
constructor() {
if (AppConfig.instance) {
return AppConfig.instance;
}

this.settings = { theme: 'dark' };
AppConfig.instance = this;
}
}

const config1 = new AppConfig();
const config2 = new AppConfig();
console.log(config1 === config2); // true


### 2. Factory Pattern
class UserFactory {
static createUser(type) {
switch(type) {
case 'admin':
return new Admin();
case 'customer':
return new Customer();
default:
throw new Error('Invalid user type');
}
}
}


### 3. Observer Pattern
class EventEmitter {
constructor() {
this.events = {};
}

on(event, listener) {
(this.events[event] || (this.events[event] = [])).push(listener);
}

emit(event, ...args) {
this.events[event]?.forEach(listener => listener(...args));
}
}

const emitter = new EventEmitter();
emitter.on('login', user => console.log(`${user} logged in`));
emitter.emit('login', 'Ali');


### 4. Module Pattern
const CounterModule = (() => {
let count = 0;

return {
increment() {
count++;
},
getCount() {
return count;
}
};
})();


---

## πŸ”Ή Practical Example: RPG Character System
class Character {
constructor(name, level) {
this.name = name;
this.level = level;
this.health = 100;
}

attack(target) {
const damage = this.level * 2;
target.takeDamage(damage);
console.log(`${this.name} attacks ${target.name} for ${damage} damage`);
}

takeDamage(amount) {
this.health -= amount;
if (this.health <= 0) {
console.log(`${this.name} has been defeated!`);
}
}
}

class Mage extends Character {
constructor(name, level, mana) {
super(name, level);
this.mana = mana;
}

castSpell(target) {
if (this.mana >= 10) {
const damage = this.level * 3;
this.mana -= 10;
target.takeDamage(damage);
console.log(`${this.name} casts a spell on ${target.name}!`);
} else {
console.log("Not enough mana!");
}
}
}

// Usage
const warrior = new Character('Conan', 5);
const wizard = new Mage('Gandalf', 7, 50);

warrior.attack(wizard);
wizard.castSpell(warrior);


---

## πŸ”Ή Performance Considerations
### 1. Prototype vs Instance Methods
- Prototype methods are memory efficient (shared)
- Instance methods are created per object

### 2. Object Creation Patterns
| Pattern | Speed | Memory | Features |
|---------|-------|--------|----------|
| Constructor | Fast | Efficient | Full prototype chain |
| Factory | Medium | Less efficient | No instanceof |
| Class | Fast | Efficient | Clean syntax |

### 3. Property Access Optimization
// Faster (direct property access)
obj.propertyName;

// Slower (dynamic property access)
obj['property' + 'Name'];


---

## πŸ”Ή Best Practices
1. Use classes for complex hierarchies
2. Favor composition over deep inheritance
3. Keep prototypes lean for performance
4. Use private fields for encapsulation
5. Document your classes with JSDoc

---

### πŸ“Œ What's Next?
In Part 8, we'll cover:
➑️ Functional Programming in JavaScript
➑️ Pure Functions & Immutability
➑️ Higher-Order Functions
➑️ Redux Patterns

#JavaScript #OOP #DesignPatterns πŸš€

Practice Exercise:
1. Implement a Vehicle β†’ Car β†’ ElectricCar hierarchy
2. Create a BankAccount class with private balance
3. Build an observable ShoppingCart using the Observer pattern