Lecture 2
Lecture 2
Introduction to java
Lecture 2
Kandahar University
Faculty of Computer Science
Zubair Ahmad “Khairy”
1
+ 2
Today’s Lecture
◼ Control Statements
◼ Java If-else
◼ Java Switch
◼ Loops
◼ Java For Loop
◼ Java While Loop
◼ Java Do While Loop
◼ Java Break
◼ Java Continue
◼ Arrays
◼ Question
+ 3
If-else statements
◼ Syntax:
+ 4
Switch Statement
◼ Syntax:
+ 5
Nested Switch
+ 6
Loops in Java
◼ for loop
◼ while loop
◼ do-while loop
+ 7
For Loop
for-each Loop
◼ We can use Java break statement in all types of loops such as for
loop, while loop and do-while loop.
+ 16
Break Statement
+ 17
◼ We can use Java continue statement in all types of loops such as for
loop, while loop and do-while loop.
18
+ 19
Java Arrays
Java Arrays
◼ Advantages
◼ Code Optimization: It makes the code optimized, we can
retrieve or sort the data efficiently.
◼ Random access: We can get any data located at an index
position.
◼ Disadvantages
◼ Size Limit: We can store only the fixed size of elements in the
array. It doesn't grow its size at runtime. To solve this problem,
collection framework is used in Java which grows automatically.
+ 21
◼ Multidimensional Array
+ 22
Single Dimensional
+ 23
Multidimensional Array
Jagged array