Java Fundamentals For Android Development
Java Fundamentals For Android Development
Lesson 1
Java Overview
Control Flow
Control Flow
Decision-making statements
if-then
if-then-else
Switch
Looping statements
for
While
do-while
Branching statements
break
continue
return
Control Flow
The If-then Statement
It tells your program to execute a certain section of code
only if a particular test evaluates to true.
void stopCar() {
// the "if" clause: car must be stopped
if (isMoving) {
// the "then" clause must stop car
isMoving = false;
}
}
Control Flow
The If-then Statement
The opening and closing braces are optional, provided
that the "then" clause contains only one statement:
void stopCar() {
// same as above, but without braces
if (isMoving)
isMoving = false;
}
Control Flow
The If-then-else Statement
Provides a secondary path of execution when an "if"
clause evaluates to false.
void stopCar() {
if (isMoving) {
isMoving = false;
} else {
System.err.println("The car has already stopped!");
}
}
Control Flow
The Switch Statement
Unlike if-then and if-then-else statements, the switch
statement can have a number of possible execution
paths.
Works with the byte, short, char, and int primitive data
types.
It also works with enumerated types, the String class,
and special classes that wrap certain primitive types:
Character, Byte, Short, and Integer.
Control Flow
The Switch Statement
int month = 8;
switch (month) {
case 1: futureMonths.add("January");
case 2: futureMonths.add("February");
case 3: futureMonths.add("March");
case 4: futureMonths.add("April");
case 5: futureMonths.add("May");
break;
default: break;
}
Control Flow
The while and do-while Statements
Continually executes a block of statements while a
particular condition is true. Its syntax can be expressed
as:
while (expression) {
statement(s)
}
do {
statement(s)
} while (expression);
break
continue
return
Control Flow
The for Statement
The for statement provides a compact way to iterate over
a range of values.
Count is: 10
References
https://www.tutorialspoint.com/java/java_quick_guide.htm
https://docs.oracle.com/javase/tutorial/java/data/strings.html
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op2.html
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/flowsummary.html
https://docs.oracle.com/javase/tutorial/java/javaOO/classdecl.html
https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html