Object Oriented Programming
with Java
What is Object Oriented Programming ?
Object-oriented programming (OOP) is a computer programming model that organizes
software design around data, or objects, rather than functions and logic.
● An object can be defined as a data field that has unique attributes and behavior
● OOP focuses on the objects that developers want to manipulate rather than the logic
required to manipulate them
● Well-suited for programs that are large, complex and actively updated or maintained
● Beneficial to collaborative development, where projects are divided into groups
● Additional benefits of OOP include code reusability, scalability and efficiency
Principles of OOP
Encapsulation
Binding data and functions and prevent outside interference
Eg. A car with its attributes like color, make, model etc - which cannot be changed by
interference
Abstraction
Reveal only essential information and hide unnecessary information
Eg. How a car starts, moves and its different features
Inheritance
Extending existing functionality and promote re-use. Parent and child classes
Eg. A car can be derived into multiple sub-models with varying features
Polymorphism
Ability to take multiple forms in runtime. Retain its own behaviour while looks like its
parent
Eg. Car can be represented as a Vehicle, which can also represent a Truck, Van etc.
Java Overview
● A high level programming language developed at Sun Microsystems in 1991 by James
Gosling and Patrick Naughton. Initially named as Oak
● Was intended to be used for cable-tv boxes and other embedded systems with low
memory requirements
● In 1994, the team focused on the uses of World Wide Web and released a web-browser
written in Java called WebRunner (later renamed to HotJava)
● Renamed to Java in 1996 due to the name Oak already being a registered trademark
● Java version 1.0 released in 1996, promising Write Once Run Anywhere feature
● Java 2 released in 1998, featured new technologies - J2EE (now JavaEE) for enterprise
applications and J2ME (now JavaME) for mobile applications
● Acquired by Oracle in 2011, but still the standards are set and maintained by Java
Community Process (JCP)
Java compiler compiles code into an intermediate instruction format called bytecode. This
bytecode can be executed on any platform that contains a Java Virtual Machine(JVM).
Hence the notion of Write Once Run Anywhere
Components of Java
Java Development Kit
Collection of programming tools containing the
java implementation. Used to compile classes
and generate bytecode
Java Runtime Environment
Part of JDK. Contains libraries and other
resources essential to run a java program
Java Virtual Machine
Virtual machine that converts java bytecode to
machine specific instructions
Source: JVM Architecture
Java Virtual Machine
Source: JVM Architecture
Java Programming Model
● Basic data types
● Class, Objects and Interfaces
● Multi-threading
● Concurrent Library - Classes for building concurrency features
● Collections Library - For storing and manipulating group of elements
● Abstract Window Toolkit and Swing for developing UI applications
● Servlet API - Libraries for developing web applications
● Java Database Connectivity - For database operations
● JAX-WS and JAX-RS for web services
● Java Persistence API
● Java Messaging System
Java Class
Running a Java Program
Inheritance in Java
Java allows to create subclasses using the extends keyword.
Abstract Classes
Abstract class is a type of class
where some of the methods are
concrete and the remaining
methods are left for the child
class to implement.
Abstract class is declared using
the abstract keyword.
An abstract class method is
marked using the abstract
keyword with no
implementation provided.
It is not mandatory to for a
abstract class to have a
abstract method
Interfaces
An interface is a pure abstract
type which defines the blueprint
of how a class should be
implemented.
Additionally you can also define
interface as a contract that a
implementing class should fully
adhere to.
Interface consists of abstract
methods and constants
Thank you