Lecture 1
Introduction to Java
Course Instructor Aysha Safdar, Lectur
Aysha Safdar er CS, NUML H9 ca
mpus, Islamabad
Lecturer Computer Science H9
Campus
Islamabad
Aysha Safdar, Lecture
r CS, NUML H9 camp
us, Islamabad
Programming Paradigm
• • A programming paradigm is a fundamental
approach or style of programming that
provides a set of principles, concepts, and
techniques for designing and implementing
computer programs.
• It defines the structure, organization, and
flow of the code, and methodologies for
problem-solving and expressing
computations.
• It dictates how programmers should think
about and structure their code
Aysha Safdar, Lecture
r CS, NUML H9 camp
us, Islamabad
Procedural programming
Procedural programming focuses on the
process/actions that occur in a program.
The program starts at the beginning, does
something, and ends.
Examples: C and Pascal are examples of
languages that follow this paradigm.
• based upon the concept of calling
procedure, routines, subroutines or
functions,
Aysha Safdar, Lecture
r CS, NUML H9 camp
us, Islamabad
Object-Oriented programming
• Object-Oriented programming is based on the data and
the functions that operate on it. Objects are instances
of class that represent the data and its functions
Examples: Java, C++, and Python are popular languages
that support OOP.
• In object-oriented programming, computer programs
are designed
using the concept of objects that interact with the real
world
Aysha Safdar, Lecture
r CS, NUML H9 camp
us, Islamabad
PL vs OOP
Aysha Safdar, Lecture
r CS, NUML H9 camp
us, Islamabad
PL vs OOP
Aysha Safdar, Lecture
r CS, NUML H9 camp
us, Islamabad
OOP Advantages
It allows us to hide implementation details from clients. This makes it easy
Encapsulation
to change internal implementations without affecting the client’s behavior.
Inheritance Allows reuse of existing functionality through inheritance.
Polymorphism Provides flexibility at run time.
Abstraction Makes complex problems look simple.
Modularity Separates concerns such as input/output, presentation, etc.
We can use the same set of codes across multiple projects or even different
Code reusability
programming paradigms like procedural, functional, imperative, etc.
Unit testing becomes much simpler because we don't have to test
Testable
individual components but rather the entire system.
Scalable Objects allow you to add new features easily.
Aysha Safdar, Lecture
r CS, NUML H9 camp
us, Islamabad
Advantages OOP
Because classes are independent units that contain data and
Cross-
functions, they can be used anywhere.
platform
Easier Learning object-oriented concepts is less difficult compared to
learning procedural programming.
curve
When using objects, there is no need to allocate memory for
Better
each variable separately. Instead, all variables share the same
performanc
space.
e
Faster Writing code in an object-oriented style takes less effort than
developmen writing code in a procedural style.
t cycle
Ease of The structure of object-oriented applications tends to remain
maintenanc stable throughout.
e
Aysha Safdar, Lecture
r CS, NUML H9 camp
us, Islamabad
Disadvantages OOP
As mentioned earlier, creating an object requires defining its
state and behaviors. However, not every business process has
these characteristics. Some processes require only a few steps
Complexity
while others involve dozens of steps. Creating an abstract class
with hundreds of methods would result in bloated code.
Since everything is contained within a single file, large files
become very hard to manage. This makes refactoring harder as
Code bloat
well.
Inheriting behavior from another class means inheriting both the
parent's properties and methods. It might cause unexpected
Inheritanc
results since the child class doesn’t necessarily inherit all the
e problems
attributes and methods of the parent class.
Testing an object-oriented program involves verifying whether
Difficulties
the correct output was produced by calling the right number of
in unit
methods. Unit tests usually test individual components rather
testing
than entire systems.
Aysha Safdar, Lecture
r CS, NUML H9 camp
us, Islamabad
Java introduction
• Object oriented
• developed in 1991 by James Gosling at
Sun Microsystems
• released in 1995 as a core component of
Sun Microsystems' Java platform
• Now merged into Oracle Corporation
Aysha Safdar, Lecture
r CS, NUML H9 camp
us, Islamabad
Lexical issues in Java
• Whitespace: In Java, whitespace is a space, tab, or newline.
Each word work as token, no need of indentation
• Identifiers: Identifiers are used for class names, method
names, and variable names. It starts with lowercase,
upercase alphabet and numbers. Not start with number. Java
is case sensitive.
• Comments: (1) single-line( // ) (2) multiline. // //
OR /* and ends with a */
• Literals: A constant value in Java is created by using a literal
representation of it. For example, 100, 98.6 etc
• Keywords: reserved word in language
Aysha Safdar, Lecture
r CS, NUML H9 camp
us, Islamabad
Lexical issues in Java
• Seperator: The most commonly used
separator
Aysha Safdar, Lecture
r CS, NUML H9 camp
us, Islamabad
Lexical issues in Java
• Escape Sequences:
Aysha Safdar, Lecture
r CS, NUML H9 camp
us, Islamabad
OOP Principles
• Data hiding:
Information Hiding is concealing some
information
For example use of access modifiers in C++ (public,
private, protected etc.)
• Encapsulation:
Encapsulation is encapsulating or grouping 1 or
more things (data and operations) together into a
single entity.
Aysha Safdar, Lecture
r CS, NUML H9 camp
us, Islamabad
OOP Principles
• Abstraction
Abstraction is a way of dealing with the
information you want and ignoring the rest (as
good as non-existent for you) from 1 or more items.
• Inheritance
Inheritance is the process of creating new classes,
called derived classes, from existing or base
classes.
• Polymorphism
Different forms
Aysha Safdar, Lecture
r CS, NUML H9 camp
us, Islamabad
Thank You...