Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Computer Programming II

Lecture 3
Object-Oriented Programming in Java

You learned:

● Data - Declarations, Assignment and Initialization


● Variables and Constants
● Object References
● Uninitialized Objects
● Renaming Objects
● Data Types
● Wrapper Classes
● Type Conversion
Object-Oriented Programming in Java

You’ll learn:

● Control Statements
○ Expressions
○ Statements
○ Selection
○ Repetition
○ For Loops in Java
○ While Loops in Java
○ Continuous Loops and the Break Statement
Expressions

An expression in the context of computer programming languages is a formula. As such, expressions are
composed of one or more operands whose values are combined by operators.

Example numA + (2 * numB)

operand1 < 50

operand2 == 0

operand3 >= 10 & operand3 <= 20

operand3 < 10 | operand3 > 20


Evaluation

operand1 & operand2 ; will return false if operand1 is false regardless of the value of operand2

operand1 | operand2 ; will return true if operand1 is true regardless of the value of operand2

operand1 && operand2

operand1 || operand2
Statements

Statements are the commands in a language that perform actions and change the state of an object.

1. Assignment - changes the value (state) of a field.


2. Method calls - causes a method to be performed.
3. I/O (Input/Output) - statements to control input and output
4. Selection - choices between alternative statements or groups of statements to be performed.
5. Repetition - perform a certain statement or group of statements in an iterative manner until some
end condition is met.
6. Exception - detect and react to some unusual circumstance.
Selection

Choice points into flow of control path so that we can have several paths going through
a program

1. If-else statements

2. Switch statements
If-else Statements

An if-else statement, sometimes referred to as a conditional, can be used in two forms.


The first is often referred to as a linear if:
If-else Statements
If-else Statements
Switch Statements
Repetition
Fixed count loops - repeat a predefined number of times (i.e. defined prior to
compilation/interpretation).

Variable count loops (also sometimes referred to as conditional loops) - repeat an


unspecified number of times.
Repetition - Pre-test and Post-test Loops
Repetition - For Loops in Java
Repetition - For Loops in Java
Repetition - While Loops in Java
Repetition - Continue and the Break Statement

You might also like