chapter1
chapter1
1.1 Introduction
Object oriented programming is a programming language based on the concept of object, which
may contain data or objects, rather than functions and logic. . It utilizes several techniques including
modularity, polymorphism, inheritance, and encapsulation. The fundamental idea behind object-
oriented programming is to combine data and function into a single unit, such a unit is called an object.
An object’s function is called member function and the data are only accessible through a member
function. An object can be defined as a data field that has unique attributes and behavior. Programming
languages like in C++, Java, JavaScript and objective-C are object-oriented programming languages.
Object: In OOPs, combine both data and function in a single entity. This entity is also called
object. So, a particular instance of a class is known as an object. An object has some
properties, behaviors and relationships. It represents an entity that can store data and its
associated functions.
Class: A class is a collection or group of similar objects that have same properties,
common behavior and relationships. Each class describes a set of individual objects. The
concept of class leads to the reusability of programming code. A code is written for an
object of the class can be reused by another object of the class.
Encapsulation:
Encapsulation is the process that allows selective hiding data and functions in a class. It
is the wrapping up of data and associated functions in a single unit in such a way so that,
only essential details are exposed and rest remain hidden. Encapsulation groups all the
pieces of an object into a neat package. It avoids undesired side effects of the member
data when is it defined out the class and also protects the intentional misuse of
important data. Encapsulation ensures that only authorized functions access the
relevant data thereby maintaining against unauthorized access to ensure data safety.
Inheritance:
It is process by which a class can be derived from a base class with all features of base
class and some of its own. The old class is known as base class or super class (Parent
class) and new class is known as derived class or child class. Sub class or derived class
inherits all the instance variable and method define by super class and it adds its own
unique elements. It is intended to help reuse to share the same code, leading to a
reduction in code size and an increase in functionality. These increase code reusability.
Polymorphism: Polymorphism enables the same function to behave differently on
different classes. It is the concept that supports the capability of an object of a class to
behave differently in response to a message or action. It is a property by which the same
message can be sent to objects of several different classes, and each object can respond
in a different way depending on its classes. It expresses how to carry out different
processing steps using the same function name and the ability of a single operator to
perform more than one.
Abstraction: Data abstraction is the process of identifying properties and methods
related to a particular entity as relevant to the application. Abstraction is a process
where you show only “relevant” data and “hide” unnecessary details of an object from
the user. It is the ability to represent data at very conceptual level without any details.
Code reuse and Recyclying : object created for OOP are easily reused in other programs.
Encapsulation: Objects has the ability to hide certain part of themselves from programmers or
outside clients.
Design benefits: Large program are very difficult to write. OOPs force designer to go through an
extensive planning phase, which makes for better design with less false.
Software maintenance: OOP is much easier to modify and maintains.
2.5 Introduction to java programming
Java is a programming language and platform. It is also high level, robust, secured and OOP
language. Java programming is case sensitive. Java was developed by James Gosling from Sun
Microsystems in 1995 as an object-oriented language for general purpose business applications and for
interactive, Web-based internet applications.
Platform independent: Java programming uses the Java virtual machine as abstraction and do
not access the operating system directly. This makes java programs highly portable. A java
program can run unmodified on all supported platforms, eg; Windows or Linux.
Object-oriented programming language: Except the primitive or basic data types, all elements
in Java are objects.
Automatic memory management: java manages the memory allocation and de-allocation for
creating new objects. The program does not have direct access to the memory. The so-called
garbage collector automatically deletes objects to which no active pointer exists.
Interpreted and compiled language: Java source code is transferred into the bytecode format
which does not depend on the target platform. These bytecode instructions will be interpreted
by the Java Virtual Machine (JVM). The JVM contains Hotspot-compiler which translate
bytecode instructions into native code instructions.
Strongly-typed programming language: Java is strongly-typed, e.g. , the types of the used
variables must be pre-defined and conversion to other objects is relatively strict.
I mport java.io.*;
public class Main
{
public static void main(String[] args)
{
System.out.println("Hello World");
}
}