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

3.1 (A) Introduction To OOP

The document contains lecture notes on the Java programming language. It discusses 6 topics: introduction to Java, data types and operators, control structures, arrays, methods, and Java programs. It covers object-oriented programming concepts like classes, objects, abstraction, encapsulation, inheritance, and polymorphism. Real-world examples are provided to illustrate each concept.

Uploaded by

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

3.1 (A) Introduction To OOP

The document contains lecture notes on the Java programming language. It discusses 6 topics: introduction to Java, data types and operators, control structures, arrays, methods, and Java programs. It covers object-oriented programming concepts like classes, objects, abstraction, encapsulation, inheritance, and polymorphism. Real-world examples are provided to illustrate each concept.

Uploaded by

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

[LECTURE NOTES]

TOPIC 3:
JAVA LANGUAGE

Computer Science 2 - SC025 [2021/2022] 1


Six (6) Subtopics
3.1 Introduction to 3.2 Data Type, Operator and
Java Expression

3.4 Array 3.3 Use of


Control
Structure

3.5 Method 3.6 Java


Program

Computer Science 2 - SC025 [2021/2022] 2


3.1 Introduction to Java

3.1 (a) Introduction to Object-oriented


Programming

Computer Science 2 - SC025 [2021/2022] 3


Object-oriented Programming

 Object oriented programming (OOP) is


a
programming technique that uses
design the applications and computer programs.
“objects” to

 Program contains objects and classes.

 Examples of programming language:


- Java - C++
- Phyton - C#

Computer Science 2 - SC025 [2021/2022] 4


Class & Object

 Class is a category of objects or template for


creating objects.

Computer Science 2 - SC025 [2021/2022] 5


Class & Object

 Syntax to declare a Class in Java:

Computer Science 2 - SC025 [2021/2022] 6


Class & Object

 Object is an instance of a Class.

 Object determines the behavior of the Class.

 From a programming point of view, an object can


be a data structure, a variable or a function.

 It has a memory location allocated. The object is


designed as Class hierarchies.

Computer Science 2 - SC025 [2021/2022] 7


Class & Object

Computer Science 2 - SC025 [2021/2022] 8


Class & Object

Dog2Object

Computer Science 2 - SC025 [2021/2022] 9


Class & Object

Computer Science 2 - SC025 [2021/2022] 10


Class & Object

Computer Science 2 - SC025 [2021/2022] 11


Class & Object

Computer Science 2 - SC025 [2021/2022] 12


Class & Object

Computer Science 2 - SC025 [2021/2022] 13


Class & Object

Sample
Program

Computer Science 2 - SC025 [2021/2022] 14


Characteristics of OOP

01 02

03 04

Computer Science 2 - SC025 [2021/2022] 15


 Abstraction is a process of hiding the
implementation details and showing only
functionality to the user.

 It is the ability to represent data at a very


conceptual level without any details.

 Another way, it shows only essential things to the user


and hides the internal details.

Computer Science 2 - SC025 [2021/2022] 16


 Real-life example of abstraction. Think about how
you use your phone:
Smart phones are
complex. But using them
is simple.
You interact with your
phone by using only a
few buttons. What’s
going on under the
hood? You don’t have to
know —
implementation details
are hidden. You only
need to know a short
set of actions.
Computer Science 2 - SC025 [2021/2022] 17
 Encapsulation in Java is a process of wrapping code
and data together into a single unit.

 Object is designed to be
self-contained modules
include the behavior and
data together in one
container.

Computer Science 2 - SC025 [2021/2022] 18


 Hiding of data by declaring the object data to be
private so it will not be accessible by non-member
modules.

 Say we have a program. It has a few logically


different objects which communicate with each other
— according to the rules defined in the program.

Computer Science 2 - SC025 [2021/2022] 19


 Encapsulation is
achieved when each
object keeps its
state private, inside a
class. Other objects
don’t have direct
access to this state.
 Instead, they can only
call a list of public
functions — called
methods.

Computer Science 2 - SC025 [2021/2022] 20


 Benefits of Encapsulation:
- The fields of a class can be made read-only
or write-only.

- A class can have total control over what


is stored in its fields.

Computer Science 2 - SC025 [2021/2022] 21


Computer Science 2 - SC025 [2021/2022] 22
 Inheritance in Java is a mechanism in which one
object acquires all the properties and behaviors of a
parent object.

 It is the ability to create a new class from an existing


class. It is the mechanism in Java by which one class
is allow to inherit the features (fields and methods)
of another class.

Computer Science 2 - SC025 [2021/2022] 23


A private teacher is a type of teacher. And any teacher is a type of
Person. Computer Science 2 - SC025 [2021/2022] 24
 We use inheritance in Java for the following reasons:

1. We can reuse the code from the base class.


2. We can increase features of class or method.
3. Inheritance is used to use the existing features of
class.
4. It is used to achieve runtime polymorphism.
5. We can organize the information in the hierarchy
form.

Computer Science 2 - SC025 [2021/2022] 25


 The advantages of inheritance in Java are as follows:

(1) User can minimize the length of duplicate code in


an application.
(2) Due to reducing the length of code, redundancy of

the application is also reduced.


(3) Application code becomes more flexible.

Computer Science 2 - SC025 [2021/2022] 26


Computer Science 2 - SC025 [2021/2022] 27
 Polymorphism occurs when there are many classes
that are related to each other by inheritance.
 It is a concept by which user can perform a single action
in different ways.
 A single statement is used to call various
methods and the exact method to be called is
only known during runtime.
 Polymorphism gives a way to use a class exactly like
its parent so there’s no confusion with mixing types.
But each child class keeps its own methods as they
are.
Computer Science 2 - SC025 [2021/2022] 28
 Real life example of
polymorphism:
A person at the same time
can have different
characteristic.
Like a man at the same time is
a father, a husband, an
employee. So the same person
have different behavior in
different situations.

Computer Science 2 - SC025 [2021/2022] 29


 Real life example of polymorphism.
Suppose if you are in class room that time you behave like a
student, when you are in market at that time you behave like a
customer, when you at your home at that time you behave like a
son or daughter.

Computer Science 2 - SC025 [2021/2022] 30


Summary

Computer Science 2 - SC025 [2021/2022] 31


Summary

Computer Science 2 - SC025 [2021/2022] 32


References

Y. Daniel Liang (2018). Introduction to Java Programming,


Brief Version -11th Ed. Pearson.

YouTube Channel

Website:
https://www.tutorialspoint.com/java/index.htm

Computer Science 2 - SC025 [2021/2022] 33

You might also like