Professional Documents
Culture Documents
CS 201 Object Oriented Programming: Summer 2021
CS 201 Object Oriented Programming: Summer 2021
OBJECT
ORIENTED
PROGRAMMING
Summer 2021
WELCOME
Instructor Info
• Dr. Sadeeq Jan
– Designation
– Chairman CS&IT / Asst. Professor
– Director, National Center for Cyber Security-UETP
– Qualification
– PhD (Security Testing) with Excellent grade – University of Luxembourg
– MS (Info/Comm System Security) with Excellent grade - KTH Sweden
– BSc Engg (Computer Systems Engineering) - UET Peshawar
– IZAZ-E-SABQAT (Presedential Award), Gold Medalist, CGPA 3.98/4.00
• Email: sadeeqjan@uetpeshawar.edu.pk
sadeeqjan@yahoo.com
2
WHY JAVA?
3
POPULAR JAVA IDES
4
A SIMPLE JAVA PROGRAM
5
CREATING AND EDITING USING NOTEPAD
6
CREATING AND EDITING USING WORDPAD
7
CREATING, COMPILING,
AND RUNNING PROGRAMS
Create/Modify Source Code
Result
8
If runtime errors or incorrect result
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
9
animation
TRACE A PROGRAM
EXECUTION
Enter main method
10
animation
TRACE A PROGRAM
EXECUTION
Execute statement
11
animation
TRACE A PROGRAM
EXECUTION
Comments
Reserved words
Modifiers
Statements
Blocks
Classes
Methods
The main method
14
COMMENTS
Three types of comments in Java.
16
MODIFIERS
17
STATEMENTS
18
BLOCKS
19
CLASSES
20
METHODS
21
MAIN METHOD
23
THE SHOWMESSAGEDIALOG
METHOD
JOptionPane.showMessageDialog(null,
"Welcome to Java!",
"Display Message",
JOptionPane.INFORMATION_MESSAGE);
24
TWO WAYS TO INVOKE THE METHOD
There are several ways to use the showMessageDialog
method. For the time being, all you need to know are
two ways to invoke it.
One is to use a statement as shown in the example:
JOptionPane.showMessageDialog(null, x,
y, JOptionPane.INFORMATION_MESSAGE);
where x is a string for the text to be displayed, and y is a
string for the title of the message dialog box.
The other is to use a statement like this:
JOptionPane.showMessageDialog(null, x);
where x is a string for the text to be displayed.
25
JAVA
Primary Motivation
Portability & Platform Independence
Primarily for embedded controllers in consumer electronics
At the same time, WWW was emerging and demanded portable programs
Syntax