0% found this document useful (0 votes)
46 views108 pages

Unit - 1 Part 1

The document discusses two programming paradigms: Process-Oriented Programming (POP) and Object-Oriented Programming (OOP), highlighting their differences in structure, approach, and data handling. It explains the features and advantages of Java as an object-oriented language, its history, various editions, and its applications across different domains. Additionally, it covers Java's characteristics, environment, and comparisons with C and C++, emphasizing its platform independence and robust nature.

Uploaded by

charanmekala17
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)
46 views108 pages

Unit - 1 Part 1

The document discusses two programming paradigms: Process-Oriented Programming (POP) and Object-Oriented Programming (OOP), highlighting their differences in structure, approach, and data handling. It explains the features and advantages of Java as an object-oriented language, its history, various editions, and its applications across different domains. Additionally, it covers Java's characteristics, environment, and comparisons with C and C++, emphasizing its platform independence and robust nature.

Uploaded by

charanmekala17
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/ 108

Object-Oriented Thinking

Two Paradigms of Programming

•Program = Code + Data


• Program can be organized around Data or around Code
•Two paradigms of programming:
1. Process-oriented model: around Code (acting on data)
• Program is defined by sequence of codes
• Data structures + Algorithms = Program
• Problem complexity: <25,000-100.000 lines of code
2. Object-oriented model: around Data (Objects)
• Objects + Messages = Program
• Data-controlling access to code
Procedure-Oriented Programming Object-Oriented Programming
• In POP, program is divided into small • In OOP, program is divided into parts
parts called functions called objects.
• In POP, Importance is not given to data • In OOP, Importance is given to the data
but to functions as well as sequence of rather than procedures or functions
actions to be done. because it works as real world.
• POP follows Top Down approach. • OOP follows Bottom Up approach.
• OOP has access specifiers named
• POP does not have any access specifier.
Public, Private, Protected, etc.
• In OOP, objects can move and
• In POP, Data can move freely from
communicate with each other through
function to function in the system.
member functions.
• To add new data and function in POP is • OOP provides an easy way to add new
not so easy. data and function.
Procedure-Oriented Programming Object-Oriented Programming

• In OOP, data can not move easily


• In POP, Most function uses Global data
from function to function, it can be
for sharing that can be accessed freely
kept public or private so we can
from function to function in the system.
control the access of data.
• POP does not have any proper way for • OOP provides Data Hiding so provides
hiding data so it is less secure. more security.
• In OOP, overloading is possible in the
• In POP, Overloading is not possible. form of Function Overloading and
Operator Overloading.

• Example of POP are : C, VB, • Example of OOP are : C++,


FORTRAN,Pascal. JAVA, VB.NET,C#.NET.
A way of viewing world

•Want to send flowers to another town

•How: ask your local florist

“don’t even want to know the details (delegation)”


Agents and communities
•OO program = community of interacting agents
called objects

•Each object provides a service, used by others:


Message passing
•Message passing is the process by which an object
sends data to another object or asks the other
object to invoke a method.

•Also known to some programming languages as


interfacing.
Messages and methods
•Action: initiated by a message to an object
responsible for the action
•Arguments: additional necessary information for
the request
•Receiver: accepts message, performs some
method to satisfy the request
More on methods
• Information hiding, be lazy, let someone else perform
the task, reuse, use others’ services.

• Method passing Vs Function


• Selected receiver
• Different interpretation depending on the specific receiver
• Receiver only known at runtime (late binding)
What is java
Java
• Work on Java started in 1991

• Java was created by a team lead by James Gosling in 1995 for Sun Microsystems.

• The goal: a new portable language

• Original name: Oak

• Original tagline: "Write once, run everywhere"

• Programming language

• Object-oriented language

• Foundational language
Where is Java used ?
Where is Java used ?
• Java has been used in different domains. Some of them are listed
below:

• Banking: To deal with transaction management.

• Retail: Billing applications that you see in a store/restaurant are completely written in Java.

• Information Technology: Java is designed to solve implementation dependencies.

• Android: Applications are either written in Java or use Java API.

• Financial services: It is used in server-side applications.

• Stock market: To write algorithms as to which company they should invest in.

• Big Data: Hadoop MapReduce framework is written using Java.

• Scientific and Research Community: To deal with huge amount of data.


Java Editions
Java Editions
• Java Platform, Standard Edition (SE)
• Core language and Java Runtime Environment (JRE)

• Java Platform, Enterprise Edition (EE)


• Recommendation for industrial-strength web applications
• Donated to Apache in 2018, now named Apache Jakarta EE
Other Java Platforms

•Java Platform, Micro Edition (ME)


• Microcontrollers, sensors, and mobile devices
• Subset of Java SE

