Lecture-2 3

You might also like

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

UNIVERSITY INSTITUTE OF ENGINEERING

DEPARTMENT OF AIT - CSE


Bachelor of Engineering (CSE)
Programming in Java (21CSH-244)
By: Kushagra Agrawal(E13465)

Lecture - 2 & 3
Introduction to Procedural Programming,
DISCOVER . LEARN . EMPOWER
Object-Oriented Programming, Features to
Java
Chapter Course Objectives

● To understand the about of Procedural Oriented Language


1. ● To understand the about of Object Oriented Language
● To understand Features of JAVA

Chapter Course Outcomes


After completion of this course, student will be able to

● Differentiate to Procedural Oriented Language and Object


1. Oriented Language
● Aware the features of JAVA

2
Contents
• Introduction to Procedurals Oriented Programming Language.
• Introduction to Object Oriented Programming Language.
• Features of OOPs.
• Features of JAVA.

3
Introduction to Procedural Oriented Programming
Language
• Procedural Oriented Programming is a programming language that follows a step-
by-step approach to break down a task into a collection of variables and routines
(or subroutines) through a sequence of instructions. Each step is carried out in
order in a systematic manner so that a computer can understand what to do.

• POP the main program is divided into small parts based on the functions and is
treated as separate program for individual smaller program.

• POP is less secure as compare to OOPs.

• No modifiers are introduced in POP. 4


Introduction to Object Oriented Language

• Object-oriented Programming is a programming language that uses classes and


objects to create models based on the real world environment. In OOPs it makes it
easy to maintain and modify existing code as new objects are created inheriting
characteristics from existing ones.

• In OOPs concept of objects and classes is introduced and hence the program is
divided into small chunks called objects which are instances of classes.

• In OOPs access modifiers are introduced namely as private,protect and public.

5
Differences between POP and OOP

6
Differences between POP and OOP (cont..)

7
Features of Object Oriented Programming

8
What Is an Object?

• An object is a software bundle of related state and behaviour.


• Software objects are often used to model the real-world objects that you find in everyday
life.
• For example: chair, pen, table, keyboard, bike etc. It can be physical and logical.

Note: Hiding internal state and requiring all interaction to be performed through an object's
methods is known as data encapsulation — a fundamental principle of object-oriented
programming.
Benefits of Object
• Modularity: The source code for an object can be written and maintained
independently of the source code for other objects. Once created, an object can be
easily passed around inside the system.
• Information-hiding: By interacting only with an object's methods, the details of
its internal implementation remain hidden from the outside world.
• Code re-use: If an object already exists (perhaps written by another software
developer), you can use that object in your program. This allows specialists to
implement/test/debug complex, task-specific objects, which you can then trust to
run in your own code.
• Pluggability and debugging ease: If a particular object turns out to be
problematic, you can simply remove it from your application and plug in a
different object as its replacement. This is analogous to fixing mechanical
problems in the real world. If a bolt breaks, you replace it, not the entire machine.
What is a Class?
• A class is a blueprint or prototype from which objects are created.
• In the real world, you'll often find many individual objects all of the same kind.
• Ex:
class Bicycle
{
int cadence = 0; int speed = 0; int gear = 1;
void changeCadence(int newValue)
{ cadence = newValue; }
void changeGear(int newValue)
{ gear = newValue; }
void speedUp(int increment)
{ speed = speed + increment; }
}
Ex:- Main method
class BicycleDemo
{
public static void main(String[] args)
{
// Create two different
Bicycle bike1 = new Bicycle();
Bicycle bike2 = new Bicycle();
// Invoke methods on
bike1.changeCadence(50);
bike1.speedUp(10);
bike2.changeCadence(50);
bike2.speedUp(10);
}
}
What Is Inheritance?
• Inheritance provides a powerful and natural mechanism for organizing and
structuring your software.
• When one object acquires all the properties and behaviours of parent
object i.e. known as inheritance.
• It provides code reusability. It is used to achieve runtime polymorphism.
• Ex:
class MountainBike extends Bicycle
{
// new fields and methods defining
// a mountain bike would go here
}
What is a Polymorphism ?

• When one task is performed by different ways i.e. known as


polymorphism.
• For example: to convince the customer differently, to draw something
e.g. shape or rectangle etc.
• In java, we use method overloading and method overriding to achieve
polymorphism.

draw() draw()
What is a Abstraction?

• Hiding internal details and showing functionality is known as


abstraction.
• For example: phone call, we don't know the internal processing.
• In java, we use abstract class and interface to achieve abstraction.
What is a Encapsulation?
• Binding (or wrapping) code and data together into a single unit is
known as encapsulation.
• For example: capsule, it is wrapped with different medicines.
• A java class is the example of encapsulation.
Features of JAVA

17
• Java is a simple programming language.
• This is the design aim of JAVA.
Simple • Omitted Pointer concepts from JAVA.
• Use same syntax of C and C++.

• Pointers lead to confusion for a programmer.


• Pointers may crash a program easily.
Why pointers are • Pointers break security.(Using pointers
eliminated from JAVA? harmful programs like Virus and other hacking
program can be developed).
Object- • Java is an object-oriented programming language.
• This means Java programs use objects and classes.
oriented • Java is a purely object-oriented programming language.

• Information on various computers on a networks.


Distributed • Java can handle the protocols like TCP/IP and UDP.
• Java supports Remote Method Invocation(RMI).

• Java strong as compare to C and C++.


• Java has got excellent inbuilt exception handling features.
Robust • Java has lies in its memory management features.(User need not
allocate and deallocate the memory in Java(Garbage Collector).)
• Security problem like eavesdropping, tampering, impersonation and virus
Secure threats can be eliminated or minimized by using Java on Internet.

System • Java’s byte code is not machine dependent.


independence

• If a program yields the same result on every machine then that program is
Portability called portable.
• This is the result of Java’s System independence nature.

• Java programs are complied to generate the byte code.


Interpreted • This byte code can be download and interpreted by the interpreter in JVM.
• Java use both compiler and interpreter.
• The problem with interpreter inside the JVM is that it is slow.
• To overcome this problem, along with the interpreter have used JIT(Just in
High Performance Time ) compiler.
• Which enhances the speed of execution.

• Java allows to write programs that do many things simultaneously.


• A thread represents an individual process to execute a group of statements.
Multithreaded • JVM uses several threads to execute different block of code.
• Creating multiple threads is called ‘multithreaded’.

• Java animation done using an applet program, which are the


dynamically interacting programs on Internet.
Dynamic • In Java environment byte code may be dynamically updated on a
running system.
Summary
• Discussed Procedural Oriented Programming Language.
• Discussed Object Oriented Programming Language.
• Discussed Features of OOPs.
• Discussed Features of JAVA.

22
Home Work
Q1. Identify five Difference in-between POPs and OOPs ?
Q2. Illustrate the uses of Object Oriented Programming languages?

23
References

Online Video Link


• https://nptel.ac.in/courses/106/105/106105191/
• https://www.coursera.org/courses?query=java
• https://www.coursera.org/specializations/object-oriented-programming
• https://www.youtube.com/watch?v=aqHhpahguVY

Text Book
• Herbert Schildt (2019), “Java The Complete Reference, Ed. 11, McGraw-Hill .

24
THANK YOU

For queries
Email: kushagra.e13465@cumail.in

You might also like