Lecture 1 Intro To Java
Lecture 1 Intro To Java
Lecture 1 Intro To Java
Programming
Lecture 1
BSCS 2(Afternoon)
Spring 2024
sqayuum@numl.edu.pk
Topics to be covered according to
outline
Recommended Books
Theory Marks
Midterm Examination 25
Final Examination 50
IE (Assignments / Quizzes) 25
total = 100
Revision
• Variables
• String in C/C++ ?
• Arrays
• 1D
• 2D
• ND
Revision
• Functions / Methods
• Declaration
• Definition
• Calling
• Overloading
• Passing Arguments
• By Value
• By reference in java ?
Programming Paradigms
Programming Paradigms
In procedural programming, the program is divided into small In object-oriented programming, the program is divided into
parts called functions. small parts called objects.
Procedural programming follows a top-down approach. Object-oriented programming follows a bottom-up approach.
There is no access specifier in procedural programming. Object-oriented programming has access specifiers like
private, public, protected, etc.
Adding new data and functions is not easy. Adding new data and function is easy.
Procedural programming does not have any proper way of Object-oriented programming provides data hiding so it
hiding data so it is less secure. is more secure.
In procedural programming, the function is more important In object-oriented programming, data is more important than
than the data. function.
Procedural programming is based on the unreal world. Object-oriented programming is based on the real world.
Procedural programming is used for designing medium-sized Object-oriented programming is used for designing large and
programs. complex programs.
Procedural programming uses the concept of procedure Object-oriented programming uses the concept of data
abstraction. abstraction.
Code reusability absent in procedural programming, Code reusability present in object-oriented programming.
Examples: C, FORTRAN, Pascal, Basic, etc. Examples: C++, Java, Python, C#, etc.
Advantages of OOP
Encapsulati It allows us to hide implementation details from clients. This makes it easy to
on change internal implementations without affecting the client’s behavior.
Code We can use the same set of codes across multiple projects or even different
reusability programming paradigms like procedural, functional, imperative, etc.
Testable Unit testing becomes much simpler because we don't have to test individual
components but rather the entire system.
Maintainabl Classes provide encapsulated states so they're more maintainable than traditional
e modules.
Cross-platform Because classes are independent units that contain data and
functions, they can be used anywhere.
Easy Debugging an application written in an object-oriented language is
debugging easier than one written in a nonobject-oriented language.
Easier learning Learning object-oriented concepts is less difficult compared to
curve procedural programming.
Fewer bugs Bugs tend to occur when developers try to write too many lines of
code instead of writing them correctly.
Better When using objects, there is no need to allocate memory for each
performance variable separately. Instead, all variables share the same space.
Faster Writing code in an object-oriented style takes less effort than writing
development code in a procedural style.
cycle
Ease of The structure of object-oriented applications tends to remain stable
maintenance throughout.
Disadvantages of OOP
As mentioned earlier, creating an object requires defining its state and
behaviors. However, not every business process has these
Complexity characteristics. Some processes require only a few steps while others
involve dozens of steps. Creating an abstract class with hundreds of
methods would result in bloated code.
Code bloat Since everything is contained within a single file, large files become
very hard to manage. This makes refactoring harder as well.
• whitespace
• identifiers
• comments
• literals
• operators
• separators
• keywords
Whitespaces
• Java is a free-form language. This means that you do not need to
follow any special indentation rules.
• For example
• the Example program could have been written all on oneline or in any
other strange way you felt like typing it, as long as there was at least
onewhitespace character between each token that was not already
delineated by an operatoror separator.
• In Java, whitespace is a space, tab, or newline.
Identifiers
• Identifiers are used for class names, method names, and variable
names.
• An identifier may be any descriptive sequence of uppercase and
lowercase letters, numbers, or the underscore and dollar-sign
characters.
• They must not begin with a number, lest they be confused with a
numeric literal
• Java is case-sensitive, so VALUE is a different identifier
than Value.
Identifiers
• Some examples of valid identifiers are:
• HighTemp
• temp
• h8
• $low
• this_is_ok
• Invalid variable names include:
• 2temp
• low-temp
• Yes/ok
Comments
OR
/* and ends with a */
Literals
• A constant value in Java is created by using a literal representation
of it. For example,
• here are some literals:
• Data hiding
• Abstraction
• Encapsulation
• Inheritance
• Polymorphism
Object Oriented Programming
Data hiding
Information Hiding is concealing some information
For example use of access modifiers in C++ (public,
private, protected etc.) hides some data.
Encapsulation
Encapsulation is encapsulating or grouping 1 or more
things (data and operations) together into a single
entity.
Don’t mistake this with information hiding, all the data
encapsulated need not be hidden.
Object Oriented Programming
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
OOP Concepts
• Classes
• Objects
• Instance
• Method
• Message Parsing
Questions are Welcome