π The Rules of Programming (2023)
π Download Link: https://shts.me/bsNS
π¬ Tags: #programming
β By: @DataScience_Books - @DataScience4 - @EBooks2023
π Download Link: https://shts.me/bsNS
π¬ Tags: #programming
β By: @DataScience_Books - @DataScience4 - @EBooks2023
π How to Make Things Faster (2023)
π Download Link: https://shts.me/PaPh
π¬ Tags: #programming
β By: @DataScience_Books - @DataScience4 - @EBooks2023
π Download Link: https://shts.me/PaPh
π¬ Tags: #programming
β By: @DataScience_Books - @DataScience4 - @EBooks2023
π Quick Functional Programming (2023)
π Download Link: https://link.pnfreegames.com/T9hj
π¬ Tags: #programming
βοΈ β interaction = β books
β Click here π: Surprise π
π Download Link: https://link.pnfreegames.com/T9hj
π¬ Tags: #programming
βοΈ β interaction = β books
β Click here π: Surprise π
π1
π Functional Design and Architecture (2023 - V9)
1β£ Join Channel Download:
https://t.iss.one/+MhmkscCzIYQ2MmM8
2β£ Download Book: https://t.iss.one/c/1854405158/92
π¬ Tags: #Programming
USEFUL CHANNELS FOR YOU
1β£ Join Channel Download:
https://t.iss.one/+MhmkscCzIYQ2MmM8
2β£ Download Book: https://t.iss.one/c/1854405158/92
π¬ Tags: #Programming
USEFUL CHANNELS FOR YOU
π3β€βπ₯2β€1
Forwarded from Machine Learning with Python
β Online
β PDF
β Online
β PDF
β Online
β PDF
β Online
β PDF
β Online
β PDF
β Online
β PDF
β Online
β PDF
β Online
β PDF
β Online
β PDF
β Online
β PDF
#DataScience #Python #DataAnalysis #DataVisualization #RProgramming #DeepLearning #CommandLine #HandsOnLearning #Statistics #Bayesian #Kafka #MachineLearning #AI #Programming #FreeBooks
https://t.iss.one/CodeProgrammerβ
Please open Telegram to view this post
VIEW IN TELEGRAM
π12β€3π₯1
# π Connecting MySQL Database with Popular Programming Languages
#MySQL #Programming #Database #Python #Java #CSharp #PHP #Kotlin #MATLAB #Julia
MySQL is a powerful relational database management system. Hereβs how to connect MySQL with various programming languages.
---
## πΉ 1. Connecting MySQL with Python
#Python #MySQL
Use the
---
## πΉ 2. Connecting MySQL with Java
#Java #JDBC
Use JDBC (Java Database Connectivity).
---
## πΉ 3. Connecting MySQL with C# (.NET)
#CSharp #DotNet #MySQL
Use
---
## πΉ 4. Connecting MySQL with PHP
#PHP #MySQL
Use
---
## πΉ 5. Connecting MySQL with Kotlin
#Kotlin #JDBC
Use JDBC (similar to Java).
---
## πΉ 6. Connecting MySQL with MATLAB
#MATLAB #Database
Use Database Toolbox.
---
## πΉ 7. Connecting MySQL with Julia
#Julia #MySQL
Use
---
#MySQL #Programming #Database #Python #Java #CSharp #PHP #Kotlin #MATLAB #Julia
MySQL is a powerful relational database management system. Hereβs how to connect MySQL with various programming languages.
---
## πΉ 1. Connecting MySQL with Python
#Python #MySQL
Use the
mysql-connector-python or pymysql library. import mysql.connector
# Establish connection
conn = mysql.connector.connect(
host="localhost",
user="your_username",
password="your_password",
database="your_database"
)
cursor = conn.cursor()
cursor.execute("SELECT * FROM your_table")
result = cursor.fetchall()
for row in result:
print(row)
conn.close()
---
## πΉ 2. Connecting MySQL with Java
#Java #JDBC
Use JDBC (Java Database Connectivity).
import java.sql.*;
public class MySQLJava {
public static void main(String[] args) {
String url = "jdbc:mysql://localhost:3306/your_database";
String user = "your_username";
String password = "your_password";
try {
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM your_table");
while (rs.next()) {
System.out.println(rs.getString("column_name"));
}
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
---
## πΉ 3. Connecting MySQL with C# (.NET)
#CSharp #DotNet #MySQL
Use
MySql.Data NuGet package. using MySql.Data.MySqlClient;
string connStr = "server=localhost;user=your_username;database=your_database;password=your_password";
MySqlConnection conn = new MySqlConnection(connStr);
try {
conn.Open();
string query = "SELECT * FROM your_table";
MySqlCommand cmd = new MySqlCommand(query, conn);
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read()) {
Console.WriteLine(reader["column_name"]);
}
} catch (Exception ex) {
Console.WriteLine(ex.Message);
} finally {
conn.Close();
}
---
## πΉ 4. Connecting MySQL with PHP
#PHP #MySQL
Use
mysqli or PDO. <?php
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM your_table";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo $row["column_name"];
}
} else {
echo "0 results";
}
$conn->close();
?>
---
## πΉ 5. Connecting MySQL with Kotlin
#Kotlin #JDBC
Use JDBC (similar to Java).
import java.sql.DriverManager
fun main() {
val url = "jdbc:mysql://localhost:3306/your_database"
val user = "your_username"
val password = "your_password"
try {
val conn = DriverManager.getConnection(url, user, password)
val stmt = conn.createStatement()
val rs = stmt.executeQuery("SELECT * FROM your_table")
while (rs.next()) {
println(rs.getString("column_name"))
}
conn.close()
} catch (e: Exception) {
e.printStackTrace()
}
}
---
## πΉ 6. Connecting MySQL with MATLAB
#MATLAB #Database
Use Database Toolbox.
conn = database('your_database', 'your_username', 'your_password', 'com.mysql.jdbc.Driver', 'jdbc:mysql://localhost:3306/your_database');
data = fetch(conn, 'SELECT * FROM your_table');
disp(data);
close(conn);---
## πΉ 7. Connecting MySQL with Julia
#Julia #MySQL
Use
MySQL.jl package. using MySQL
conn = MySQL.connect("localhost", "your_username", "your_password", db="your_database")
result = MySQL.execute(conn, "SELECT * FROM your_table")
for row in result
println(row)
end
MySQL.disconnect(conn)
---
β€5
# π 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
2. Compile into bytecode (
3. JVM (Java Virtual Machine) executes the bytecode
---
## πΉ 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
3οΈβ£ Set `JAVA_HOME` (For IDE compatibility)
---
## πΉ Your First Java Program
### π Explanation:
-
-
-
### βΆοΈ How to Run?
Output:
---
## πΉ Java Syntax Basics
β Case-Sensitive β
β Class Names β
β Method/Variable Names β
β Every statement ends with `;`
---
## πΉ Variables & Data Types
Java supports primitive and non-primitive types.
### Primitive Types (Stored in Stack Memory)
| Type | Size | Example |
|-----------|---------|----------------|
|
|
|
|
### Non-Primitive (Reference Types, Stored in Heap)
-
- Arrays β
- Classes & Objects
---
### π Whatβs Next?
In Part 2, weβll cover:
β‘οΈ Operators & Control Flow (if-else, loops)
β‘οΈ Methods & Functions
Stay tuned! π
#LearnJava #JavaBasics #CodingForBeginners
#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
Oracle
Download the Latest Java LTS Free
Subscribe to Java SE and get the most comprehensive Java support available, with 24/7 global access to the experts.
β€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
### 2. Relational Operators
### 3. Logical Operators
### 4. Assignment Operators
---
## πΉ Control Flow Statements
Control the execution flow of your program.
### 1. if-else Statements
### 2. Ternary Operator
### 3. switch-case Statement
### 4. Loops
#### while Loop
#### do-while Loop
#### for Loop
#### Enhanced for Loop (for-each)
---
## πΉ Break and Continue
Control loop execution flow.
---
## πΉ Practical Example: Number Guessing Game
---
### π What's Next?
In Part 3, we'll cover:
β‘οΈ Methods and Functions
β‘οΈ Method Overloading
β‘οΈ Recursion
#JavaProgramming #ControlFlow #LearnToCodeπ
#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 Components
### 1. Simple Method Example
### 2. Method Parameters
### 3. Return Values
---
## πΉ Method Overloading
Multiple methods with same name but different parameters.
---
## πΉ Recursion
A method that calls itself.
### 1. Factorial Example
### 2. Fibonacci Sequence
---
## πΉ Variable Scope
Variables have different scope depending on where they're declared.
---
## πΉ Practical Example: Temperature Converter
---
## πΉ 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
#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 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
### 2. Creating Objects
---
## πΉ Constructors
Special methods called when an object is instantiated.
### 1. Default Constructor
### 2. Parameterized Constructor
### 3. Constructor Overloading
---
## πΉ Encapsulation
Protecting data by making fields private and providing public getters/setters.
---
## πΉ 'this' Keyword
Refers to the current object instance.
---
## πΉ Practical Example: Student Management System
---
## πΉ 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 |
---
#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);
}
}---