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

Unit I

The document outlines the syllabus for a course on Object Oriented Programming (OOP) with a focus on Java, covering topics such as the introduction to OOP, differences between procedural and object-oriented programming, and key features of Java. It discusses the advantages of OOP, including encapsulation, inheritance, and polymorphism, as well as the history and features of Java as a programming language. The document also compares procedural programming with object-oriented programming, highlighting the benefits of OOP in terms of security, code reusability, and handling complex problems.

Uploaded by

sudikshanarawade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Unit I

The document outlines the syllabus for a course on Object Oriented Programming (OOP) with a focus on Java, covering topics such as the introduction to OOP, differences between procedural and object-oriented programming, and key features of Java. It discusses the advantages of OOP, including encapsulation, inheritance, and polymorphism, as well as the history and features of Java as a programming language. The document also compares procedural programming with object-oriented programming, highlighting the benefits of OOP in terms of security, code reusability, and handling complex problems.

Uploaded by

sudikshanarawade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

SY BTech

AIDS - Semester III


Course Code: AID203
Course: Object Oriented Programming

OOP’s - UNIT I

Submitted by : A R Kothimbire
Department of Emerging Science and Technology
Syllabus – Unit I
✓ Introduction to OOP
✓ JAVA Need of Object-Oriented Programming
(OOP)
✓ Procedure Oriented Programming (POP) Versus
Object Oriented Programming (OOP)
✓ Features of Object Oriented Paradigm
✓ History of Java
✓ Features of Java
✓ Difference between Java, C and C++
✓ Java Development Kit (JDK)
What are procedural languages ?
 FORTRAN, ALGOL, COBOL, BASIC, Pascal, C and similar languages are
procedural languages
 A program in a procedural language is a list of instructions.
 Example :Get some input, add these numbers, divide by six, display that output.
 A procedural program is divided into functions, and (ideally, at least) each
function has a clearly defined purpose and a clearly defined interface to the other
functions in the program.
 When programs become larger, a single list of instructions becomes unwieldy
 The term function is used in C++ and C. In other languages the same concept
may be referred to as a subroutine, a subprogram, or a procedure.
 As programs grow ever larger and more complex, The project is too complex, the
schedule slips, more programmers are added, complexity increases, costs
skyrocket, the schedule slips further, and disaster ensues.
JAVA Need of Object-Oriented Programming (OOP) or
Disadvantages of Procedural language
 1.Global and Local Variables:
 there are two kinds of data. Local data is hidden inside a function,
and is used by the function. Local data is closely related to its
function and is safe from modification by other functions.
 Global data can be accessed by any function in the program.
 In a large program, there are many functions and many global data
items.
 The problem with the procedural is that this leads to an larger
number of connections between functions and data, as shown in
Figure.
 This large number of connections causes problems in several ways.
First, it makes a program’s structure difficult to conceptualize.
Second, it makes the program difficult to modify.
 A change made in a global data item results in rewriting all the
functions that access that item.
Continued…..
 2.Real World Modeling - Difficult to relate to real-world objects.
 The second and more important problem with the procedural is that its
arrangement of separate data and functions does a poor job of modeling
things in the real world. In the physical world we deal with objects such
as people and cars. Such objects aren’t like data and they aren’t like
functions. Complex real world objects have both attributes and behavior.
• 3. The code reusability feature is not present in procedural-oriented
programming. We have to rewrite the same programming code many
times.
• 4. We can not perform operations like encapsulation, inheritance,
abstraction.
Introduction to OOP’s?
 OOP stands for Object-Oriented Programming.
 Procedural programming is about writing procedures or methods that perform
operations on the data.
 object-oriented programming is about creating objects that contain both data and
methods.
 Advantages of OOP’s over Procedural:
❖ OOP is faster and easier to execute.
❖ OOP provides a clear structure for the programs.
❖ OOP helps to keep the Java code DRY "Don't Repeat Yourself", and makes the
code easier to maintain, modify and debug.
❖ OOP makes it possible to create full reusable applications with less code and
shorter development time.
Java - What are Classes and Objects?
 Classes and objects are the two main aspects of object-
oriented programming.
 Look at the following illustration to see the difference
between class and objects:

class objects
Fruit Apple
Banana
Mango

class objects
Car Volvo
Audi
Toyota
The Object Oriented Approach
 The fundamental idea behind object oriented languages is to
combine into a single unit both data and the functions that
operate on that data. Such a unit is called an object.
 An object’s functions, called member functions in C++, typically
provide the only way to access its data. If you want to read a
data item in an object, you call a member function in the object.
It will access the data and return the value to you. You can’t
access the data directly.
 The data is hidden, so it is safe. Data and its functions are said
