×

Java

📌 Important Notice & Guidelines

  • Scholarship Rule: The percentage of marks you score in the test will be equal to the percentage of scholarship you receive.
  • Weekly Test: Tests will be conducted every Friday.
  • Result Update: Your marks/results will be updated on the WhatsApp Channel every Saturday.
  • New Batches: New batches will start every Monday.

1. Introduction to Java

Java is an object-oriented, platform-independent programming language used in desktop, web, and mobile applications. Its slogan “Write Once, Run Anywhere” means code can run on any machine. Java syntax is similar to C/C++ and beginner-Satendly.

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
                

Hello, World!

2. Java Basics – Variables and Data Types

Variables store data in programs. Java has primitive data types: int, float, double, char, boolean.

int age = 20;
double price = 99.99;
char grade = 'A';
boolean isPassed = true;
System.out.println(age + ", " + price + ", " + grade + ", " + isPassed);
                

20, 99.99, A, true

3. Operators in Java

Operators perform arithmetic, relational, and logical operations. Assignment operators are also used.

int a = 10, b = 5;
System.out.println(a + b); // Addition
System.out.println(a > b);  // Comparison
System.out.println(a != b); // Not equal
                

15
true
true

4. Conditional Statements (if-else, switch)

Conditional statements control the program flow.

int num = -5;
if(num > 0) {
    System.out.println("Positive");
} else if(num < 0) {
    System.out.println("Negative");
} else {
    System.out.println("Zero");
}
                

Negative

5. Loops in Java (for, while, do-while)

Loops are used for repetitive tasks.

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

1 2 3 4 5

6. Arrays in Java

Arrays store multiple values together. Index starts from 0.

String[] fruits = {"Apple", "Banana", "Mango"};
System.out.println(fruits[1]);
        

Banana

7. Functions / Methods in Java

Methods make code modular and reusable. Parameters and return types are specified.

public static int multiply(int a, int b) {
    return a * b;
}
System.out.println(multiply(5, 4));
        

20

8. Object-Oriented Programming – Classes & Objects

Class is a blueprint, object is a real instance. OOP concepts: Encapsulation, Inheritance, Polymorphism.

class Car {
    String color;
}
Car myCar = new Car();
myCar.color = "Red";
System.out.println(myCar.color);
        

Red

9. Constructors in Java

Constructor initializes objects during creation. Types: Default and Parameterized.

class Car {
    String color;
    Car(String c) { color = c; }
}
Car myCar = new Car("Blue");
System.out.println(myCar.color);
        

Blue

10. Inheritance

Inheritance allows a class to inherit properties and methods from another class.

class Vehicle { int speed = 100; }
class Bike extends Vehicle {}
Bike myBike = new Bike();
System.out.println(myBike.speed);
        

100

11. Polymorphism

Polymorphism allows a function to take multiple forms. Compile-time (method overloading) and Run-time (method overriding).

class Math {
    int sum(int a, int b) { return a+b; }
    int sum(int a, int b, int c) { return a+b+c; }
}
Math m = new Math();
System.out.println(m.sum(2,3));
System.out.println(m.sum(2,3,4));
        

5
9

12. Encapsulation

Encapsulation keeps data private and accessed via getter/setter.

class Student {
    private String name;
    public void setName(String n) { name = n; }
    public String getName() { return name; }
}
Student s = new Student();
s.setName("Avi");
System.out.println(s.getName());
        

Avi

13. Exception Handling

Use try-catch-finally to handle errors in Java.

try {
    int a = 10/0;
} catch(Exception e) {
    System.out.println("Error occurred");
} finally {
    System.out.println("Execution complete");
}
        

Error occurred
Execution complete

14. Java Packages

Packages help organize and reuse code.

import java.util.Scanner;
Scanner sc = new Scanner(System.in);
System.out.println("Enter your name:");
String name = sc.nextLine();
System.out.println("Hello " + name);
        

Enter your name: Avi
Hello Avi

15. File Handling in Java

Java uses File, FileReader, FileWriter, BufferedReader/Writer to read/write files.

import java.io.File;
public class ReadFile {
    public static void main(String[] args) {
        File file = new File("test.txt");
        if(file.exists()) {
            System.out.println("File exists");
        } else {
            System.out.println("File not found");
        }
    }
}
        

File exists

Best of Luck to All Students!

Give your best in the test, stay focused, and keep learning something new every day. Believe in yourself, and let each lesson make you stronger and smarter.

WhatsApp Chat