Concept of Oops

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 36

Module 1 - Concepts of Object oriented

programming, Benefits of OOP


Reference: E.Balagurusamy
Java History
• A general purpose object oriented programming language.
• Developed by Sun Microsystems of USA in 1991.
• James Gosling, Patrick Naugthon, Chris Warth, Ed Frank and Mike Sheridan.
• Originally called OAK.
• Designed for the development of software for consumer electronic devices
(like TV, VCR, Toaster, Washing Machine and such other electronic devices).
• The main goal of the team - make a language that is simple, portable and
highly reliable.
• C, C++ had limitations in terms of reliability and portability.
• Java removed a number of features from C and C++ that were considered as
sources of problems and made it really simple, reliable, portable and highly
powerful language.
Overlap of C, C++, and Java

C++

C Java
JAVA MILESTONES
Year Development
1990 Sun Microsystems decided to develop special software that could be used
for electronic devices.
A team of Sun Microsystem programmers called Green Project was created
and head by James Gosling.

1991 Explored possibility of using C++, with some updates announced a new
language named “Oak”
1992 The team demonstrated the application of their new language to control a
list of home appliances using a hand held device with a tiny touch-sensitive
screen.
1993 The World Wide Web appeared on the Internet and transformed the text-
based internet to a graphical rich environment.
The team came up with the idea of developing Web applets (tiny programs)
using the new language , that could run on all types of computers connected
JAVA MILESTONES
Year Development
1994 The team developed a new Web browser called “Hot Java” to locate and
run Applets.
HotJava demonstrated the power of the new language and gained instant
success.
1995 Oak was renamed to Java, as it did not survive “legal” registration.
Many companies such as Netscape and Microsoft announced their
support for Java
1996 Java established itself it self as both
1. “the language for Internet programming”
2. a general purpose OO language.
Sun released Java Development Kit 1.0(JDK 1.0)
1997- Sun released JDK 1.1
A class libraries, Community effort and standardization, Enterprise Java,
Clustering, etc..
JAVA MILESTONES
Year Development
1998 Sun released Java 2 with version 1.2 of the software Development Kit(SDK 1.2)

1999 Sun released Java 2 Platform, Standard Edition(J2SE)and Enterprise Edition(J2EE)

2000 J2SE with SDK 1.3 was released.

2002 J2SE with SDK 1.4 was released.

2004 J2SE with JDK5.0 was released. This is known as J2SE5.0.

Currently Java Platform, Standard Edition 11. Java SE 11.0.18 is the latest release of Java
SE 11 Platform. As of March 2022, Java 18 is the latest released Java version.
Concepts of Object Oriented
Programming

• Objects and classes


• Data Abstraction and Encapsulation
• Inheritance
• Polymorphism
• Dynamic Binding
• Message Communication
Objects and Classes

• Any entity that has state and behaviour is known as an object.


• Objects – Basic runtime entities in an object oriented system.
• Programming problems are analysed in terms of objects and the
nature of communication between them.
• Objects interact by sending messages.
• Contain data and code to manipulate the data.
• Data + code - Class
• An Object can be defined as an instance of a class.
• An object contains an address and takes up some space in memory.
• Objects can communicate without knowing the details of each other's
data or code.
• The only necessary thing is the type of message accepted and the
type of response returned by the objects.
Objects and Classes

• Collection of objects is called class. It is a logical entity.


• A class can also be defined as a blueprint from which you
can create an individual object. Class doesn't consume any
space.
Abstraction

• Data abstraction is the process of hiding certain details


and showing only essential information to the user.

• Abstraction can be achieved with either abstract


classes or interfaces.
Encapsulation

• Encapsulation is the mechanism that binds together code and the data it
manipulates, and keeps both safe from outside interference and misuse.
• Encapsulation is like a protective wrapper that prevents the code and
data from being arbitrarily accessed by other code defined outside the
wrapper.
• The meaning of Encapsulation, is to make sure that "sensitive" data is
hidden from users.
• Done using the access specifier private
• To achieve this, you must:
• declare class variables/attributes as private
• provide public get and set methods to access and update the value of
a private variable
Inheritance

