📢 Join My WhatsApp Channel JavaWithSumit

Get Daily ICSE Java Notes, Programs & Exam Tips 🚀

👉 Join Now

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 

✔ Step 1: Identify the Entity

Example → Student


✔ Step 2: Identify Properties

  • Name

  • Roll number

  • Age


✔ Step 3: Identify Behavior

  • Study

  • Write exam


✔ Step 4: Represent in Java

class Student
{
int roll;
String name;

void study()
{
System.out.println("Studying...");
}
}

Real-Life Example of Object Modelling

Example: Car

Properties:

  • Color

  • Speed

Behaviour:

  • Start

  • Stop


Java Representation

class Car
{
String color;
int speed;

void start()
{
System.out.println("Car Started");
}
}

Program: Model a Fan Object

class Fan
{
String brand;
int speed;

void rotate()
{
System.out.println("Fan is rotating");
}
}

class Main
{
public static void main(String args[])
{
Fan f1 = new Fan();
f1.brand = "Usha";
f1.speed = 3;

f1.rotate();
}
}



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)


✅ Step 1: Write the Class

Example:

class Student
{
void show()
{
System.out.println("Welcome to BlueJ");
}
}

✅ Step 2: Compile the Class

Click Compile button in BlueJ.


✅ Step 3: Create Object

Right-click class → Select new Student() → Press OK.

An object box appears on screen.


✅ Step 4: Call Method

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

  1. Define a method.

  2. What is an object?

  3. 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





Comments

Post a Comment

Popular posts from this blog

Introduction to Object Oriented Programming and Java- ICSE Notes

Introduction to OOP's