0% found this document useful (0 votes)
2 views14 pages

Java Programming - Class X Revision Notes Chapter1

This document serves as a comprehensive guide to Java programming fundamentals for ICSE/ISC students, covering key concepts such as Object Oriented Programming, classes and objects, data types, operators, input handling, and control structures. It includes practical examples and exam tips to aid understanding and retention. The content is structured in a way that relates programming concepts to real-world analogies for easier comprehension.

Uploaded by

swarhhhswarjjj
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views14 pages

Java Programming - Class X Revision Notes Chapter1

This document serves as a comprehensive guide to Java programming fundamentals for ICSE/ISC students, covering key concepts such as Object Oriented Programming, classes and objects, data types, operators, input handling, and control structures. It includes practical examples and exam tips to aid understanding and retention. The content is structured in a way that relates programming concepts to real-world analogies for easier comprehension.

Uploaded by

swarhhhswarjjj
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

🚀 Java Programming - Class X Revision

Notes

Complete Guide to Java Fundamentals for ICSE/ISC Students

📚 Table of Contents

1. Introduction to Object Oriented Programming Concepts

2. Elementary Concept of Objects and Classes

3. Values and Data Types

4. Operators in Java

5. Input in Java

6. Mathematical Library Methods

7. Conditional Constructs in Java

8. Iterative Constructs in Java

9. Nested for Loops

1. Introduction to Object Oriented Programming Concepts


🎯
What is Object Oriented Programming (OOP)?

Hey class! Think of OOP like organizing your Instagram account. Just like you have different types
of posts (photos, stories, reels), OOP organizes code into different types called classes. Each post
has properties (likes, comments, date) and actions (like, share, delete) - this is exactly how OOP
works!
Key OOP Concepts:

Class: A blueprint or template (like a cookie cutter)


