Object Modelling – Entities and Their Behaviour in Java
Introduction to Object Modelling in Java
Java is an Object-Oriented Programming (OOP) language. In OOP, programs are designed by modelling real-world entities as objects.
👉 Object Modelling means representing real-life things inside a program using:
-
Their properties (data)
-
Their behaviour (actions)
Components of Object Modelling
Every object consists of three main components:
1. State (Properties / Attributes)
State represents the data stored in an object.
Examples:
-
Student → Name, Roll Number
-
Car → Color, Speed
In Java → Variables
int roll;
String name;
2. Behaviour (Actions / Functions)
Behaviour represents what the object can do.
Examples:
-
Student → Study, Write Exam
-
Car → Start, Stop
In Java → Methods
void study()
{
System.out.println("Student is studying");
}
3. Identity (Unique Name)
Each object has a unique identity.
Example:
Student s1;
Student s2;
Here:
-
s1 and s2 are different objects.
Steps in Object Modelling
Example → Student
-
Name
-
Roll number
-
Age
-
Study
-
Write exam
class Student
{
int roll;
String name;
void study()
{
System.out.println("Studying...");
}
}
Real-Life Example of Object Modelling
-
Color
-
Speed
-
Start
-
Stop
Java Representation
class Car
{
String color;
int speed;
void start()
{
System.out.println("Car Started");
}
}
Program: Model a Fan Object
Importance of Object Modelling
Object modelling helps in:
- Understanding real-world problems
- Organizing programs properly
- Making code reusable
- Reducing complexity
- Easy debugging
Difference Between Entity and Object
| Entity | Object |
|---|---|
| Real-world thing | Program representation |
| Physical or logical | Software model |
| Example: Car | Object of class Car |
What is a Method in Java?
A method is a block of code that performs a specific task when it is called.
👉 Simply:
A method is a function inside a class.
Real-Life Example
Think of a method like a machine button:
-
Press button → Machine works
-
Call method → Code runs
Why Do We Use Methods?
Methods help to:
- Reduce repetition of code
- Make program easy to understand
- Organize code properly
- Save time and effort
Parts of a Method
- Every method has: Method Name
- Name of the function.
- Return Type
- Type of value returned.
- Parameters (Optional)
- Values passed to method.
Example:
void greet(String name)
-
void → return type
-
greet → method name
-
name → parameter
Creating Objects in BlueJ (Step-by-Step)
Example:
class Student
{
void show()
{
System.out.println("Welcome to BlueJ");
}
}
Click Compile button in BlueJ.
Right-click class → Select new Student() → Press OK.
An object box appears on screen.
Right-click object → Select method → Output appears.
Program: Method and Object Creation
class Student
{
String name;
void input(String n)
{
name = n;
}
void display()
{
System.out.println("Name: " + name);
}
}
In BlueJ:
Create object → Call:
input("Rahul")
display()
Output:
Name: Rahul
Important Points to Remember
- Method must be inside a class
- Object is needed to call non-static methods
- Method name should be meaningful
- Always compile before creating object
Common Errors Students Make
- Forgetting to compile
- Writing method outside class
- Not creating object before calling method
ICSE Exam Important Questions
❓Very Short Questions
-
Define a method.
-
What is an object?
-
What does void mean?
Short Answer Questions
Q. Why do we create objects in Java?
Ans: Objects are created to access class variables and methods.
Practical Question
Q. Write steps to create object in BlueJ.
👉 Write:
-
Compile class
-
Right-click class
-
Select new
-
Call method
Quick Revision Trick
👉 Remember:
Method = Action
Object = User of Action



Good one 👌
ReplyDelete