Java Class 10th Chapter 1
Java Class 10th Chapter 1
Page 1 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
Table of Contents
Table of Contents ................................................................................................................................................ 2
1.1 Procedure Oriented Programming (POP) .................................................................................................... 4
Characteristics of POP..................................................................................................................................... 4
Limitations of POP .......................................................................................................................................... 4
1.2 Object Oriented Programming (OOP) ......................................................................................................... 5
Characteristics of OOP .................................................................................................................................... 5
Advantages of OOP ......................................................................................................................................... 5
1.3 Difference between Procedure Oriented and Object Oriented Programming .......................................... 6
1.4 Elements and Principles of OOP .................................................................................................................. 7
1. Object .......................................................................................................................................................... 7
2. Class ............................................................................................................................................................. 7
3. Data Abstraction ......................................................................................................................................... 7
4. Encapsulation (Data Hiding) ....................................................................................................................... 7
5. Inheritance .................................................................................................................................................. 7
6. Polymorphism ............................................................................................................................................. 7
7. Dynamic Binding (Late Binding) ................................................................................................................. 7
8. Message Passing ......................................................................................................................................... 7
1.5 Class as an Object Factory ........................................................................................................................... 9
1.6 Class as a User-defined Data Type ............................................................................................................ 10
1.7 Message Passing between Objects ........................................................................................................... 11
Steps involved in message passing .............................................................................................................. 11
General syntax of a message ........................................................................................................................ 11
1.8 Introduction to Java ................................................................................................................................... 12
Important Features (Buzzwords) of Java ..................................................................................................... 12
JVM, JRE and JDK .......................................................................................................................................... 12
How a Java Program Executes ...................................................................................................................... 12
1.9 Introduction to BlueJ ................................................................................................................................. 13
Features of BlueJ ........................................................................................................................................... 13
Main Components of the BlueJ Interface .................................................................................................... 13
Steps to Work in BlueJ .................................................................................................................................. 13
1.10 Character Sets .......................................................................................................................................... 14
Types of Character Sets ................................................................................................................................ 14
1.11 Escape Sequence ...................................................................................................................................... 15
Commonly used Escape Sequences in Java.................................................................................................. 15
1.12 Tokens ...................................................................................................................................................... 16
Types of Tokens in Java ................................................................................................................................ 16
Rules for naming an Identifier ...................................................................................................................... 16
Some Reserved Keywords of Java ................................................................................................................ 16
Types of Literals ............................................................................................................................................ 16
Page 2 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
Page 3 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
In POP, importance is given to functions/procedures rather than to the data on which they operate. Data is
usually kept in global variables that can be freely accessed and modified by any function in the program.
Characteristics of POP
● Emphasis is on the algorithm / sequence of steps needed to solve a problem.
● Large programs are divided into smaller programs called functions.
● Most functions share global data, i.e. data moves freely around the system from function to function.
● Follows a top-down approach in program design (the problem is broken into sub-problems repeatedly).
● Data is not secure, since it is global and can be changed by any function accidentally.
● Examples of POP languages: C, Pascal, FORTRAN, COBOL, BASIC.
Limitations of POP
● Data is exposed to the entire program — no data hiding, so it is insecure.
● Difficult to relate real-world entities/objects to the program (does not model the real world naturally).
● Adding new data and functions is difficult without affecting existing code.
● Overuse of global data makes debugging and maintenance harder as the program grows.
● Does not support the concept of reusability of code through inheritance.
Exam Tip: Remember POP with the phrase “Functions over Data, Global Data, Top-Down” — this single line
answers most 2-mark POP questions.
Page 4 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
Unlike POP, OOP gives importance to data rather than procedures. Data is hidden inside objects and can be
accessed only through the object’s own methods, which makes the data secure.
Characteristics of OOP
● Emphasis is on data rather than on procedure.
● Programs are divided into objects, and each object contains both data and functions that act on that
data.
● Data is hidden inside objects (encapsulated) and cannot be accessed by outside functions directly.
● Objects communicate with each other through message passing (calling one another’s methods).
● Follows a bottom-up approach in program design (objects are identified first, then combined to build
the whole program).
● New data and functions can be added easily whenever required, without disturbing existing code.
● Supports the four pillars: Encapsulation, Abstraction, Inheritance and Polymorphism.
● Examples of OOP languages: Java, C++, Python, C#, BlueJ (built on Java).
Advantages of OOP
● Data security through encapsulation and data hiding.
● Code reusability through inheritance — saves development time.
● Easier to maintain, modify and debug because objects are independent units.
● Models real-world entities more naturally (e.g. a Student, a Car, a BankAccount can each be an object).
● Problems can be divided into smaller, self-contained pieces called objects.
Page 5 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
Page 6 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
1. Object
An object is a real-world entity or a basic run-time unit in an OOP system. It is an instance of a class and consists
of: (i) State — represented by the data/attributes of the object, and (ii) Behaviour — represented by the
methods/functions of the object. Example: “student1” is an object of the class Student, having state such as
name and rollNo, and behaviour such as calculateGrade().
2. Class
A class is a blueprint, template or a user-defined data type from which objects are created. It defines the data
members (fields) and member functions (methods) that its objects will have. A class itself does not occupy
memory for data until an object is created from it.
3. Data Abstraction
Data Abstraction refers to displaying only the essential features of an object to the outside world while hiding
the background details/implementation. For example, a person driving a car knows how to use the accelerator
and brake (essential features) without knowing the internal mechanism of the engine (implementation
details).
5. Inheritance
Inheritance is the mechanism by which a new class (called the derived/child/sub class) acquires the properties
(fields) and behaviours (methods) of an existing class (called the base/parent/super class). It supports the
concept of reusability — common features are written once in the parent class and reused by every child class.
Example: a class Vehicle can be the parent of child classes Car and Bike.
6. Polymorphism
Polymorphism means “many forms” — the ability of a message/function to behave differently depending on
the context in which it is used. In Java, it is mainly implemented through: (i) Method Overloading — same
method name with different parameter lists in the same class (compile-time/static polymorphism), and (ii)
Method Overriding — a child class provides a specific implementation of a method already defined in its parent
class (run-time/dynamic polymorphism).
8. Message Passing
Objects communicate with one another by sending and receiving information, called messages. A message is
essentially a request from one object asking another object to execute one of its methods. Message passing
Page 7 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
involves: creating classes, creating objects from the classes, and establishing communication among the
objects.
Exam Tip: A very common board question is: “State any two/four principles of OOP.” Be ready to write the
name PLUS a one-line definition for each — not the name alone.
Page 8 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
Analogy: Consider the class Car as a factory design. Using this one design, we can “manufacture” (instantiate)
many actual car objects such as car1, car2 and car3 — each having its own colour and registration number (its
own state), but all following the same blueprint (the same class).
class Car
{
String colour;
String regNo;
void display()
{
[Link]("Colour: " + colour);
[Link]("Reg. No: " + regNo);
}
}
class TestCar
{
public static void main(String args[])
{
Car car1 = new Car(); // object 1 manufactured from the class
Car car2 = new Car(); // object 2 manufactured from the class
[Link] = "Red";
[Link] = "UP32-AB-1234";
[Link] = "Blue";
[Link] = "UP32-CD-5678";
[Link]();
[Link]();
}
}
Output:
Colour: Red
Reg. No: UP32-AB-1234
Colour: Blue
Reg. No: UP32-CD-5678
Notice that only one class (Car) was written, but it acted as a factory to produce two independent objects (car1
and car2), each with its own data.
Page 9 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
Once a class is defined, its name can be used exactly like a built-in data type to declare variables (which are
then called objects/reference variables) that can store the composite data described by that class.
class TestStudent
{
public static void main(String args[])
{
Student s1; // s1 declared, just like "int x;"
s1 = new Student(); // memory allocated to the object
[Link] = "Aarav";
[Link] = 12;
[Link] = 92.5;
Output:
Aarav 12 92.5
Here, just as “int” is a built-in type used to declare variables like “int x;”, “Student” is a user-defined type used
to declare the reference variable “Student s1;”. This is why a class is described as a user-defined data type /
extensible data type.
Page 10 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
[Link](argumentList);
This statement is itself a message being sent to “objectName”, asking it to execute “methodName” using the
given arguments.
class Calculator
{
int add(int a, int b)
{
return a + b;
}
}
class TestMessage
{
public static void main(String args[])
{
Calculator calc = new Calculator(); // object created
int result = [Link](15, 20); // message passed to "calc"
[Link]("Sum = " + result);
}
}
Output:
Sum = 35
In this example, the object “calc” of class Calculator receives the message add(15, 20) from the main() method,
executes it, and returns the result 35, which demonstrates communication between the caller and the object.
Page 11 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
Exam Tip: Whenever a question asks “why is Java called platform independent”, always mention bytecode +
JVM together — mentioning only one of the two loses marks.
Page 12 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
Features of BlueJ
● Provides a simple and clean interface, ideal for beginners.
● Displays classes and their relationships visually through a UML-style class diagram.
● Objects can be created interactively on the “object bench” and their methods can be invoked directly
by right-clicking, without writing a main() method.
● Provides an inbuilt code editor, compiler and a terminal/console window for output.
● Allows step-by-step testing of individual methods, which is extremely useful for learning.
Main Components of the BlueJ Interface
Component Purpose
Contains menus such as Project, Edit, Tools, View, Help for various
Menu Bar
operations.
Provides quick-access buttons for common operations like Compile and
Tool Bar
New Class.
Shows all classes of the project as boxes, along with arrows depicting
Class Diagram (workspace)
relationships (e.g. inheritance).
The area at the bottom where created objects appear as red/orange
Object Bench
object icons, ready to be tested.
A separate console window that displays output produced by
Terminal Window
[Link]()/print() statements.
Opens when a class is double-clicked; used to write/edit the Java
Code Editor
source code of that class.
Steps to Work in BlueJ
● Create a new BlueJ project (Project → New Project).
● Create a new class (click “New Class” icon, provide a class name).
● Double-click the class icon to open the code editor and write the Java code.
● Click “Compile”; a red-striped icon turns plain once compilation succeeds.
● Right-click the class icon on the diagram and choose “new ClassName()” to create an object; give it an
object name.
● The new object appears on the object bench; right-click it and select a method to invoke (test) it.
● Output/results appear in the Terminal Window.
Page 13 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
Exam Tip: Java uses the Unicode character set (16-bit) internally for the char data type — this single fact is a
favourite board fill-in-the-blank/one-word question.
Page 14 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
Even though an escape sequence is written using two or more characters, the compiler treats the whole
sequence as a single character.
class EscapeDemo
{
public static void main(String args[])
{
[Link]("Rahul says, \"Java is fun!\"");
[Link]("Name\tAge\tCity");
[Link]("Aman\t15\tLucknow");
[Link]("Line1\nLine2");
}
}
Output:
Rahul says, "Java is fun!"
Name Age City
Aman 15 Lucknow
Line1
Line2
Page 15 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
1.12 Tokens
Definition: A token is the smallest individual unit of a Java program that is meaningful to the compiler. Every
Java program is essentially a sequence of tokens, separated by whitespace, punctuation or operators.
Types of Literals
Literal Type Example
Integer literal 10, -25, 0, 1000
Floating-point literal 3.14, -0.5, 2.0f
Character literal 'A', 'z', '5', '$'
String literal "Hello World", "ICSE"
Boolean literal true, false
Null literal null
Page 16 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
● 1. Primitive (Fundamental) Data Types: Predefined by the language; they store a single simple value
directly in memory. There are 8 primitive data types — byte, short, int, long, float, double, char and
boolean.
● 2. Non-Primitive (Reference/Derived) Data Types: Created by the programmer or provided by
libraries; they store the address (reference) of the object rather than the value itself. Examples —
String, Array, Class, Interface.
The 8 Primitive Data Types — Size and Range
Data Type Size Default Value Range / Values
byte 1 byte (8 bit) 0 –128 to 127
short 2 bytes (16 bit) 0 –32,768 to 32,767
int 4 bytes (32 bit) 0 –2,147,483,648 to 2,147,483,647
–9,223,372,036,854,775,808 to
long 8 bytes (64 bit) 0L
9,223,372,036,854,775,807
float 4 bytes (32 bit) 0.0f Single precision decimal (≈ 6–7 digits precision)
double 8 bytes (64 bit) 0.0d Double precision decimal (≈ 15 digits precision)
char 2 bytes (16 bit) '\u0000' 0 to 65,535 (single Unicode character)
boolean 1 bit (conceptual) false true or false only
Page 17 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
class DataTypeDemo
{
public static void main(String args[])
{
byte b = 100;
int age = 15;
long population = 1400000000L;
float pi_val = 3.14f;
double area = 154.532;
char grade = 'A';
boolean pass = true;
Output:
Byte : 100
Int : 15
Long : 1400000000
Float : 3.14
Double : 154.532
Char : A
Boolean : true
Page 18 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
1.14 Variables
Definition: A variable is a named memory location used to store a data value that can change (vary) during
the execution of a program. Every variable in Java must be declared with a data type before it is used.
Syntax of Declaration
// examples
int rollNo;
char grade = 'A';
class VariableDemo
{
int rollNo; // instance variable
static String school = "St. Xavier's"; // static (class) variable
void show() {
int marks = 88; // local variable
[Link]("Roll No : " + rollNo);
[Link]("School : " + school);
[Link]("Marks : " + marks);
}
public static void main(String args[]) {
VariableDemo obj = new VariableDemo();
[Link] = 21;
[Link]();
}
}
Output:
Roll No : 21
School : St. Xavier's
Marks : 88
Page 19 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
1.15 Constants
Definition: A constant is a fixed value that does not change during the execution of a program. Unlike a
variable, once a constant is set, it cannot be modified.
class ConstantDemo
{
public static void main(String args[])
{
final double PI = 3.14159; // symbolic constant
final int MAX_MARKS = 100;
double radius = 7;
double area = PI * radius * radius;
Output:
Area of circle = 153.93791
Maximum marks = 100
Page 20 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
Output:
Result = 10.0
(b) Explicit Type Conversion (Narrowing / Type Casting)
This is done manually by the programmer when converting a “larger” data type into a “smaller” one. Since
some information may be lost in this process, the programmer must explicitly write the target type in
parentheses before the value — this is called type casting.
class ExplicitDemo
{
public static void main(String args[])
{
double price = 99.99;
int roundedPrice = (int) price; // explicit
casting; decimal part is lost
Output:
Original price : 99.99
After casting : 99
Page 21 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
class OperatorFormsDemo
{
public static void main(String args[])
{
int a = 8, b = 3;
Output:
Unary (-a) : -8
Binary (a+b) : 11
Ternary : a is greater
Page 22 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
Page 23 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
class IncrDemo
{
public static void main(String args[])
{
int x = 5;
[Link](x++); // prints 5, then x becomes 6
[Link](x); // prints 6
[Link](++x); // x becomes 7, then prints 7
}
}
Output:
5
6
7
Operator Meaning
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
~ Bitwise complement (NOT)
<< Left shift
>> Right shift
(h) instanceof Operator
A special binary operator used to test whether an object is an instance of a particular class (or its subclass).
Returns a boolean value. Syntax: objectName instanceof ClassName
Page 24 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
Operator Associativity: When an expression contains two or more operators of the same precedence,
associativity determines the order (Left-to-Right or Right-to-Left) in which they are evaluated.
class PrecedenceDemo
{
public static void main(String args[])
{
int result = 20 + 5 * 2 - 3;
[Link]("Result = " + result);
}
}
Output:
Result = 27
Page 25 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
class PrintDemo
{
public static void main(String args[])
{
[Link]("Hello ");
[Link]("World"); // no newline, continues on same line
[Link](); // just moves to next line
[Link]("ICSE");
[Link]("Board"); // starts on a fresh line each time
}
}
Output:
Hello World
ICSE
Board
Both methods are overloaded, i.e. they can accept an argument of any data type (int, double, char, boolean,
String, or even an object) and will automatically convert it to its String representation before displaying it.
Example — println() with different data types:
class PrintlnOverload
{
public static void main(String args[])
{
[Link](101); // int
[Link](3.14); // double
[Link]('A'); // char
[Link](true); // boolean
[Link]("Result: " + (5 + 3)); // String concatenation
}
}
Output:
101
3.14
A
true
Result: 8
Page 26 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
Guess Paper – 1
Chapter 1: Revision of Class IX | Max. Marks: 40 | Time: 1 hour
Q15. State the data type and size (in bytes) of: (a) char (b) long (c) boolean (d) double. [2]
int a = 5, b = 2;
[Link](a + b + "Result");
[Link]("Result" + a + b);
[Link](a++ + " " + ++b);
Q20. Write short notes on (any five): Keywords, Identifiers, Literals, final keyword, Unicode, Type casting.
[5]
Page 27 of 28
Sachin Tripathi ICSE Class X – Java: Revision of Class IX
Guess Paper – 2
Chapter 1: Revision of Class IX | Max. Marks: 40 | Time: 1 hour
Q18. Evaluate the following expression step by step, clearly stating the precedence rule applied at each step:
[undefined]
15 % 4 + 3 * 2 – 1
Q19. Write a Java program (class with a main method) that declares an int, a double, a char and a boolean
variable, initialises them with suitable values, and prints all four using println(). Show the expected output.
[5]
Q20. What will be the output of the following code? Explain your reasoning for each line. [5]
int p = 4, q = 4;
[Link](p++ + q);
[Link](p + ++q);
[Link](p + " " + q);
Page 28 of 28