•Java FX
• Desktop application framework
• Was bundled with JDK, removed in 2018 with Java SE 11
The History and Future of
Java
Java Version History
J2SE 5.0 (1.5)
Generics
JDK 1.1 Metadata
Inner classes J2SE 1.3
HotSpot JVM Enumerations
JavaBeans
JDBC JNDI interface Variable
First RMI Java Sound API arguments
Release Reflection Debugging architecture For-each loops
1995 1997 2000 2004

2002
1996 1998 J2SE 1.4
JDK 1.0 J2SE 1.2 Regular expressions
Swing graphical API IPv6 network communications
JIT compiler Logging API
Java plugin XML and
Collections network XSLT
Security and cryptography
Java Version History
Java SE 8
Lambda expressions Still most popular as
and method references of early 2019*
Collections with streams *jetbrains.com/lp/
New date/time API
Oracle buys Sun Nashorn JavaScript engine
devecosystem-2019/java
2010 2014

2006 2011 2017


Java SE 6 Java SE 7 Java SE 9
Performance JDBC 4.0 Strings in switch Library modularization
GUI improvements Try-catch improvements JShell environment
Simplified variable arguments Improved Javadoc
Underscores in numeric Process API updates
Private interface methods
literals
Java SE Roadmap
• Long term support (LTS) versions every three years
• Oracle premiere support for five years, extended support for eight
years

• Rapid release (non-LTS) versions every six months


• Only supported until next release
Recent Versions
Java SE 11 (LTS) Java SE 13
New lambda syntax Many JVM and garbage
Dynamic class-file constants collector improvements
New HTTP client More in switch expressions
Nashorn deprecated (still preview)
Text blocks (preview)
September 2018
September 2019

March 2018 March 2019


Java SE 10 March 2019
Type inference Java SE 12
Garbage collector Switch expressions (preview)
JVM Constants API
interface
Abortable mixed collections
Time-based release
versioning
Java Features
The Java Buzzwords
• To support internet application development Java programming
has below features
• The Java programming language can be characterized by all of the
following buzzwords:
1. Simple 6. High performance
2. Object oriented 7. Portable
3. Secure 8. Distributed
4. Multithreaded 9. Platform Independent
10. Dynamic
5. Robust
11. Interpreted
Simple:
• The java language is called as simple programming
language because of the following reasons:
• The syntax of java language is similar to other
programming languages like C, C++ etc. &
therefore, simple to migrate from other languages.
• The complex topics like pointers, templates etc. are
eliminated from java making it simple.
• In the java language the programmer is responsible for
only allocation of memory. The deallocation of the
memory is done by the garbage collector.
Object Oriented:
• The java language is called as object oriented language.
• Any language can be called as object oriented if the development of the application is
based on objects and classes.
• Object:
• Any entity that exists physically in this real world which requires some memory is called as object.
• Every object contains some properties and some actions. The properties are the data which
describes the object and the actions are the tasks or the operations performed by the objects.
• Class:
• A class is a collection of common properties, and common actions of a group of objects.
• A class can be considered as a plan or a model or a blue print for creating the objects.
• For every class we can create any number of objects and without a class object can't be
created.
• Example:
• Class: Student
• Object: Rajesh, Ramu
Security:
• Security is one of the most important
principles of any programming
language.

• The java language contains in-built


security programs for protecting the
data from unauthorized usage.
Distributed:
• Using the distributed feature we can
access the data available in multiple
machines and provide it to the user.
• Using this feature we can improve the
performance of the application by making
the data more available and more
accessible.
Platform Independent or
Machine Independent or
Architecture Neutral:
C++ Platform Dependent
Java : Platform Independent
Platform Independent
• The java program can be executed on any machine irrespective of their hardware, software,
architecture, operating system etc., therefore it is called as platform independent language.

• C Language:
• When we compile a C program, the compiler verifies whether, the language instructions are valid
not, if valid the compiler generates .exe file containing machine language instructions.
Compiler
Mgit.c Mgit.exe
C language Instruction Machine Language Instruction
• The machine language instructions available in the .exe files generated by the compiler can be
executed only in that machine, where it is compiled.

• If we want to execute the C program in another machine, then we need to recompile and then
execute. This nature of C language makes it machine dependent or platform dependent language.
Cont..
• Java Language:

• When we compile a java program, the compiler verifies whether the java language
instructions are valid or not,
• if valid the compiler will generate .class file containing special java instructions
(byte code inst ructions).
Compiler
Mgit.java Mgit.class
Java language Byte code Instruction
Instruction

• The special java instructions available in the .class file generated by the compiler
can be executed on any machine with help of JVM, without recompiling it.

• This nature of java language makes it platform independent.