to be encapsulated into a single entity. Data encapsulation and
data hiding are key terms in the description of object-oriented
languages.
 If you want to modify the data in an object, you know exactly
what functions interact with it. The member functions in the
object. No other functions can access the data. This simplifies
writing, debugging, and maintaining the program.
 A C++ program typically consists of a number of objects, which
communicate with each other by calling one another’s member
functions. The organization of program is shown in Figure.
Features of Object Oriented Paradigm…
 Class
 Objects
 Data Abstraction
 Encapsulation
 Inheritance
 Polymorphism
 Dynamic Binding
 Message Passing
Classes and objects in OOP’s
 Class is not a real-world entity. It is just a template or blueprint or prototype from which objects are
created.
 The compiler does not allocate memory whenever you define a class.
 Class is a group of variables of different data types and a group of methods.
 A Class in Java can contain: Data member, Method, Constructor, Nested Class
 An object in Java is real-life entities.
 Objects are the instances of a class that are created to use the attributes and methods of a class.
 A typical Java program creates many objects, which interact by invoking methods.
 An object consists of :
1. State: It is represented by attributes of an object. It also reflects the properties of an object.
2. Behavior: It is represented by the methods of an object. It also reflects the response of an object with
other objects.
3. Identity: It gives a unique name to an object and enables one object to interact with other objects.
Data Abstraction…
 Abstraction is to remove some characteristics from something to reduce it to a smaller set Class.
 In real life, like when you toggle a switch, it simply turns on or off the lights. Here, we only know the
functionality of the switch, but we don’t know its internal implementation, like how it works.
 Object Oriented Programming abstraction exposes only the essential information of an object to the
user and hides the other details.
 How to implement abstraction?
• by using classes that group the data members and function together.
• Inside classes, you can choose the access specifiers like Private, Protected and Public
• for its members
• Access specifiers tell how members are visible to outside world..
• We can also create header files containing functions.
 Advantages of Abstraction
 The advantages of abstraction are as follows:
▪ It enables code reuse by avoiding code duplication.
▪ It enhances software security by making only necessary information available to the users and hiding
the complex ones.
Encapsulation…
 Encapsulation means enclosing the data/variables and the methods for
manipulating the data into a single entity called a class.
 It helps to hide the internal implementation of the functions.
 Example:
 You can have some private variables in a class that you can't access
outside the class for security reasons. Now, to read or change the value
of this variable, you can define public functions in the class which will
perform the read or writes operations.
Inheritance….
 Inheritance is one of the most important features of object
oriented programming
 It allows a class to inherit the properties and methods of
another class called the parent class, the base class, or the
super-class.
 The class that inherits is called the child class or sub-class.
 It helps to avoid duplication of codes by allowing code reuse
as you need not define the same methods and properties
present in a super-class in the sub-classes again.
 The sub-class can simply inherit them.

 Example:
 You can have a parent class called “Shape” and other classes
like Square, Circle, Rectangle, etc. Since all these are also
shapes, they will have all the properties of a shape so that they
Polymorphism….
 The word polymorphism means to have many
forms.
 So, by using polymorphism, you can add
different meanings to a single component.
 Example:
 There are there function with same name as
findArea() inside the Shape class, but have
different attributes.
Dynamic Binding….
 Dynamic binding takes place during run time based on the
type of object. Since it is delayed till the run time, it is also
called late binding or runtime binding. When the compiler
cannot determine all the information required to resolve a
function call during compile time, these function calls are not
bound until run time.
Message Passing….
 Message Passing refers to the process of passing a message,
or data, between different objects or components in a
program. This can be done in many ways, such as function
calls, events, or inter-process communication. The specific
implementation of message passing will depend on the
program's design and the system's needs.
Procedure Oriented Programming (POP) Versus Object Oriented Programming (OOP)

On the basis of Procedural Programming Object-oriented programming

Definition It is a programming language that is derived from Object-oriented programming is a computer programming design
structure programming and based upon the concept of philosophy or methodology that organizes/ models software design
calling procedures. It follows a step-by-step approach in around data or objects rather than functions and logic.
order to break down a task into a set of variables and
routines via a sequence of instructions.
Security It is less secure than OOPs. Data hiding is possible in object-oriented programming due to
abstraction. So, it is more secure than procedural programming.
Approach It follows a top-down approach. It follows a bottom-up approach.

Data movement In procedural programming, data moves freely within In OOP, objects can move and communicate with each other via
the system from one function to another. member functions.
Orientation It is structure/procedure-oriented. It is object-oriented.

