Jump to content

1. Introduction to Java and O.O.P.

Guest Prayaas Aggarwal

Recommended Posts

Guest Prayaas Aggarwal


Object Oriented Programming is the core of Java. Before writing an app in Java, you'll first need to know the basic principles of it. You'll know what is  an object, a class, how they are related, and how different objects communicate, and will thus be able to understand and create your own programs in Java, after having read this tutorial. This thread aims to describing the concepts behind Object Oriented Programming (O.O.P.) This thread, is the first part of the tutorial. For the second part, head on to the next thread.

Object Oriented Programming Concepts

All computer programs consist of two types of elements, code and data. A program can be conceptually organized either around it's code, or around it's data. The first approach is called a process-oriented model. Procedural languages like C, employ this model. The second approach is called object-oriented model. It organizes the program around it's data, that constitutes the objects, and a set of interfaces to the data.


It's an important feature of OOP. Technically, humans too use it, to manage complexity. For example, we do not think of our computer as a set of 1000 individual parts. We regard it as a single object. It has it's own unique behaviour. The program can be transformed by abstraction into component objects in a hierarchical manner, just like our computer can be further thought of as a screen, keyboard, and all. a sequence of process steps can become a collection of messages between the objects. Thus, each object will define its own behaviour.

What is an Object?

Any 'thing' is an object, which has a state and a behaviour. For example, let's say that a dog is an object. It has it's state that is, name, colour and breed, and it's behaviour, that is barking, fetching objects, or wagging it's tail. Software objects have been modelled after real-life objects and they too, have a state and a behaviour. The state is maintained in one or more variables. An 'identifier' is a unique value which can be used to name variables. The behaviour of the software object, is implemented by it's methods. A method is a function or a subroutine assosciated with the object. Things got too complicated? Don't worry! I have an illustration of an object to make things easier.

Posted Image

Still didn't get the hold of it? I know. Check out the example below.

Let's say, the object is a real-life television. It will have variables to describe the TV's current state. The variables are, Volume=12, and Channel=5. These variables are called instance variables, and a particular object is called an instance. The TV has been modelled as a software object by me, for better understanding. Check out the illustration below, which will make things much clear.

[img width=560 height=420] 2.png

Things should become much clearer now. 12 and 5 are instance variables for Volume, and Channel respectively, and ChangeVolume Method and ChangeChannel Method are instance methods, because they modify the behaviour of a particular TV instance.

When an object is mapped into software representation, it consists of 2 parts:

1. Data referred to as 'attributes'.

2. Processes that may correctly change the data structure, referred to as functions, or methods.

Example - A Person object would have the following attributes:

1. Name

2. Age

3. Weight

The methods would be:

1. set_name

2. get_name

3. set_age

4. get_age

and so on..

Check Your Progress

1. What is an Object? What role does it play in programming Java?

2. What are the types of elements in a computer program?

3. What is a method, what does it affect and how?

If you can answer all three fairly good, then proceed, otherwise read this again and see.

This concludes the first part of the tutorial. Check out the next post for further information. :)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...