Bahria University Karachi Campus
CSC- 210
Object Oriented Programming
Lecturer
Sameena Javaid
[Link]
Bahria University Karachi Campus
LECTURE 1
PROGRAM DESIGN
TECHNIQUES
&
INTRODUCTION TO JAVA
OUTLINE
• Program design techniques
• Programming Overview
• Programming Techniques
• Problem Solving Steps
• Introduction to Java
• Anatomy of Java
• Installation and introduction of Java
Bahria University Karachi Campus
PROGRAM DESIGN TECHNIQUES
Programming
Computer programming (often shortened to programming) is a
process that leads from an original formulation of a computing
problem to executable computer programs.
Programming Techniques / paradigms
Different programming languages support different styles of
programming (called programming paradigms). The choice of
language used is subject to many considerations, such as company
policy, suitability to task, availability of third-party packages, or
individual preference. Ideally, the programming language best
suited for the task at hand will be selected.
Bahria University Karachi Campus
EVOLUTIONS OF PROGRAMMING LANGUAGES
Bahria University Karachi Campus
EVOLUTIONS OF PROGRAMMING LANGUAGES
Bahria University Karachi Campus
EVOLUTIONS OF HIGH LEVEL LANGUAGES
Programming languages have
emerged as the powerful
tools we use to describe
algorithms for execution by
computers. Numerous
languages have been
designed and implemented
with varying goals and for
different application areas.
Evolution of high level
languages considers
unstructured approach to the
present day object-oriented
programming languages.
Bahria University Karachi Campus
EVOLUTIONS OF HIGH LEVEL LANGUAGES
Object-
Oriented
Modular Programming
Programming
Procedural
Structured Programming
Programming
Blocks like “if, if
else, switch, for”
controlled the Emerged in Emerged in
program flow 1990’s
Emerged in 1980’s
Emerged in e.g. C++, Java,
1970’s e.g. Turbo
1960’s .Net
e.g. C, Pascal, Ada
Unstructured e.g. Pascal,
Programming Ada Fortran
Bahria University Karachi Campus
UNSTRUCTURED VS STRUCTURED
UNSTRUCTURED STRUCTURED / PROCEDURAL
Main program directly operates Procedures, Methods or functions
on data call each other
Data is always declared as Data is handled in procedures or
global functions
Duplication of data and Duplication of data and
instructions occurs instructions don’t occurs
Whole logic is written in a single Logic is distributed into modules
module
Difficult to write a program Easy to write a program
Hard to understand and debug Easy to understand and debug a
a program program
Bahria University Karachi Campus
UNSTRUCTURED VS STRUCTURED
UNSTRUCTURED STRUCTURED / PROCEDURAL
Examples: Examples:
Early versions of BASIC (such as MSX
BASIC and GW-BASIC), JOSS, FOCAL, C, Pascal, Ada, Fortran etc.
MUMPS, TELCOMP, COBOL, machine-
level code, early assembler systems
(without procedural metaoperators),
assembler debuggers and some
scripting languages such as MS-DOS
batch file language
Bahria University Karachi Campus
MODULAR PROGRAMMING
• Procedures of a
common functionality
are grouped together
into separate modules.
• The modules can be
linked together to
complete a whole task.
• The main program
coordinates calls to
procedures in separate
modules.
Bahria University Karachi Campus
MODULAR PROGRAMMING (PROBLEMS)
• No matter how well structured, large programs
become excessively complex.
• They allow unrestricted access to global data.
• Attributes and behavior are separated such that they
poorly model of the real world.
Bahria University Karachi Campus
OBJECT ORIENTED PROGRAMMING
• One of the most powerful and popular paradigms
• Includes facilities for modular programming, and (in
some sense) procedural programming.
• A program consists of a collection of cooperating
objects rather than a list of instructions (actions)
• An object combines data structure and its related
operations together
Bahria University Karachi Campus
BENEFITS OF OOP
• Reduced cognitive load (have less to think about
and more natural paradigm)
• Isolation of programmers (better team
programming)
• Less propagation of errors more adaptable/flexible
programs
• Faster development due to reuse of code
Bahria University Karachi Campus
Procedural (Structured) Object-Oriented
Programming
1 Algorithm is given importance. Data is given importance.
2 Can handle up to moderately Can handle very complex programs.
complex programs.
3 Flexibility is less. Flexibility is more.
4 Focus is on algorithm and control Focus is on object model.
flow.
5 Function call is used. Message passing is used.
6 Functions are independent of each Each class is related in a hierarchical
other. manner.
7 Less code reusability More code reusability
8 Less data security More data security
9 Maintenance is costly. Maintenance is relatively cheaper.
Bahria University Karachi Campus
Procedural (Structured) Object-Oriented Programming
10 Views data and functions as two Views data and functions as a single
separate entities. entity.
11 Program is divided into a number Program is organized by having a
of sub modules or functions or number of classes and objects.
procedures.
12 Solution is solution-domain Solution is problem-domain specific.
specific.
13 The flow of execution of the The basic entity is object. Each
programming is dependent on the computation is performed using objects
structure of the program. only.
14 This is top-down approach. This is a bottom-up approach.
Bahria University Karachi Campus
HISTORY OF OOP
• Object programming was reported to exists in Simula 67
back in 1960s
• Simula 67 is developed at the Norwegian Computing
Center in Oslo, by Ole-Johan Dahl and Kristen Nygaard.
• Simula 67 is used to program Simulation
• Influenced from Simula 67, later, the theory of OOP is
introduced by smallTalk (Xerox PARC) which further
designed it to include the pervasive use of objects and
messages as the basis for computation.
• Mid 1980s, OOP dominant the programming methodology
through C++ (an extension of C Language)
• More recently, a number of OOP languages exists
Bahria University Karachi Campus
APPLICATIONS OF OOP
The promising areas for application of OOP includes:
1. Real time systems
2. Simulation and modeling
3. Object oriented databases
4. Hypertext, hypermedia
5. AI and expert systems
6. Neural networks and parallel programming
7. Decision support and office automation systems
8. CIM/CAD systems
Object oriented technology is certainly changing
the way software engineers think, analyze, design
and implement systems today.
Bahria University Karachi Campus
OOP LANGUAGES
• Pure OO Languages
• Smalltalk, Eiffel, Actor, Java, C#, Visual
Basic .NET
• Hybrid OO Languages
• C++, Objective-C, Object-Pascal
Bahria University Karachi Campus
PROBLEM SOLVING USING COMPUTER
Problem solving while using computer is the process of
finding solutions to difficult or complex issues
Bahria University Karachi Campus
PROBLEM SOLVING STEPS
1. Analyze the problem: Outline
solution requirements and
design an algorithm.
2. Implement the algorithm in a
programming language (Java)
and verify that the algorithm
works.
3. Maintain the program: Use and
modify if the problem domain
changes.
Bahria University Karachi Campus
PROBLEM SOLVING STEPS (Execution Cycle)
Bahria University Karachi Campus
PROGRAMMING APPROACHES
STRUCTURED DESIGN OBJECT ORIENTED DESIGN
Problem is divided into smaller Program is a collection of
sub problems interacting objects
Data and operations are at Objects consist of data and
different places operations
Steps in Structured Design: Steps in OOD:
1. Large problem divided into
1. 1. Identify objects
subroutines or subprograms
2. All subprograms are solved 2. Form the basis of the solution
individually
3. Determine how these objects
3. Solved subprograms are
interact
integrated together
Bahria University Karachi Campus
INTRODUCTION TO JAVA
Bahria University Karachi Campus
ORIGINS OF JAVA
• James Gosling, Mike Sheridan, and Patrick Naughton
initiated the Java language project in June 1991
• The language was initially called Oak after an oak
tree that stood outside Gosling's office
• It went by the name Green later, and was later
renamed Java, from a list of random words
• Gosling aimed to implement a virtual machine and a
language that had a familiar C/C++ style of notation
• Sun Microsystems released the first public
implementation as Java 1.0 in 1995
• On May 8, 2007, Sun finished the process, making all
of Java's core code available under free
software/open-source distribution terms (GNU Public
License)
Bahria University Karachi Campus
JAVA FAMILY SUIT
1. Java Standard Edition
(Java SE)
For desktop, client/server
application
2. Java Enterprise Edition
(Java EE)
For e-business, e-commerce
web based application
3. Java Micro Edition
(Java ME)
For small devices, like palm,
hand phone, etc
Bahria University Karachi Campus
JAVA VERSIONS
The following table summarizes all versions of Java SE from its
early days to the latest.
Version Name Code Name Release Date
JDK 1.0 Oak January 1996
JDK 1.1 (none) February 1997
J2SE 1.2 Playground December 1998
J2SE 1.3 Kestrel May 2000
J2SE 1.4 Merlin February 2002
J2SE 5.0 Tiger September 2004
Java SE 6 Mustang December 2006
Java SE 7 Dolphin July 2011
Java SE 8 (Not available) March 2014
Bahria University Karachi Campus
LEADS OF JAVA
• Simple and familiar object oriented
programming
• Architecture neutral (platform independent)
• Open Source
• First rank in TIOBE Index
• De-Facto standard programming language
in education
Bahria University Karachi Campus
TIOBE INDEX
[Link]
Bahria University Karachi Campus
JAVA PROGRAMMING TOOLS
1. Compiler (Interpreter):
Java Standard Edition (JSE)
2. Code Editor:
1. Text Editor:
TextPad, Notepad++
2. Integrated Development Environment
(IDE):
Netbeans, Eclipse, JCreator
Bahria University Karachi Campus
JAVA TRANSLATORS
javac java
(Java Compiler) (Java Interpreter)
Bahria University Karachi Campus
INSTALLATION SETUP
1. Install Java SE by clicking:
[Link]
(download from:
[Link]
oads)
2. Install Netbeans by clicking:
netbeans-8.0.-[Link]
(download from: [Link]
Follow the entire installation process to complete
Bahria University Karachi Campus
HOW JAVA WORKS
public class Hello
{
public static void main(String[] args)
{
[Link]("Hello World!");
}
}
[Link]
Bahria University Karachi Campus