Access modifiers There are no access modifiers in procedural The access modifiers in OOP are named as private, public, and
programming. protected.
Inheritance Procedural programming does not have the concept of There is a feature of inheritance in object-oriented programming.
inheritance.
Code reusability There is no code reusability present in procedural It offers code reusability by using the feature of inheritance.
programming.
Continued……
Overloading Overloading is not possible in procedural In OOP, there is a concept of function
programming. overloading and operator overloading.
Importance It gives importance to functions over data. It gives importance to data over functions.

Virtual class In procedural programming, there are no In OOP, there is an appearance of virtual classes
virtual classes. in inheritance.
Complex It is not appropriate for complex problems. It is appropriate for complex problems.
problems
Data hiding There is not any proper way for data hiding. There is a possibility of data hiding.

Program In Procedural programming, a program is In OOP, a program is divided into small parts that
division divided into small programs that are referred to are referred to as objects.
as functions.

Examples Examples of Procedural programming include The examples of object-oriented programming are
C, Fortran, Pascal, and VB. -
.NET, C#, Python, Java, VB.NET, and C++.
History of Java….
 Java is one of the most popular programming languages.
 It was created by James Gosling and Patrick Naughton, employees of Sun Microsystems,
with support from Bill Joy, co-founder of Sun Microsystems.
 The project was born in 1991, behind the scenes of a Sun Microsystems team, when three
engineers, James Gosling, Mike Sheridan, and Patrick Naughton sought to design a
language applicable to small electrical devices.
 Soon after, they launched the Green Project to study the impact of convergence between
digitally controlled home appliances and computers.
 Using a syntax similar to that of C++, they made a digital remote control, equipped with a
graphic and animated touch screen. The fruit of several months of intense research, this
remote control had the fantastic feature of controlling a whole living room equipment. It
was programmed in a new language, completely independent of the processor it was
running on, making the remote one-of-a-kind.
 Ultimately, it was James Gosling, one of the members of the Green Project, who originated
this new language, which he called Oak.
 Afterward, the project gained ground when American cable operators joined the project.
Oak then became FirstPerson. Unfortunately, the FirstPerson project had no commercial
success, as it was certainly too far ahead of the industry, whose priority was, above all,
profitability.
 In 1993, the HTTP protocol and the Mosaic browser arrived, which was a crucial event
for the project. During this time, the team realized that the Internet would be the ideal
network to position their product.
 Then, in 1995, James Gosling unveiled a browser called WebRunner that was capable of
showing HTML content mixed with Applets. Things took off from there. First,
WebRunner became HotJava, then java.sun.com officially opened to the public.
 Eventually, the name of this technology would become “Java” (meaning “coffee” in
American slang), in honor of the programmer’s favorite drink, namely coffee, part of the
production of which comes from the island of Java.
 It was then that Sun and Netscape announced their desire to integrate this new
technology into their browsers, which definitively launched the language. The versions
would then follow one another from version 1 in 1996 to version 17 in 2021.

 Sun officially presented the Java language at SunWorld on May 23, 1995.
 Then, in 2009, the Oracle company bought the Sun company, which explains why the
language now belongs to Oracle.
Features of Java
 Object Oriented  Architecture-neutral : Java compiler generates
an architecture-neutral object file format,
 In Java, everything is an Object. Java can be which makes the compiled code executable on
easily extended since it is based on the Object many processors, with the presence of Java
model. runtime system. Being architecture-neutral and
 Simple having no implementation dependent aspects of
the specification makes Java portable. The
 Platform Independent
compiler in Java is written in ANSI C with a
 Unlike many other programming languages clean portability boundary, which is a POSIX
including C and C++, when Java is compiled, subset.
it is not compiled into platform specific
 Portable
machine, rather into platform-independent
byte code. This byte code is distributed over  Secure
the web and interpreted by the Java Virtual  With Java's secure feature it enables to
Machine (JVM) on whichever plaatform it is develop virus-free, tamper-free systems.
being run on. Authentication techniques are based on
 Java is designed to be easy to learn. If you public-key encryption.
understand the basic concept of OOP Java, it  Robust
would be easy to master.
 Java makes an effort to eliminate error-prone situations by emphasizing mainly on compile time error
checking and runtime checking.
 Multithreaded
 With Java's multithreaded feature it is possible to write programs that can perform many tasks
simultaneously. This design feature allows the developers to construct interactive applications that can
run smoothly.
 Interpreted
 Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The
development process is more rapid and analytical since the linking is an incremental and light-weight
process.
 High Performance
 With the use of Just-In-Time compilers, Java enables high performance.
 Distributed
 Java is designed for the distributed environment of the internet.
 Dynamic
 Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving
