Monday, February 5, 2018

Object-Oriented Programming In Java


Object-Oriented Programming:-

object-oriented programming(OOP) is at the core of Java.In fact,all Java programs are to at least some extent object-oriented. OOP is so integral to Java that it is understand its basic principles before you begin writing even simple java programs.

All computer programs consist of two elements: code and data.Furthermore,a program can be conceptually organized around its code,or its data.That is, some programs are written around “what is happening” and others are written around “who is being affected.” These are the two paradigms that govern how a program is constructed. The first way is called the process-oriented model.

To manage increasing complexity,the second approach,called object-oriented programming.Object-oriented programming organize a program around its data(that is object) and  set of well defined interfaces to that data.An object-oriented program can be characterized as data controlling access to code.

Abstraction:-


An essential element of object-oriented programming is abstraction.Humans manage complexity through abstraction.For example,people do not think of a car as a set of tens thousands of individual parts.They think it is well defined object with its own unique behavior.This abstraction allows people to use a car to drive to the grocery store without being overwhelmed by the complexity of the parts that form the car. They can ignore the details of how the engine, transmission, and braking systems work. Instead, they are free to utilize the object as a whole.

A powerful way to manage abstraction is through the use of hierarchical classifications.This allow you to layer the semantics of complex systems,breaking them into more manageable pieces.From the outside, the car is single object.once inside,you see that the car consist of several subsystems: streening, breakes, sound system,seat belts,heating,cellular phone,
and so on. In turn,each of subsystems is made of more specialized units. For instance,the second system consist of a radio,a CD player ,and a tape or MP3 player.
The point is that you manage the complexity of the car through the use of hierarchical abstractions.

Hierarchical abstractions of complex systems can also be applied to computer programs.The data from a traditional process-oriented program can be transformed by abstraction into its component objects. A sequence of process steps can become a collection of messages between these objects. Thus, each of these objects describes its own unique behavior. You can treat these objects as concrete entities that respond to messages telling them to do something.

All object oriented programming languages provide mechanisms that help you implement the object oriented model. They are encapsulation,inheritance,and polymorphism.
 let's take a look at these concepts now.

Encapsulation:-

Encapsulation is the mechanisms that binds together code and the data it manipulates,and keeps both safe from outside interference and misuse. One way to think about encapsulation
ia as a protective wrapper that prevents the code and data from being arbitrarily accessed by other code defined outside the wrapper.

Inheritance:-


Inheritance is the process by which one object acquires the properties of another object. This is important because it supports the hierarchical classification. As mentioned earlier,most knowledge is made manageable hierarchical(that is top-down) classifications.

Polymorphism:-


Polymorphism(from Greek,meaning "Many forms") is a feature that allows one interface to be used for a general class of actions. The specific action is determined bye the exact nature of the situation. Consider a stack(Which is a last-in, first -out list). You might have a program that requires three types of stacks. One Stack is used for integer values,one for floating-point values,and one for characters. The algorithm that implements each stack is the same,even though the data being stored differs. In a non-object-oriented language,you would be required to create three different sets of stack routines, with each set using different names. However, because of polymorphism, in Java you can specify a general set of stack routines that all share the same names.

More generally, the concept of polymorphism is often expressed by the phrase “one interface, multiple methods.” This means that it is possible to design a generic interface to a group of related activities. This helps reduce complexity by allowing the same interface to be used to specify a general class of action. It is the compiler’s job to select the specific action (that is, method) as it applies to each situation. You, the programmer, do not need to make this selection manually. You need only remember and utilize the general interface.

First Simple Helloworld Program in java
Data Types in java  

No comments:

Post a Comment

Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...