0% found this document useful (0 votes)
33 views31 pages

CUI Abbottabad: Object Oriented Programming

Uploaded by

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

CUI Abbottabad: Object Oriented Programming

Uploaded by

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

CUI Abbottabad

Department of Computer Science

Object Oriented Programming


Lecture No. 1
Introduction to OOP

COMSATS University Islamabad, Abbottabad Campus


Evolution of OOP
 OOP is being used for designing large and complex
applications.
 Before OOP many programming approaches existed
which had many drawbacks. These programming
approaches have been passing through revolutionary
phases.
 Initially for designing small and simple programs,
the machine language was used.
 Next came the Assembly Language which was used
for designing larger programs.

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

 Object Oriented 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

Source code (developed by the programmer)


Saved on the disk
public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!"); Source Code
}
}

Compile Source Code


Byte code (generated by the compiler for JVM i.e., javac Welcome.java
to read and interpret, not for you to understand)

Method Welcome() If compilation errors
0 aload_0 stored on the disk

Bytecode
Method void main(java.lang.String[])
0 getstatic #2 …
3 ldc #3 <String "Welcome to
Java!">
5 invokevirtual #4 …
8 return Run Byteode
i.e., java Welcome

Result

If runtime errors or incorrect result 27


Compiling Java Source Code
You can port a source program to any machine with appropriate
compilers. The source program must be recompiled, however, because
the object program can only run on a specific machine. Nowadays
computers are networked to work together. Java was designed to run
object programs on any platform. With Java, you write the program
once, and compile the source program into a special type of object
code, known as bytecode. The bytecode can then run on any computer
with a Java Virtual Machine, as shown below. Java Virtual Machine is
a software that interprets Java bytecode.
Java Bytecode

Java Virtual
Machine

Any
Computer

28
Trace a Program Execution
Enter main method

//This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

29
Trace a Program Execution
Execute statement

//This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

30
Trace a Program Execution

//This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

print a message to the


console

31

You might also like