0% found this document useful (0 votes)
0 views

chapter1

The document provides an overview of Object-Oriented Programming (OOP) concepts using Java, detailing its characteristics such as encapsulation, inheritance, polymorphism, and abstraction. It highlights the features and advantages of OOP, including code reuse and easier maintenance, and introduces Java as a robust, platform-independent, and object-oriented programming language. Additionally, it includes simple Java programs demonstrating basic functionalities like displaying text and performing arithmetic operations.

Uploaded by

Bijay Sahani
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

chapter1

The document provides an overview of Object-Oriented Programming (OOP) concepts using Java, detailing its characteristics such as encapsulation, inheritance, polymorphism, and abstraction. It highlights the features and advantages of OOP, including code reuse and easier maintenance, and introduces Java as a robust, platform-independent, and object-oriented programming language. Additionally, it includes simple Java programs demonstrating basic functionalities like displaying text and performing arithmetic operations.

Uploaded by

Bijay Sahani
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Object Oriented Programming concept with java

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.

1.2 characteristics of OOP


There are different types of characteristics of OOP. They are:

 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.

1.3 features of OOP


Some key features of OOP are as follows:

 Data is hidden and can’t be accessed by external functions.


 Objects communicate each other through function
 New data and functions can be easily added whenever necessary
 It follows bottom-up approch in program design
 The security features is high due to data hiding concept.

2.4 Important / Advantage of OOP


Some important advantages are as follows:

 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.

The Java language was designed with the following properties:

 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.

1. Simple program to display a “Hello world”

I mport java.io.*;
public class Main
{
public static void main(String[] args)
{
System.out.println("Hello World");
}
}

2. WAP to add two input numbers in java


import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int a,b, s;
Scanner sc = new Scanner(System.in);
a = sc.nextInt();
b = sc.nextInt();
s = a + b;
System.out.println("sum is "+s);
}
}
3. WAP to check your are in teenager or not.
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
int a;
System.out.println("Enter the age");
Scanner sc = new Scanner(System.in);
a = sc.nextInt();
if(a>=13 && a<=19)
{
System.out.println("the person is in teenager");
}
else
System.out.println("the person is not in teenager");
}

You might also like