environment. Java programs can carry an extensive amount of run-time information that can be used to
verify and resolve accesses to objects at run-time.
Differences between C, C++, and Java
Differences Continued….
JDK (Java Development Kit)
 1. JDK (Java Development Kit) is a Kit that provides the
environment to develop and execute(run) the Java program.
JDK is a kit(or package) that includes two things
• Development Tools(to provide an environment to develop your
java programs)
• JRE (to execute your java program).
 2. JRE (Java Runtime Environment) is an installation package
that provides an environment to only run(not develop) the
java program(or application)onto your machine. JRE is only
used by those who only want to run Java programs that are  Here are the important reasons for using JVM:
end-users of your system. • The JVM is a platform-independent Java source code
 3. JVM (Java Virtual Machine) is a very important part of execution engine.
both JDK and JRE because it is contained or inbuilt in both. • It has numerous libraries, tools, and frameworks.
Whatever Java program you run using JRE or JDK goes into • Once you run a Java program, you can run it on any
JVM and JVM is responsible for executing the java program platform and save lots of time.
line by line, hence it is also known as an interpreter.
• JVM has a built-in JIT compiler that converts Java
source code into machine code. This results in faster
performance compared to regular applications.
The components of JRE are as follows:

1. Deployment technologies, including deployment, Java Web Start, and Java Plug-in.
2. User interface toolkits, including Abstract Window Toolkit (AWT), Swing, Java 2D, Accessibility, Image
I/O, Print Service, Sound, drag, and drop (DnD), and input methods.
3. Integration libraries, including Interface Definition Language (IDL), Java Database Connectivity
(JDBC), Java Naming and Directory Interface (JNDI), Remote Method Invocation (RMI), Remote Method
Invocation Over Internet Inter-Orb Protocol (RMI-IIOP), and scripting.
4. Other base libraries, including international support, input/output (I/O), extension mechanism, Beans,
Java Management Extensions (JMX), Java Native Interface (JNI), Math, Networking, Override
Mechanism, Security, Serialization, and Java for XML Processing (XML JAXP).
5. Lang and util base libraries, including lang and util, management, versioning, zip, instrument, reflection,
Collections, Concurrency Utilities, Java Archive (JAR), Logging, Preferences API, Ref Objects,
and Regular Expressions.
6. Java Virtual Machine (JVM), including Java HotSpot Client and Server Virtual Machines.
Just in Time compilers:
 JIT is an part of run time.
 The JIT compiler is enabled by default.
 It compiles bytecode to native machine code at run time.
 At run time JVM loads the classes, convert it to bytecodes and
compiling bytecodes into native machine code at run time.
 Suppose there is an java function that is going to be called 100
times, then first the method is compiled and the native machine
codes are generated by JIT.
 Later instead of interpreting the function everytime, the
compiled bytecode is called 100 times hence very fast.  Advantages of JIT compilation include:
 JIT needs processor time, When JVM first starts up, thousands • JIT compilers need less memory usage.
of methods are invoked and Compiled. Due to which start time • JIT compilers run after a program starts.
is more in JIT. • Code optimization can be done while the code is
running.
 Disadvantages of just-in-time compilation
• Any page faults can be reduced.
• Startup time can take a noticeable amount of time. • Code that is used together will be localized on the
• Heavy usage of cache memory. same page.
• Can utilize different levels of optimization.
• Increases the level of complexity in a Java program
The Difference Between JDK JRE And JVM In Java
Parameter JDK JRE JVM

Definition Java Development Kit (JDK) In Java, the Runtime Known as the Java Virtual
allows developers to develop Java Environment (JRE) implements Machine (JVM), it is a
applications. Besides the JRE, the the Java Virtual Machine (JVM). platform-independent
JDK also includes tools for For running Java applications, it abstraction machine with three
developing applications (Java provides class libraries, JVM, notions. JVM requirements are
Debugger, JavaDoc, compilers, and various other components. described in this document.
etc.).

Functionality JDKs are primarily used to execute As a code execution In the JVM, all
codes. Primarily, it is used for environment, JRE plays an implementations are specified.
development. important role. JRE relies on it for all of these
implementations.

Platform JDKs are platform-dependent. The JRE is also platform- JVMs are platform-
Dependency Each platform requires a different dependent, just like the JDK. independent. That means you
JDK. Every platform requires a don't need different JVMs for
different JRE. different platforms.
Important Questions

 Differentiate between Procedure oriented programming and Object oriented programming. (8)
 Explain the need & features of object oriented programming.(8)
 What is the difference between C and C++. (2)
 State the JIT compiler advantages. (2)
 What is the advantage of OOPs? (2)
 List the features of java programming language.(2)
 What is the difference between JDK, JRE and JVM? (8)
 Why is inheritance used in java? (2)

You might also like