Java Programming Notes for Class 10
1. Revision of Class IX Syllabus
1.1 Introduction to Object-Oriented Programming (OOP)
- OOP is a programming style based on real-world concepts like objects and classes.
- Key Features: Encapsulation, Inheritance, Polymorphism, Abstraction.
- Benefits: Code reuse, modularity, and easier debugging.
1.2 Elementary Concept of Objects and Classes
- Object: A real-world entity with state (data) and behavior (methods).
- Class: A blueprint to create objects.
Example:
class Car {
int speed;
void drive() {
System.out.println("The car is driving.");
1.3 Values and Data Types
- Primitive Types: int, char, float, double, boolean.
- Reference Types: Objects and arrays.
Example:
int age = 20; // Primitive
String name = "John"; // Reference
1.4 Operators in Java
- Arithmetic: +, -, *, /, %
- Relational: ==, !=, >, <, >=, <=
- Logical: &&, ||, !
- Assignment: =, +=, -=, etc.
- Unary: ++, --
1.5 Input in Java
- Use Scanner class to take input:
import java.util.Scanner;
Scanner sc = new Scanner(System.in);
int number = sc.nextInt();
1.6 Mathematical Library Methods
- Common methods in Math class:
Math.sqrt(double x): Finds square root.
Math.pow(double a, double b): Calculates power.
Math.abs(int x): Absolute value.
1.7 Conditional Constructs in Java
- Use if, if-else, and switch statements.
Example:
if (age > 18) {
System.out.println("Eligible to vote.");
} else {
System.out.println("Not eligible.");
}
1.8 Iterative Constructs in Java
- Loops: for, while, do-while.
- Nested loops for complex problems.
Example:
for (int i = 1; i <= 5; i++) {
System.out.println(i);