Our social:

Wednesday, August 17, 2016

Objects and Classes in Java – The must know concepts-Best Education Service

objects in java

[Tutorial 7] :

In this tutorial ,You will learn about the basic foundations of Java i.e Classes and Objects
As you know that Java is an ” Object Oriented Language  , So we must understand what objects in Java are.  Apart from knowing what object are , You will also learn how to create objects and how to make use of them.
This tutorial will also make you build superb concepts about Classes in Java.
PS – This is completely a theoretical tutorial and does not include anything related to programming. These are the basic concepts which you must know in  order to learn other concepts.
After reading this article , you will be able to tackle the following questions with ease :-
  • What are objects ?
  • What are classes in Java ? 
  • What is Abstraction  ?
  • What is encapsulation ? 
  • How to implement objects in software terms ? 
  • Why is class known as Object Factory ? 
And much more 😉
So , Let us Proceed to the mainstream of this article.

What are Objects ?

An object can be thought of as an entity having some specific characteristics , specific identity, and specific behaviour.
For example – A car is an object or a chair is an object.
Now let us take the example of the car object. According to the definition ,  We understand that an object must have some characteristics and some behaviour.
In case of car ,
  • Characteristics  – The characteristics of the object car is that “It is blue in colour” or “It is somewhat square shaped “
  • Behaviour – The behaviour includes that “It can move” , “It can blow horn” , “It can turn around” etc.
  • Identity – The car is given a nameplate which gives it an identity.
Let us take another example of an “Orange” fruit.
In case of an orange   :-
  • Characteristics  – The characteristics of the object orange is that “It is orange in colour” or “It is round “
  • Behaviour – The behaviour includes that “It is citrus” , “It tastes sweet” , “It even tastes sour” etc.
Hope , You are clear about what are objects.
But , The objects that we are talking about are the “real world objects” which now needs to be implemented in software terms. Right ?  So , Let us see , How these Objects are implemented in software terms :-

How are objects implemented in Software terms ?

The real world objects need to be implemented in Software terms.
This is how these objects are implemented in software terms :-
  • Characteristics / Attributes / State of the object are implemented through members variables or data items of the object.
    In Java , The characteristics of the object are implemented through member variables or the data items of the object.
  • Behaviour is implemented through member functions called methods. The functions that we allot to the object, implement its behaviour.
  • Data and Methods are encapsulated into a single unit called class to give it an identity.
If you do now know the meaning of the word “encapsulation” , you need not worry , read the article till last and you will find it.
So , In this way , the real world objects are implemented in software terms.
It seems that you are now well aware of Objects in Java. Let us now proceed to other topics such as Abstraction , Encapsulation etc. 😉

What is abstraction ? 

At times , We have a lot of data and we need do not need all that data. We only need a small fragment of it ( Which is important ) . In that case , We need to abstract that small piece of data from  the given data. For this , we use abstraction .
Let us see , What the definition says :-
The act of representing essential features without including backgroud details and explanations is called abstraction. 
Let us take an example :-
  • Switchboard  –  In the case of a switchboard , we are only concerned about pressing switches and make the fans glow and we are not at all bothered to know what is inside the board , the wiring etc. So , The switches of a switchboard are the abstraction in this case.
 Abstraction has not much to do with programming in core java but you must know these concepts for learning advanced Java. 

What is encapsulation  ?

Suppose , You have abstracted a piece of data from a bigger fragment and now you need to wrap it up into a single entity. Right ? In order to do that , we make use of Encapsulation.Encapsulation is defined as :-
The act of wrapping up of Data and Instructions into a single unit called  “class” is called Encapsulation. 
NOTE – In the above definition ,  the word “class” is of utmost importance because, in software terms , the data and instructions are wrapped up into the “CLASS”
Well, We can have an example for encapsulation also 😀
  • A school student – The real world belongings of the student can be many things  such as her name , her parent’s name , her roll number , her class , her hobbies , her parent’s profession , her locality , her interests , her awards , her marks etc.
    But if we want to know about her result :-
The abstraction will be her roll number , her class and her marks.
This abstraction will be into put into a single file named “Result” and this is Encapsulation. 
Now you don’t know what an object is ? But you still are not aware about classes in Java. Read further and you will come to know 😀

What is a class ?

Everything , including you, have a name. Right ? So , Why not our program. I mean we need to give an identity to our program also and for that we use a class name.
The definition of class is :-
A class is nothing but a blueprint or a template for creating different objects which defines its properties and behaviors. Java class objects exhibit the properties and behaviors defined by its class. A class can contain fields and methods to describe the behavior of an object.
The two important questions related to class which are frequently asked :-
  • How is a class related to an object ? 
    A class represents a set of objects that share common characteristics and behaviour.
  • Why to we need a class ? 
    We need a class to define objects as objects are instances of class.

Why is class known as object factory ?

If you would have ever been to a factory, you must have seen that a factory has a blueprint based on which , it produces replicas of blueprint known as products.
In case of  Object Oriented Programming , the factory is class and the products that are made by the factory are called “objects”
A class contains all the statements needed to create and object , its attributes as well as the statements to describe the operations that the object will be able to perform.
Having a class defined , we can create as many objects as needed. All these objects materialise the abstraction represented by the class. All instance created with  a given class will have the same structure and behaviour. They will only differ regarding their state.


Post a Comment

Hello Every One thanks For Visit My site You Can Suggest any Idea About site And Related Education Information Provide me Its Best Content For you am Include in this Site And feel free contact And email now I hope This site very help full you