• Inheritance is the process by which one object acquires the properties of


another object.
• This is important because it supports the concept of hierarchical classification.
• By use of inheritance, an object need only define those qualities that make it
unique within its class.
• It can inherit its general attributes from its parent. Thus, it is the inheritance
mechanism that makes it possible for one object to be a specific instance of a
more general case.
• We group the "inheritance concept" into two categories:
• subclass (child) - the class that inherits from another class
• superclass (parent) - the class being inherited from.
• To inherit from a class, use the extends keyword.
Polymorphism
• Polymorphism means "many forms", and it occurs when we have many
classes that are related to each other by inheritance.
• 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.
• The programmer does not need to make this selection manually but only
remember and utilize the general interface.

• Inheritance lets us inherit attributes and methods from another class.


Dynamic Binding

• Binding – linking of a procedure call to the code to be


executed in response to the call.
• Dynamic binding- the code associated with a given
procedure call is not known until the time of the call at
runtime.
• It is associated with polymorphism and inheritance.
• A procedure call associated with a polymorphic reference
depends on the dynamic type of that reference.
Message Communication

• An OO PROGRAM consists of a set of objects that


communicate with each other.
• Programming process:
• Creating classes that define objects and their behaviour.
• Creating objects from class definitions.
• Establishing communication among objects.
• A message for an object is a request for execution of a
procedure and therefore will invoke a method in the
receiving object that generates the desired result.
Features of Java

• Familiar, Simple, Small


• Compiled and Interpreted
• Platform-Independent (Architecture-Neutral) and
Portable
• Object-Oriented
• Robust and Secure
• Distributed
• Multithreaded and Interactive
• High Performance
• Dynamic and Extensible
Simple, Small and Familiar
• Many features of C and C++ are part of the Java language.
• Java removed a number of features from C and C++ that
were considered as sources of problems.
• No pointers, preprocessor header files , goto statement, etc
• No operator overloading.
• No MULTIPLE INHERITANCE.

• Familiar to the programmers – modelled based on C and


C++
• Uses many constructs of C and C++ .
• Looks like C++ code – but is a simplified version of C++.
Compiled and Interpreted

• Usually programming languages are either compiled or


interpreted.
• Java combines both these approaches making it a two-stage
system.
• Step 1: Java Compiler translates source code into bytecode
instructions.
• Bytecodes are not machine instructions and therefore
interpreter is required
• Step 2 – Java interpreter generates machine code that can
be directly executed by the machine that is running the java
program.
Java is Compiled and Interpreted

Hardware and
Programmer
Operating System

Source Code Byte


Code
Text Editor Compiler Interpreter
.java file .class
file java
Notepad, javac
emacs,vi appletviewer
netscape
Platform-Independent (Architecture-Neutral) and Portable

• Most significant feature of java is portability.


• Java programs can be easily moved from one computer system to
another anywhere and anytime.
• Goal – write once, run anywhere, anytime, forever .
• Changes and upgrades in OS, processor and system resources will
not force any changes in the java programs -> reason why it became
famous for internet programming.
• Download a Java Applet from a remote computer onto our local
machine via internet and execute it locally.
• Java ensures portability in 2 ways:
• Generates bytecode instructions that can be implemented on any machine.
• The size of the primitive datatypes are machine independent.
Total Platform Independence
JAVA COMPILER
(translator)

JAVA BYTE CODE


(same for all platforms)

JAVA INTERPRETER
(one for each different system)

Windows 95 Macintosh Solaris Windows NT


Object-Oriented

• Pure(true) object oriented language.


• Almost everything in java is an OBJECT.
• All program code and data resides within objects and classes.
• Java has an extensive set of classes arranged in PACKAGES.
• Classes in these Packages may be used in our programs by
inheritance.
• The object model in Java is simple and easy to extend.
Robust and Secure

