What is an Object in Java?

image credit-pexels

Hi guys, welcome to the next step in Java programming. This object oriented programming part is essentially, the most important section in the tutorial series. So, let get down to business 🙂 shall we?

In order to understand this “object” thing, I’ll try to give you a little example..

Now, consider a car. We know, it is an object in real life.

Now let’s observe the vehicle closely. What can we see from the outside?… Yes it has a specific colour, number plate and a brand name such as BMW, Toyota, Mustang or whatsoever.

What are the functions of a car?

Most important thing, it can travel from one location to another.

Apart from that, it performs some other functions.

For example, it would play some cool music for you while you are travelling…

and it also turn air bags on immediately during an accident.

Now we can see there are two things related with a usual object.

  • State


  • Behaviour

State is collection of the usual properties that an object has such as the colour of the car in the previous example. Also, it has the behaviour or some specific functions when we interact with it.

Example, giving the music while driving the car. They are much like nouns(state) and verbs(behaviour).

So at this point we can sum up a car object like this;


  1. state :- colour, registration number, brand name…….
  2. behaviour :- start moving when power is given, playing music while travelling, turn air bags on during an accident………..

This is the basic layout of the Car object.

This layout of the object can REALLY be written in some programming language and put in to the computer.

What if we assign real values to these properties?

Based on the Basic layout Car;

Car: “Bob’s car”


  • colour – black
  • registration number – 12-23113xx
  • brand name – BMW
  • ……..

behaviour :-

  • start moving when power is given
  • play “Rihana – Diamonds” song while travelling
  • turn air bags on during an accident
  • ………..

another one;

Car: “Ranjan’s car”


  • colour – red
  • registration number – 21-54741xx
  • brand name – AUDI
  • ……..

behaviour :-

  • start moving when power is given
  • play “Charlie Puth – One Call Away” song while travelling
  • turn air bags on during an accident
  • ………..

Wouldn’t this make any sense? They are like real cars! If you order a real car with these exact same properties, you may get a one in real world having exact same state and behaviour. (Of course, you should have a plenty of money for that:)

In fact, “Bob’s car” and “Ranjan’s car” are Objects in Object Oriented Programming. You just have to assign real values for the state and behaviour of the basic layout to make a unique Object.

There’s another important thing that you should understand.

Have you ever made presentations with MS PowerPoint or some other software like libreOffice Impress..etc? There, you are given nice layouts so that you can use the same layout to make thousands of presentations.

Same logic is applied in here. We don’t rewrite the layout code of the Car.

Instead, we order the computer to make an empty copy of this layout so that we can assign real values for the state and behaviour manually(There’s a method for that in real programming languges).

Otherwise, we may easily get tired of writing the same layout code over and over and over again, before adding the unique features.. Suppose 10000 cars? How hard can it be? 🙁

Likewise we can make thousands of virtual car objects with their own unique features, but they have the same layout.

What I’m trying to explain in this picture: there’s a Class where we write the code manually, targeting to create new Car Objects from it. So, then, we create new Car Objects using the keyword “new“. Each Object we create is unique. Later on, we can modify each one as we want…

Making these kinds of objects virtually in a computer and using them to do various tasks is called Object Oriented Programming (OOP).

Now we can really make use of the objects like this in real world. We can use the above Car layout as the base for some cool car game.

You just have to make a 3D model for the Car layout( It’s much complicated though :P) and then, it will automatically create a copy of the model for every Car object that you create and assign real values like “Bob’s car” or “Ranjan’s car” above.

When you assign the colour “Red” for the state of “Ranjan’s car”, the 3D model would paint red.

Similarly “Bob’s car” would be painted black. That’s what you are actually doing in Car games, not with a chunk of code, but in a beautiful graphical user interface (probably in a 3D garage??).

Also, if you create a database about vehicles, you may use this OOP style to concentrate all the information about a car in a single virtual Car object.

K Here’s the Final Note: what you are doing is,

  1. first you make a basic layout of the state and behaviour of an object, and
  2. then assign real values to the *copies of the layout to make unique objects.
  3. Next, you use these objects to do various tasks.

That’s all!

*actually the concept of the copy is given for the easy understanding of the reader. The values are actually assigned to the variables in the instances of the Class declared for the particular object.

Now let’s have a better idea of this object with a more programming approach in the next tutorial…