CSC103-Programming Fundamentals: Introduction To Java Lecture-5
CSC103-Programming Fundamentals: Introduction To Java Lecture-5
Introduction to Java
Lecture-5
Instructors
Dr. Manzoor Illahi Tamimi, Dr.Behjat Zuhaira, Ms. Saadia Maqbool and Mr. Rizwan Rashid
Lecture Outline
• About Java
• Installing Java
• Features of Java
• A Simple Java Program
• Anatomy of a Java Program
• Creating, Compiling, and Running Programs
• Programming Style and Documentation
• Programming Errors
About Java
• Java is a powerful and versatile programming
language for developing software running on
mobile devices, desktop computers, and
servers
• Developed by James Gosling in 1995
• Popular because of write a program once and
run it anywhere
JDK Editions
p
ubl
iccla
ssTes
t{
pu
bli
cstat
icvoi
dmain
(St
ring
[]a
rgs
){ C
la
ssb
loc
k
Sys
tem
.ou
t.p
rin
tln
("W
elc
ometoJ
ava
!")
;Me
tho
dblo
ck
}
}
Special Symbols
" " Opening and closing Enclosing a string (i.e., sequence of characters).
quotation marks
; Semicolon Marks the end of a statement.
Creating, Compiling, and
Running Programs
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.
Programming Style and
Documentation
• Appropriate Comments
• Naming Conventions
• Proper Indentation and Spacing Lines
• Block Styles
Appropriate Comments
Include a summary at the beginning of the
program to explain what the program does, its key
features, its supporting data structures, and any
unique techniques it uses.
• Spacing
– Use blank line to separate segments of the code.
Block Styles
A block is a group of statements surrounded by braces. There are two popular
styles, next-line style and end-of-line style
N e
xt-lin
e p
ubl
iccla
ssTes
t
sty
le {
pu
bli
cstat
icvoi
dmain
(St
rin
g[]ar
gs)
{
Sys
tem
.ou
t.p
rin
tln
("B
loc
kStyl
es"
);
}
}
E n
d-of-lin
e
sty
le
p
ubl
iccla
ssTes
t{
pu
bli
cstat
icvoi
dmain
(St
rin
g[]ar
gs){
Sys
tem
.ou
t.p
rin
tln
("B
loc
kStyl
es"
);
}
}
Programming Errors
• Syntax Errors
– Detected by the compiler
• Runtime Errors
– Causes the program to abort
– System.out.println(1 / 0);
• Logic Errors
– Produces incorrect result
Summary
• Features of Java
• Parts of a simple Java Program
• How to write, compile and run a Java Program
• Program Documentation
• Program Errors
Next Lecture
• Simple Computation in Java Program
• Obtaining Input from Console
• Identifiers to name variables, constants,
methods, and classes
• Java Numeric Primitive Data types