Object: An actual instance created from a class (like individual cookies)
Encapsulation: Keeping data safe inside a class (like keeping your diary private)
Inheritance: One class getting features from another (like getting your parent's traits)

📝 Exam Tip: Remember the real-world analogy! Car is a class, your family's car is an object.
Always relate OOP concepts to real-world examples in your answers.

Summary: OOP organizes code like organizing your room - everything has its place and
purpose. Classes are blueprints, objects are the actual things created from those blueprints.

2. Elementary Concept of Objects and Classes 🏗️

Understanding Classes

A class is like a blueprint for a house. It defines what rooms the house will have, but it's not the
actual house yet!

Basic Class Structure:

class Student {
// Data members (attributes)
String name;
int age;
String grade;

// Method (behavior)
void displayInfo() {
[Link]("Name: " + name);
[Link]("Age: " + age);
[Link]("Grade: " + grade);
}
}

Creating Objects

Now let's create actual students (objects) from our Student blueprint (class):
public class School {
public static void main(String[] args) {
// Creating objects
Student student1 = new Student();
Student student2 = new Student();

// Setting values
[Link] = "Alice";
[Link] = 15;
[Link] = "10th";

[Link] = "Bob";
[Link] = 16;
[Link] = "10th";

// Calling methods
[Link]();
[Link]();
}
}

📝 Exam Tip: Always remember the syntax! ClassName objectName = new


ClassName(); The new keyword is essential for creating objects.

Summary: Classes are templates that define structure and behavior. Objects are actual
instances created from classes using the new keyword.

3. Values and Data Types 📊

Primitive Data Types

Think of data types like different sized containers for different types of stuff in your locker!

Data Type Size Range Example

byte 1 byte -128 to 127 byte age = 15;

int 4 bytes -2.1 billion to 2.1 billion int marks = 95;

double 8 bytes 15 decimal digits double height = 5.6;


boolean 1 bit true or false boolean passed = true;

char 2 bytes Single character char grade = 'A';

Non-Primitive Data Types

// String - for text


String name = "John Doe";
String school = "ABC High School";

// Arrays - for multiple values


int[] marks = {95, 87, 92, 78, 88};
String[] subjects = {"Math", "Science", "English"};

📝 Exam Tip: Remember that String starts with capital S (it's a class), while int ,
double , etc. are lowercase (primitive types).

Summary: Java has 8 primitive data types for basic values and non-primitive types like String
and arrays for complex data. Choose the right type based on your data size and requirements.

4. Operators in Java ⚡

Arithmetic Operators

Just like your calculator, but in code!

int a = 10, b = 3;

[Link]("Addition: " + (a + b)); // 13


[Link]("Subtraction: " + (a - b)); // 7
[Link]("Multiplication: " + (a * b)); // 30
[Link]("Division: " + (a / b)); // 3 (integer division)
[Link]("Modulus: " + (a % b)); // 1 (remainder)

Comparison Operators

These help you compare values, like comparing your test scores!
int score1 = 85, score2 = 90;

[Link](score1 == score2); // false (equal to)


[Link](score1 != score2); // true (not equal to)
[Link](score1 < score2); // true (less than)
[Link](score1 > score2); // false (greater than)
[Link](score1 <= 90); // true (less than or equal)
[Link](score1 >= 80); // true (greater than or equal)

Logical Operators

boolean hasHomework = true;


boolean hasExam = false;

// AND operator (&&)


boolean busyDay = hasHomework && hasExam; // false

// OR operator (||)
boolean studyNeeded = hasHomework || hasExam; // true

// NOT operator (!)


boolean freeDay = !hasHomework; // false

📝 Exam Tip: Remember the difference between = (assignment) and == (comparison). This
is a common mistake in exams!

Summary: Operators perform operations on variables and values. Arithmetic for math,
comparison for checking conditions, and logical for combining conditions.

5. Input in Java 📥

Using Scanner Class

Scanner is like asking your friend a question and waiting for their answer!

import [Link];

public class InputExample {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter your name: ");
String name = [Link]();

[Link]("Enter your age: ");


int age = [Link]();

[Link]("Enter your height (in meters): ");


double height = [Link]();

[Link]("Hello " + name + "!");


[Link]("You are " + age + " years old");
[Link]("Your height is " + height + " meters");

[Link](); // Always close the scanner!


}
}

Different Input Methods

nextInt() - reads an integer


nextDouble() - reads a decimal number
next() - reads a single word
nextLine() - reads a complete line
nextBoolean() - reads true/false

📝 Exam Tip: Always import [Link] at the top and don't forget to close the
scanner with [Link]() for good practice!

Summary: Scanner class helps us take input from users. Import it, create an object, use
appropriate methods, and always close it when done.

6. Mathematical Library Methods 🧮

Math Class Methods

Java's Math class is like having a scientific calculator built into your code!

public class MathExample {


public static void main(String[] args) {
double num1 = 16.0;
double num2 = 4.0;
double negative = -7.5;

// Power and roots


[Link]("Square root of " + num1 + " = " + [Link](num1)); /
[Link](num2 + " to the power 3 = " + [Link](num2, 3)); /

// Absolute value
[Link]("Absolute value of " + negative + " = " + [Link](neg

// Rounding
[Link]("Ceiling of 4.3 = " + [Link](4.3)); // 5.0
[Link]("Floor of 4.7 = " + [Link](4.7)); // 4.0
[Link]("Round of 4.6 = " + [Link](4.6)); // 5

// Min and Max


[Link]("Maximum of 10 and 15 = " + [Link](10, 15)); // 15
[Link]("Minimum of 10 and 15 = " + [Link](10, 15)); // 10

// Random number (0.0 to 1.0)


[Link]("Random number: " + [Link]());
}
}

Generating Random Numbers in Range

// Random number between 1 and 100


 
int randomNum = (int)([Link]() * 100) + 1;
[Link]("Random number between 1-100: " + randomNum);

// Random number between 10 and 50


int randomInRange = (int)([Link]() * 41) + 10; // 41 = (50-10+1)
[Link]("Random number between 10-50: " + randomInRange);

📝 Exam Tip: For random numbers in range, use formula: (int)([Link]() *


(max - min + 1)) + min

Summary: Math class provides ready-to-use mathematical functions. No need to create


objects, just use [Link]() directly.

7. Conditional Constructs in Java 🎯

if-else Statements
Think of if-else like choosing what to wear based on the weather!

import [Link];

public class GradeCalculator {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

[Link]("Enter your marks: ");


int marks = [Link]();

if (marks >= 90) {


[Link]("Grade: A+ (Excellent!)");
} else if (marks >= 80) {
[Link]("Grade: A (Very Good!)");
} else if (marks >= 70) {
[Link]("Grade: B (Good!)");
} else if (marks >= 60) {
[Link]("Grade: C (Average)");
} else if (marks >= 50) {
[Link]("Grade: D (Below Average)");
} else {
[Link]("Grade: F (Failed)");
}

[Link]();
}
}

switch Statement

Switch is like a remote control - different buttons for different channels!

import [Link];

public class MenuSystem {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

[Link]("=== CAFETERIA MENU ===");


[Link]("1. Pizza - Rs.150");
[Link]("2. Burger - Rs.80");
[Link]("3. Sandwich - Rs.60");
[Link]("4. Cold Drink - Rs.40");
[Link]("Enter your choice (1-4): ");

int choice = [Link]();


switch (choice) {
case 1:
[Link]("You ordered Pizza - Rs.150");
break;
case 2:
[Link]("You ordered Burger - Rs.80");
break;
case 3:
[Link]("You ordered Sandwich - Rs.60");
break;
case 4:
[Link]("You ordered Cold Drink - Rs.40");
break;
default:
[Link]("Invalid choice! Please select 1-4");
}

[Link]();
}
}

📝 Exam Tip: Don't forget the break statements in switch cases! Without break, the
program will execute all subsequent cases too.

Summary: Use if-else for complex conditions and ranges. Use switch for simple equality
checks with specific values. Both help control program flow based on conditions.

8. Iterative Constructs in Java 🔄

for Loop

A for loop is like doing jumping jacks - you know exactly how many times you'll repeat!

public class ForLoopExample {


public static void main(String[] args) {
// Printing numbers 1 to 10
[Link]("Numbers 1 to 10:");
for (int i = 1; i <= 10; i++) {
[Link](i + " ");
}

[Link]("\n\nMultiplication Table of 7:");


for (int i = 1; i <= 10; i++) {
[Link]("7 × " + i + " = " + (7 * i));
}
}
}

while Loop

While loop is like eating snacks while watching a movie - you continue until the condition
changes!

import [Link];

public class WhileLoopExample {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

int password = 1234;


int userInput = 0;
int attempts = 0;

while (userInput != password && attempts < 3) {


[Link]("Enter password: ");
userInput = [Link]();
attempts++;

if (userInput != password) {
[Link]("Wrong password! Attempts left: " + (3 - attem
}
}

if (userInput == password) {
[Link]("Access granted! Welcome!");
} else {
[Link]("Account locked! Too many failed attempts.");
}

[Link]();
}
}

 

do-while Loop

Do-while is like trying a new game - you'll play at least once, then decide if you want to continue!

import [Link];
public class DoWhileExample {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
char playAgain;

do {
int secretNumber = (int)([Link]() * 10) + 1;
[Link]("Guess the number (1-10): ");
int guess = [Link]();

if (guess == secretNumber) {
[Link]("🎉 Correct! The number was " + secretNumber);
} else {
[Link]("❌ Wrong! The number was " + secretNumber);
}

[Link]("Play again? (y/n): ");


playAgain = [Link]().charAt(0);

} while (playAgain == 'y' || playAgain == 'Y');

[Link]("Thanks for playing!");


[Link]();
}
}

 📝 Exam Tip: Remember: for loop when you know the count, while loop when condition is 
checked first, do-while when you want to execute at least once.

Summary: Loops help repeat code efficiently. For loop for known iterations, while loop for
condition-based repetition, do-while for guaranteed first execution.

9. Nested for Loops 🎪

Understanding Nested Loops

Nested loops are like organizing a tournament - outer loop for rounds, inner loop for matches in
each round!

Pattern Printing
public class PatternExamples {
public static void main(String[] args) {

// Pattern 1: Rectangle of Stars


[Link]("Rectangle Pattern:");
for (int i = 1; i <= 4; i++) { // Outer loop - rows
for (int j = 1; j <= 6; j++) { // Inner loop - columns
[Link]("* ");
}
[Link](); // New line after each row
}

[Link]("\nRight Triangle Pattern:");


// Pattern 2: Right Triangle
for (int i = 1; i <= 5; i++) { // Outer loop - rows
for (int j = 1; j <= i; j++) { // Inner loop - stars
[Link]("* ");
}
[Link]();
}

[Link]("\nNumber Triangle:");
// Pattern 3: Number Triangle
for (int i = 1; i <= 4; i++) { // Outer loop - rows
for (int j = 1; j <= i; j++) { // Inner loop - numbers
[Link](j + " ");
}
[Link]();
}
}
}

Multiplication Table

public class MultiplicationTables {


public static void main(String[] args) {
[Link]("=== MULTIPLICATION TABLES (1 to 5) ===\n");

for (int table = 1; table <= 5; table++) { // Outer loop - tables


[Link]("Table of " + table + ":");

for (int num = 1; num <= 10; num++) { // Inner loop - numbers
[Link](table + " × " + num + " = " + (table * num));
}
[Link](); // Space between tables
}
}
}

Matrix Operations

import [Link];

public class MatrixExample {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int[][] matrix = new int[3][3];

// Input matrix elements


[Link]("Enter 9 numbers for 3x3 matrix:");
for (int i = 0; i < 3; i++) { // Outer loop - rows
 
for (int j = 0; j < 3; j++) { // Inner loop - columns
[Link]("Enter element [" + i + "][" + j + "]: ");
matrix[i][j] = [Link]();
}
}

// Display matrix
[Link]("\nYour 3x3 Matrix:");
for (int i = 0; i < 3; i++) { // Outer loop - rows
for (int j = 0; j < 3; j++) { // Inner loop - columns
[Link](matrix[i][j] + "\t");
}
[Link]();
}

[Link]();
}
}

📝 Exam Tip: In nested loops, the inner loop completes ALL its iterations for EACH iteration
of the outer loop. Trace through with small numbers to understand the flow!

Summary: Nested loops are loops inside loops. Outer loop controls rows/major categories,
inner loop controls columns/items within each category. Perfect for patterns, tables, and 2D
arrays.

🎓 You've Completed the Java Revision!


Great job! You now have a solid foundation in Java programming. Practice these concepts
with different examples and you'll be ready for your exams!

Remember: Programming is like learning to ride a bike - practice makes perfect! 🚴‍♂️

You might also like