java lesson3

advertisement
Java Programming Language
LESSON 3 (loops,break,continue,oop)
Hayk Avdalyan
Do While Loop
A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to
execute at least one time.
Hayk Avdalyan
For-Each loop
Hayk Avdalyan
break statement
The break statement in Java programming language has the following two usages:
1.
When the break statement is encountered inside a loop, the loop is immediately terminated
and program control resumes at the next statement following the loop.
2.
It can be used to terminate a case in the switch statement
Hayk Avdalyan
continue statement
The continue keyword can be used in any of the loop control structures. It causes the loop to
immediately jump to the next iteration of the loop.
1.
In a for loop, the continue keyword causes control to immediately jump to the update
statement.
2.
In a while loop or do/while loop, control immediately jumps to the Boolean expression.
Hayk Avdalyan
Object Oriented Programming
Objects
Real-world object.
Classes
•
variables (also called fields)
•
methods (or functions)
Hayk Avdalyan
Controlling Access to Members of a Class
1) Visible to the package. the default. No modifiers are needed.
2) Visible to the class only (private).
3) Visible to the world (public).
4) Visible to the package and all subclasses (protected).
Hayk Avdalyan
Variables
“Modifier” “type” “name”;
or
“Modifier” “type” “name” = “value”;
Hayk Avdalyan
Methods
Define a Method:
“Modifier” “return value type” “name” (“params”){
Method body
}
Hayk Avdalyan
Tasks
Create Logical Structures (As big as possible) from your life and print them in main function.
Hayk Avdalyan
Download