Java Programing laungage

Core Java Tutorial

Introduction of Core Java

How To Install JDk and Set of Path

Syntax of java Program

Difference between Java and C/C++

Advantage and Disadvantage of Java

What is Java

Why Java is not Pure Object Oriented Language

Java has Following Features/Characteristics

Limitation of Java Language and Java Internet

Common Misconception about Java

Simple Program of Java

Integrated Development Environment in java

Compile and Run Java Program

Applet and Comments in Java

Tokens in Java

Keywords in Java

Identifier and Variables in Java

Literals/Constants

Data Type in Java

Assignments and Initialization in Java

Operators in Java

Rule of Precedence in Java

Operator on Integer and Separators in Java Programming

Java Control Flow of Statements

If and If-else Selection Statement

Nested If-else and If-else-If Selection Statement

switch case and conditional operator Selection Statement

for and while Loop

do..while and for each Loop

break and labeled break statement

continue and labeled continue statement

return Statement and exit() Method

Escape Sequence for Special Characters and Unicode Code

Constants and Block or Scope

Statement in Java

Conversions between Numeric Types in Java

Import Statement in Java

User Input in Java using Scanner Class

User Input in Java using Console Class

Array in Java

One Dimensional Array

Two Dimensional Array

Two Dimensional Array Program

Command Line Argument in Java

String args Types in Java

Uneven/Jagged array in java

Math Class Function and Constant

Math Class all Function used in a program

Enumerated Types in Java

Object Oriented Programming v/s Procedural Programming

Object Oriented Programming Concepts in Java

Introduction to Class,Object and Method in Java

Class Declaration in Java

Class & Objects in java

Encapsulation in Java

Modifiers/Visibility for a Class or Interrface or member of a Class

Polymorphism in Java

Runtime polymorphism (dynamic binding or method overriding)

adplus-dvertising
Object Oriented Programming Concepts in Java
Previous Home Next

Object means a real word entity such as pen, chair, table etc. Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects. Object-oriented programming (OOP) is programming using "objects" to develop computer programs. There are three main features of oops objects, encapsulation, inheritance, and polymorphism, have data (fields) and behavior (methods) and do the work in an object-oriented program. OOps is a programming paradigm that uses "objects" to design applications and computer program. The Simula programming language was the first to introduce the concepts underlying object-oriented programming (objects, classes, subclasses, virtual methods, coroutines, garbage collection and discrete event simulation) as a superset of Algol. Smalltalk was the first programming language to be called "object-oriented".

Some of the essential elements of the object oriented programming:

  1. Object
  2. Class
  3. Abstraction
  4. Three OOps principles
    1. Encapsulation
    2. Inheritance
    3. Polymorphism
  5. Message
  6. Persistence
  7. Genericity
  8. Composition / Aggregation
  1. Object
  2. Objects are the real world entities. Entities are something which has extension in real world. If we consider the real-world we can find many objects around us, Cars, Dogs, Humans, etc. All these objects have a state and behavior. Software objects also have a state and behavior. A software object's state is stored in fields and behavior is shown via methods.

    Any entity that has state and behavior is known as an object. For example: chair, pen, table, keyboard, bike etc. It can be physical and logical.

    An object has three characteristics:

    1. State:
    2. represents data (value) of an object.

    3. Behavior:
    4. (Methods / Function / Operatoins)represents the behavior (functionality) of an object such as deposit, withdraw etc.

    5. Identity:
    6. Object identity is typically implemented via a unique ID. The value of the ID is not visible to the external user. But,it is used internally by the JVM to identify each object uniquely.

      Example: Pen is an object. Its name is Reynolds, color is white etc. known as its state. It is used to write, so writing is its behavior.

  3. Class
  4. Class is a collection of similar type of object. A class is a blue print for the object. That blueprint describes the each object behaviors and state variable. Collection of objects is called class. It is a logical entity.

    A class represent a category of objects by abstracting their properties and behaviour. A class can be thought of as blueprint for creating objects. An object has the properties and behaviour defined by its class. The class can be thought of as a user-defined data type and object as a variable/ instance of the data type represented by the class.

    The properites/attribute of an object are defined by data members/ fields in java. A data member/field in a class is a variable that can hold data. The behaviors / operations of an object are defined using methods in java. Both data members and method are reffered to as members of the class.

  5. Abstraction
  6. Abstraction is a process of hiding the implementation details and showing only functionality to the user. It shows only important things to the user and hides the internal details for example sending sms, you just type the text and send the message. You don't know the internal processing about the message delivery.

  7. Three OOps principles
    1. Inheritance
    2. Inheritance is a process by which features and proprieties of one class ( called super class ) is transferred to another class (called as sub class ) without changing the super class and adding new feature in sub class. It is also called as code reusability. It save the programmer's time. Inheritance defines relationships among classes in an object-oriented language.

      The idea behind inheritance in java is that you can create new classes that are built upon existing classes. When you inherit from an existing class, you can reuse methods and fields of parent class, and you can add new methods and fields also.

      Inheritance represents the IS-A relationship, also known as parent-child relationship.

    3. Polymorphism
    4. When two or more same statements having different meaning then it is called as polymorphism. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. Polymorphism in java is a concept by which we can perform a single action by different ways. Polymorphism is derived from 2 greek words: poly and morphs. The word "poly" means many and "morphs" means forms. There are two types of polymorphism in java: compile time polymorphism and runtime polymorphism. We can perform polymorphism in java by method overloading and method overriding.

    5. Encapsulation
    6. Encapsulation is a bundling of member variable and member method together in a class as a single entity is known as called as encapsulation. Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods. If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class. For this reason, encapsulation is also referred to as data hiding. for example capsule i.e. mixed of several medicines. Data Hiding is declaring a member has private we can hide them from external objects.

  8. Message, Method and Object Interaction
  9. Java is a pure object-oriented programming model, objects interact by sending messages to each other. In the Java model, objects interact by invoking each other's methods. Methods provide access to the information contained in an object. The type of access varies depending on the method. When an object receives a message, the object invokes a method to process the message. The method may change the state of the object, return information contained in the object .

  10. Persistence
  11. Persistence is the term used to refer to the situation where the objects data is stored even after the object is destroyed or the application is closed. Persistence is implemented using Serialization where the data of the object is serialized into flat files and stored into the system. These files can be de-serialized to form the objects by using de-serialization.

  12. Genericity
  13. The Java Generics programming is introduced in JDK 5 to deal with type-safe objects. Before generics, we can store any type of objects in collection i.e. non-generic. Now generics, forces the java programmer to store specific type of objects.

  14. Composition / Aggregation
  15. Aggregation:It is a specialized form of Association where all object have their own lifecycle but there is ownership. This represents “whole-part or a-part-of” relationship. This is represented by a hollow diamond followed by a line.

    Example : relationship between Department and Teacher. A Teacher may belongs to multiple departments. Hence Teacher is a part of multiple departments. But if we delete a Department, Teacher Object will not destroy.

    Composition:It is a specialized form of Aggregation. It is a strong type of Aggregation. In this relationship child objects does not have their lifecycle without Parent object. If a parent object is deleted, all its child objects will also be deleted. This represents “death” relationship. This is represented by a solid diamond followed by a line.

    Example:relationship between Questions and options. Single questions can have multiple options and option cannot belong to multiple questions. If we delete questions options will be automatically deleted.

Previous Home Next