• Java provides many safeguards to ensure reliable code.


• It has strict compile time and run time checking for datatypes.
• Designed as a garbage collected language – relieving programmers
virtually from all memory management problems(managing memory
allocation and de-allocation).
• Incorporates the concept of exception handling which captures runtime
errors and eliminates any risk of crashing the system.

• Used for programming on internet -> Security becomes an important


issue.
• Threat of viruses and abuses of resources is everywhere.
• Java system not only verifies all memory access but also ensures that
programs cannot gain access to memory locations without proper
Distributed
• Designed as a distributed language for creating
applications on networks.
• Has the ability to share both data and programs.
• It handles TCP/IP protocol which enables accessing a
resource using a URL.
• Also supports Remote Method Invocation(RMI) – a feature
which enables a program to invoke methods across a
network as easily as they can do on a local system.
• Enables multiple programmers at multiple remote
locations to collaborate and work together on a single
project.
Multithreaded and Interactive

• Multithreaded means handling multiple tasks


simultaneously.
• Multithreaded programming allows you to write
programs that do many things simultaneously.
• Need not wait for the application to finish one task
before beginning another.
• Greatly improves interactive performance of graphical
applications.
• Java runtime system comes with elegant solutions for
multiprocess synchronization that enables you to
High Performance

• Java performance is impressive for an interpreted


language due to the use of intermediate bytecode.
• The bytecode was carefully designed so that it would be
easy to translate directly into native machine code for
high performance by using a just-in-time compiler.
• Java speed is comparable to that of C, C++ -
multithreading further enhances the overall execution
speed of java programs.
• Java architecture is designed to reduce overheads
during runtime.
Dynamic and Extensible

• Programs carry substantial amount of run-time information- >


enables access to objects at runtime.
• Capable of dynamically linking code in a safe and expedient manner.
• Can dynamically link to libraries, methods and objects .
• Can determine the type of class through a query and making it
possible to either dynamically link or abort the program depending
on the response.
• Support functions written in languages like C, C++(native methods)-
enables programmers to use the efficient functions available in
these languages.
• These methods are linked dynamically at runtime.
How JAVA differs from C
• C is structured/procedural programming language while java is pure object oriented
language.
• Java does not include keywords like sizeof and typedef
• Does not contain the datatypes struct and union
• Does not define type modifiers keywords auto, extern, register, signed and unsigned.
• Does not support an explicit pointer type.
• Does not have preprocessor and hence cannot use #define, #include and #ifdef
statements.
• In java functions with no arguments must be declared with empty parenthesis and not
with the void keyword as done in C.
• Adds new operators such as instanceof and >>>.
• Adds labelled break and continue statements.
• Adds many features required for object oriented programming.
How JAVA differs from C++

• java is pure object oriented language while c++ is C with object oriented
extension.
• Java does not support operator overloading.
• Java does not support multiple inheritance of classes. This is
accomplished using a new feature called “interface”.
• Java does not support global variables. Each variable and method is
declared within a class and forms a part of that class.
• Java does not use pointers.
• Java has replaced the destructor function with a finalize() method.
• There are no header files in java.
Advantages of Java

• Has a simple programming model


• Helps you to write object oriented applications easily and in a more
productive way.
• Automatic memory management makes it robust and
secure.
• Platform independent/portable feature
• Gives ability to java programs to be moved and executed on any
computer system.
Disadvantages of Java

• Performance
• Significantly slower
• Consume more memory than natively compiled languages like C
and C++.
• Look and feel
• Look and feel of GUI applications written in Java is different form
native languages.
• Single-paradigm language
• Primarily a single-paradigm language.
Why is java a strongly typed language?

• 2 reasons
• Every variable has a type, every expression has a type and every
type is strictly defined.
• All assignments, whether explicit or via parameter passing in
method calls, are checked for type compatibility.
• The compiler checks all expressions and parameters to ensure that
these types are compatible.
• Any mismatches are errors and must be corrected before the compiler
will finish compiling the class.

You might also like