It2EDU

Sunday, December 25, 2016









Object Oriented Programming in Java:






Oops is the most powerful technology. Expansion of oop is object oriented programming.





The main components of object oriented technology are object & classes,
data abstraction, Encapsulation, inheritance and polymorphism.





Object:


Object oriented means everything is centered on the concept of object.
Main idea behind oops is to combine both data and its functions that operate on
the data into a single unit called object.


Object is a combination of data and its functionality. Objects can
interact without having to know details of each other data or functions. In
definition an object is a software bundle of variables and related methods. A
real world object has state and behavior.





Let us take an example cars have state (current gear, speed, front
wheels) behavior (braking, speed, change gear) etc. Generally objects maintain
its state one or more variables.





Variable: A variable is a symbol; it holds different values at
different instances or times.





Class:


So many objects are similar in behavior & its state. These are all
grouped together called class. In definition A class is a blueprint or
prototype that defines the variables & the methods common to all objects of
a certain kind.





Abstraction:


Abstraction refers to the act of the representing essential features
without including the background detests and distinguish objects or functions
from other object or functions. Classes are defined as a set of attributes and
functions to operate on these attributes. In case of structural programming
functional abstraction was provided by telling which task is performed by
function and hiding how that the tasks are performed. In object oriented
programming programmers use data abstraction.







Encapsulation:


Encapsulation is the wrapping up of data and functions into a single
unit is known as encapsulation. This is one of the most powerful features of
object oriented approach. The data is restricted from outside world and it is
not directly accessible to the outside world and only the functions which are
wrapped in the class can access it. Outside world can have access to the
functions these functions internally access the data.


 


Data
Hiding:


 


If there is any need of changing / modify data of any object user must
know which function is exactly doing the job to interact with the corresponding
data. This insulation of data from direct access by the program is known as
data hiding. 





Inheritance:
 


Inheritance is an ability to derive new
classes from existing classes. A derived class is known as subclass which
inherits the instance variables and methods of the super class or base class,
and can add some new instance variables and methods.









Polymorphism:


Polymorphism is the
ability of an object to take on many forms. The most common use of
polymorphism in OOP occurs
when a parent class reference is used to refer to a child class
object. Polymorphism
allows one name to be used for several related but slightly different purposes.
The purpose of polymorphism is to let one name be used to specify a general
class of action. Method overloading is one kind of polymorphism. We have
already dealt with this type of polymorphism. The other type of polymorphism simplifies
the syntax of performing the same operation with the hierarchy of classes.























When a Java program is
compiled it is converted to byte code which is then executed by the Java
interpreter by translating the byte code into machine instructions. Java
interpreter is part of Java runtime environment.  Byte code is an intermediate code independent
of any machine and any operating system. 
Program in Java run time environment, which is used to interpret byte
code, is called Java Virtual Machine (JVM). 
The Java compiler reads Java language source files, translates the
source into Java byte codes, and places the byte codes into class files. 





Any machine for which Java
interpreter is available can execute this byte code. That’s why Java is called Machine
independent and Architecture neutral
. Below Figure shows that Java
compiler is accepting a Java program and producing its byte code. This byte code
can be executed on any operating system (Window-98, Macintosh, Linux etc.) running
on any machine with suitable Java interpreter of that machine. The JVM plays
the main role to making Java portable. It provides a layer of abstraction
between the compiled Java program and the hardware platform and operating system. The JVM is
central to Java’s portability because compiled Java programs run on the JVM,
independent of whatever hardware is used.







java virtual machine
Java Virtual Machine