CUI Abbottabad: Object Oriented Programming
CUI Abbottabad: Object Oriented Programming
2
Evolution of OOP contd.
Both machine and Assembly languages are machine
dependent.
Next came Procedural Programming Approach which
enabled us to write larger and hundred lines of code.
In 1970, a new programming approach
called Structured Programming approach was
developed for designing medium sized programs.
In 1980's the size of programs kept increasing so a new
approach known as OOP was invented.
3
Difference between OOP approach and
Structured approach
The Structured Programming allows developing a
program using a set of modules or functions.
While Object Oriented Programming allows
constructing a program using a set of objects and their
interactions.
In Object Oriented Programming, Programs are divided
into small entities called objects which is more secure
as having data hiding feature.
Structured Programming is less secure as there is no
way of data hiding.
4
Structured Programming
5
Why Java?
• Java enables users to develop and deploy applications
on the Internet for servers, desktop computers, and
small hand-held devices.
• The future of computing is being profoundly influenced
by the Internet, and Java promises to remain a big part
of that future.
• Desktop applications such as window accessories, web
applications etc.
• Enterprise applications such as Banking, mobile app.
• Embeded systems, Robotics and Games
6
Examples of Java’s Versatility (Applets)
7
PDA and Cell Phone
8
Java’s History
James Gosling and Sun Microsystems
Java, May 20, 1995, Sun World
HotJava
– The first Java-enabled Web browser
Early History Website:
http://java.sun.com/features/1998/05/birthday.html
9
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
www.cs.armstrong.edu/liang/intro8e/JavaCharacteristics.pdf
10
Characteristics of Java
Java Is Simple Java is partially modeled on C++, but greatly
simplified and improved. Some people refer to
Java Is Object-Oriented Java as "C++" because it is like C++ but with
Java Is Distributed more functionality and fewer negative aspects.
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
11
Characteristics of Java
Java Is Simple Java is inherently object-oriented.
Although many object-oriented languages
Java Is Object-Oriented began strictly as procedural languages,
Java Is Distributed Java was designed from the start to be
object-oriented. Object-oriented
Java Is Interpreted programming (OOP) is a popular
Java Is Robust programming approach that is replacing
Java Is Secure traditional procedural programming
techniques.
Java Is Architecture-Neutral
Java Is Portable One of the central issues in software
development is how to reuse code. Object-
Java's Performance oriented programming provides great
Java Is Multithreaded flexibility, modularity, clarity, and
reusability through encapsulation,
Java Is Dynamic inheritance, and polymorphism.
12
Characteristics of Java
Java Is Simple Distributed computing involves several
computers working together on a network.
Java Is Object-Oriented Java is designed to make distributed
Java Is Distributed computing easy. Since networking
capability is inherently integrated into
Java Is Interpreted Java, writing network programs is like
Java Is Robust sending and receiving data to and from a
Java Is Secure file.
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
13
Characteristics of Java
Java Is Simple You need an interpreter to run Java
programs. The programs are compiled into
Java Is Object-Oriented the Java Virtual Machine code called
Java Is Distributed bytecode. The bytecode is machine-
independent and can run on any machine
Java Is Interpreted that has a Java interpreter, which is part of
Java Is Robust the Java Virtual Machine (JVM).
Java Is Secure
Java Is Architecture-Neutral
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
14
Characteristics of Java
Java Is Simple Java compilers can detect many problems
that would first show up at execution time
Java Is Object-Oriented in other languages.
Java Is Distributed
Java has eliminated certain types of error-
Java Is Interpreted prone programming constructs found in
Java Is Robust other languages.
Java Is Secure
Java has a runtime exception-handling
Java Is Architecture-Neutral feature to provide programming support
Java Is Portable for robustness.
Java's Performance
Java Is Multithreaded
Java Is Dynamic
15
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java implements several security
Java Is Interpreted mechanisms to protect your system against
Java Is Robust harm caused by stray programs.
Java Is Secure
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
16
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Portable
Java's Performance
Java Is Multithreaded
Java Is Dynamic
17
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Portable Write once, run anywhere
Java's Performance With a Java Virtual Machine (JVM),
Java Is Multithreaded you can write one program that will
run on any platform.
Java Is Dynamic
18
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Portable
Java's Performance Java’s performance Because Java is
architecture neutral, Java programs
Java Is Multithreaded are portable. They can be run on any
Java Is Dynamic platform without being recompiled.
19
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Portable
Java's Performance
Java Is Multithreaded Multithread programming is smoothly
Java Is Dynamic integrated in Java, whereas in other
languages you have to call procedures
specific to the operating system to enable
multithreading.
20
Characteristics of Java
Java Is Simple
Java Is Object-Oriented
Java Is Distributed
Java Is Interpreted
Java Is Robust
Java Is Secure
Java Is Portable
Java's Performance
Java Is Multithreaded Java was designed to adapt to an evolving
environment. New code can be loaded on the
Java Is Dynamic fly without recompilation. There is no need for
developers to create, and for users to install,
major new software versions. New features can
be incorporated transparently as needed.
21
JDK Versions
JDK 1.02 (1995)
JDK 1.1 (1996)
JDK 1.2 (1998)
JDK 1.3 (2000)
JDK 1.4 (2002)
JDK 1.5 (2004) a. k. a. JDK 5 or Java 5
JDK 1.6 (2006) a. k. a. JDK 6 or Java 6
JDK 1.7 (possibly 2010) a. k. a. JDK 7 or Java 7
JDK 1.8 and above
22
JDK Editions
Java Standard Edition (J2SE)
– J2SE can be used to develop client-side standalone
applications or applets.
Java Enterprise Edition (J2EE)
– J2EE can be used to develop server-side applications
such as Java servlets and Java ServerPages.
Java Micro Edition (J2ME).
– J2ME can be used to develop applications for mobile
devices such as cell phones.
23
Popular Java IDEs
NetBeans Open Source by Sun
Eclipse Open Source by IBM
TextPad (Any latest ver)
24
A Simple Java Program (TextPad)
25
Creating and Editing Using NotePad
26
Creating, Compiling, and
Running Programs
Create/Modify Source Code
Result
Java Virtual
Machine
Any
Computer
28
Trace a Program Execution
Enter main method
29
Trace a Program Execution
Execute statement
30
Trace a Program Execution
31