6. Interpreted: The java language is said to interpreted language as
the execution of the program is done by the interpreter available
inside the JVM.
7. High Performance: The execution of a java program is done by an
interpreter along with a special compiler called JIT compiler, thereby
reducing the execution time and improving the performance of the
application.
8. Portable: The java language is said to be portable language using
which we can develop an application, which is a collection of small
components, which can be replaced and reused.
9. Multithreaded: A language is said to be multithreaded, if it
supports multithreading. Every thread in java program is a control. If
the program contains multiple controls then we can reduce the
waiting time, and provide response faster and there by improving
the performance.
10. Dynamic: The java language is said to be dynamic because the
allocation of memory is done at execution time according to the
requirement. For example : runtime polymorphism
11. Robust:
• The java language is said to be strong programming language, because of
the following reasons:
a) Memory management: In java language the allocation of memory and
deallocation of memory, both are efficient.
• During the memory allocation time, there will be no wastage of memory
and deallocation is done by garbage collector which is also efficient as the
unused memory will be removed.
b) Exception handling: The errors that occur at runtime because of the
logical failure or invalid inputs are called as exceptions.
• When an exception occurs, the application will be terminated
abnormally and executed incompletely.
• In order to execute the code completely and terminate normally, we
take the help of exception handling. The process of exception
handling in java is simple and efficient.
Java Environment
Java Environment
• JVM (Java Virtual Machine) is an abstract machine.
It is a specification that provides runtime
environment in which java bytecode can be
executed.

• JRE (Java Runtime Environment) is a runtime


environment which implements JVM and provides all
class libraries and other files that JVM uses at
runtime.

• JDK(Java Development Kit) is the tool necessary to


compile, document and package Java programs. The
JDK completely includes JRE.
How does java work?
How does java work?
JVM Architecture
C vs C++vs JAVA
C , C++
C , C++
JAV
A
Metrics C C++ Java
Object-Oriented
Programming Paradigm Procedural language Pure Object Oriented
Programming (OOP)
Based on assembly
Origin Based on C language Based on C and C++
language
Developer Dennis Ritchie in 1972 Bjarne Stroustrup in 1979 James Gosling in 1991
Platform Dependency Platform Dependent Platform Dependent Platform Independent
Executed by JVM (Java
Code execution Direct Direct
Virtual Machine)
Approach Top-down approach Bottom-up approach Bottom-up approach
File generation .exe files .exe files .class files
Support header files Supported (#header,
Pre-processor directives Use Packages (import)
(#include, #define) #define)
keywords Support 32 keywords Supports 63 keywords 50 defined keywords
Datatypes (union,
Supported Supported Not supported
structure)
Interpreted language
Translator Compiler only Compiler only
(Compiler + interpreter)
Metrics C C++ Java
Supported except
Inheritance No inheritance Supported
Multiple inheritance
Support Function
Operator overloading is
Overloading No overloading overloading
not supported
(Polymorphism)
Pointers Supported Supported Not supported
Allocation Use malloc, calloc Use new, delete Garbage collector
Exception Handling Not supported Supported Supported
Templates Not supported Supported Not supported
No constructor neither
Destructors Supported Not supported
destructor
Multithreading/
Not supported Not supported Supported
Interfaces
Database connectivity Not supported Not supported Supported
Supported Supported
Storage Classes Not supported
( auto, extern ) ( auto, extern )
Overview of Java
Object Oriented Paradigm: Features
Encapsulation

Data Abstraction

Single Inheritance

Polymorphism
OOP
Paradigm
Persistence

Delegation

Genericity

Multiple Inheritance
53
Java’s OO Features
Encapsulation

Data Abstraction

Single Inheritance

Polymorphism
OOP Java
Paradigm
Persistence

Delegation

Genericity

Multiple Inheritance
54
Class- Example
class Account {
private String accountName;
private double accountBalance;

public withdraw();
public deposit();
public determineBalance();
} // Class Account
72
Class
•Class is a set of attributes and operations that
are performed on the attributes.

Account Student Circle


accountName name centre
accountBalance age radius
studentId
withdraw() area()
getName()
deposit() circumference()
determineBalance() getId()

73
Objects
•An Object Oriented system is a collection of
interacting Objects.

•Object is an instance of a class.

74
Classes/Objects

:John John and Jill are


Student objects of class
Student
:Jill

:circleA circleA and


Circle circleB are
:circleB objects of class
Circle
75
OOPs Concept

•The 4 main concepts of object oriented programming –


1. Inheritance
2. Encapsulation
3. Polymorphism and
4. Abstraction.
Data Hiding
Abstraction
• It is basically the quality of dealing
with ideas rather than events.

• Abstraction is the methodology of


hiding the implementation details
from the user and only providing
the functionality to the users.
Abstraction - Example

class Account {
private String accountName; Creates a data
private double accountBalance; type Account

publicwithdraw(); Account acctX;


public
deposit();
public determineBalance();
} // Class Account

108
Encapsulation
• Encapsulation in Java is a
mechanism of wrapping up the
data and code together as a
single unit.

• In encapsulation,
• the variables of a class will be
hidden from other classes, and
Encapsulation=
• can be accessed only through the Datahiding +
methods of their current class. Abstraction

You might also like