SlideShare a Scribd company logo
2. Programming with
Java Statements
• Understanding Assignment Statements
• Understanding Conditional Statements
• Understanding Iteration Statements
• Understanding Transfer of Control Statements
By Fernando Gil
Date: Jan 2015
Version: 1.0
Based in the book OCA Java SE 7 Programmer I Study Guide (Examn 1Z0-803)
1. Understanding Assignment
Statements
• An assignment statement sets a value within a variable
• All assignment are considered to be expression statements
• Expressions in Java are anything that has a value
• Typically, expressions evaluate to primitive types
Expression
Statement
Example
Assignment variable = 7
Pre-increment ++variable;
Pre-decrement --variable;
Post-increment variable++;
Post-decrement variable--;
Method invocation variable = performMethod();
Object creation variable = new ClassName();
The Assignment Expression
Statements
• Commonly known simply as assignment statements, are
designed to assign values to variables and must be
terminated with a semicolon
Variable = value;
• On the left is the variable that will be associated with the
memory and type necessary to store the value. On the
right is a literal value.
2. Understanding Conditional
Statements
• Conditional statements are used when there is a need for
determining the direction of flow based on conditions
The if conditional Statement
• The if statement is designed to conditionally execute a
statement or conditionally decide between a choice of
statements
• The if statement will execute only one statement upon the
condition, unless braces are supplied. Braces allow for
multiple enclosed statements to be executed. This group
of statements is also known as a block
• The expression that is evaluated within if statements must
evaluate to a boolean value
• The else clause is optional and may be omitted
 OCA JAVA - 2 Programming with Java Statements
The if-then conditional
Statement
• The if-then statement is used when multiple conditions
need to flow through a decision-based scenario
The if-then-else conditional
Statement
• The main difference is that the code will fall through to the
final stand-alone else when the expression fails to return
true for any condition
The switch conditional
Statement
• It is used to match the value from a switch statement
expression against a value associated with a case
keyword. Once matched, the enclosed statements
associated with the matching case value are executed,
unless a break statement is encountered
• The break statements are
optional and will cause the
immediate termination of the
switch conditional statement
• The expression of the switch
statement must evaluate to byte,
short, int, char, string
 OCA JAVA - 2 Programming with Java Statements
3. Understanding Iteration
Statements
• Iteration statements are used when there is a need to
iterate through pieces of code
• Iteration statements include for loop, enhanced for loop,
and the while and do-while statements.
• The continue statement is used to terminate the current
iteration and continue with the next iteration
• The break statement is used to exit the body of any
iteration statement
The for loop Iteration
Statement
• It has many parts that include an initialization part, an
expression part, and an iteration part
• The initialization does not need to declare a variable as
long as the variable is declared before the for statement.
So int x=0 and x=0 are both acceptable
• The expression within the for loop must be evaluated to a
boolean value
• The iteration, also known as the update part, provides the
mechanism that will allow the iteration to occur
 OCA JAVA - 2 Programming with Java Statements
The enhanced for loop
Iteration Statement
• It is used to iterate through an array, a collection, or an
object that implements the interface iterable.
• It is also commonly known as the for each loop
• Here is the general usage of the for each statement:
for (type variable : collection)
The while Iteration Statement
• This loop evaluates an expression and executes the loop
body only if the expression evaluates to true
• There is typically an expression within the body that will
affect the result of the expression
The do-while Iteration
Statement
• It is very similar to the while loop, except that it always
executes the body at least once
• The do-while loop evaluates an expression and continues
to execute the body only if it evaluates to true
4. Understanding Transfer of
Control Statements
• The transfer of control statements provide a means to stop
or interrupt the normal flow of control
• They are always used within other types of statements
• Transfer of control statements include the break, continue
and return statements
The break Transfer of Control
Statement
• It is used to exit or force an abrupt termination of the body
of the conditional and iteration statements
The continue Transfer of
Control Statement
• It is used to terminate the current iteration of a loop and
continue with the next iteration
The return Transfer of Control
Statement
• It is used to exit a method and optionally return a specified
value as an expression
• A return statement with no return value must have the
keyword void in the method declaration
Knowing your Statement-Related
keywords
3. Programming with
Java Operators
Next Slide:

More Related Content

PPTX
Control statements in Java
PDF
itft-Decision making and branching in java
PDF
Control structures in Java
PPSX
Control Structures in Visual Basic
PPTX
Control Statements in Java
PPTX
If and select statement
PPT
Control structures i
PPTX
Control statements in java
Control statements in Java
itft-Decision making and branching in java
Control structures in Java
Control Structures in Visual Basic
Control Statements in Java
If and select statement
Control structures i
Control statements in java

What's hot (20)

PPTX
Chapter 2 : Programming with Java Statements
PPTX
Decision statements in vb.net
PPT
Control structures selection
PPS
Control statements
PPT
Control Structures: Part 1
PPT
Control structures ii
PDF
10. switch case
PPTX
Switch Case in C Programming
PPTX
Conditional statement in c
PPT
04 control structures 1
PPTX
Week 1: Getting Your Hands Dirty - Part 1
DOCX
PPTX
The Switch Statement in java
PDF
Bt0067 c programming and data structures 1
PPTX
Week 2: Getting Your Hands Dirty – Part 2
PPT
Template method pattern example
PPTX
Python operators part3
PPT
Template Method Pattern
PPT
PL/SQL Example for IF .. ELSIF
Chapter 2 : Programming with Java Statements
Decision statements in vb.net
Control structures selection
Control statements
Control Structures: Part 1
Control structures ii
10. switch case
Switch Case in C Programming
Conditional statement in c
04 control structures 1
Week 1: Getting Your Hands Dirty - Part 1
The Switch Statement in java
Bt0067 c programming and data structures 1
Week 2: Getting Your Hands Dirty – Part 2
Template method pattern example
Python operators part3
Template Method Pattern
PL/SQL Example for IF .. ELSIF
Ad

Viewers also liked (13)

PDF
TXT
Ass2 1 (2)
PPTX
Java ocjp level_2
DOCX
Quiz test JDBC
PPTX
OCA JAVA - 3 Programming with Java Operators
PPTX
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
PPT
how to calclute time complexity of algortihm
PDF
Cracking OCA and OCP Java 8 Exams
PDF
Design & Analysis Of Algorithm
PPT
DESIGN AND ANALYSIS OF ALGORITHMS
PPTX
Design and Analysis of Algorithms
PDF
Study: The Future of VR, AR and Self-Driving Cars
PDF
TEDx Manchester: AI & The Future of Work
Ass2 1 (2)
Java ocjp level_2
Quiz test JDBC
OCA JAVA - 3 Programming with Java Operators
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
how to calclute time complexity of algortihm
Cracking OCA and OCP Java 8 Exams
Design & Analysis Of Algorithm
DESIGN AND ANALYSIS OF ALGORITHMS
Design and Analysis of Algorithms
Study: The Future of VR, AR and Self-Driving Cars
TEDx Manchester: AI & The Future of Work
Ad

Similar to OCA JAVA - 2 Programming with Java Statements (20)

PPT
05. Control Structures.ppt
PDF
data types.pdf
PDF
Lecture 7 Control Statements.pdf
PPT
_Java__Expressions__and__FlowControl.ppt
PPT
_Java__Expressions__and__FlowControl.ppt
PPT
Lecture-13.ppt
PPTX
Java 2.pptx
PPTX
Java Control Statement Control Statement.pptx
PPT
Control structure
PPTX
Flow of control C ++ By TANUJ
PPTX
presentation on powerpoint template.pptx
PPTX
Presentation on C Switch Case Statements
PPTX
Chapter05-Control Structures.pptx
PPTX
While , For , Do-While Loop
PDF
PPT
control-statements....ppt - definition
PDF
Control statements anil
PPTX
Java Exception Handling
PPTX
Week 4.pptx computational thinking and programming
05. Control Structures.ppt
data types.pdf
Lecture 7 Control Statements.pdf
_Java__Expressions__and__FlowControl.ppt
_Java__Expressions__and__FlowControl.ppt
Lecture-13.ppt
Java 2.pptx
Java Control Statement Control Statement.pptx
Control structure
Flow of control C ++ By TANUJ
presentation on powerpoint template.pptx
Presentation on C Switch Case Statements
Chapter05-Control Structures.pptx
While , For , Do-While Loop
control-statements....ppt - definition
Control statements anil
Java Exception Handling
Week 4.pptx computational thinking and programming

Recently uploaded (20)

PPTX
Materi-Enum-and-Record-Data-Type (1).pptx
PDF
Community & News Update Q2 Meet Up 2025
PPTX
Odoo Consulting Services by CandidRoot Solutions
PPTX
AIRLINE PRICE API | FLIGHT API COST |
PPTX
Hire Expert WordPress Developers from Brainwings Infotech
PDF
Become an Agentblazer Champion Challenge Kickoff
PDF
How to Choose the Most Effective Social Media Agency in Bangalore.pdf
PPTX
Hire Expert Blazor Developers | Scalable Solutions by OnestopDA
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
A REACT POMODORO TIMER WEB APPLICATION.pdf
PDF
Forouzan Book Information Security Chaper - 1
PPTX
10 Hidden App Development Costs That Can Sink Your Startup.pptx
PDF
Build Multi-agent using Agent Development Kit
PPTX
Benefits of DCCM for Genesys Contact Center
DOCX
The Future of Smart Factories Why Embedded Analytics Leads the Way
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
PDF
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
PDF
Best Smart Port Software of 2025 Why Envision Leads the Market.pdf
PDF
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK
Materi-Enum-and-Record-Data-Type (1).pptx
Community & News Update Q2 Meet Up 2025
Odoo Consulting Services by CandidRoot Solutions
AIRLINE PRICE API | FLIGHT API COST |
Hire Expert WordPress Developers from Brainwings Infotech
Become an Agentblazer Champion Challenge Kickoff
How to Choose the Most Effective Social Media Agency in Bangalore.pdf
Hire Expert Blazor Developers | Scalable Solutions by OnestopDA
How Creative Agencies Leverage Project Management Software.pdf
A REACT POMODORO TIMER WEB APPLICATION.pdf
Forouzan Book Information Security Chaper - 1
10 Hidden App Development Costs That Can Sink Your Startup.pptx
Build Multi-agent using Agent Development Kit
Benefits of DCCM for Genesys Contact Center
The Future of Smart Factories Why Embedded Analytics Leads the Way
2025 Textile ERP Trends: SAP, Odoo & Oracle
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Best Smart Port Software of 2025 Why Envision Leads the Market.pdf
IEEE-CS Tech Predictions, SWEBOK and Quantum Software: Towards Q-SWEBOK

OCA JAVA - 2 Programming with Java Statements

  • 1. 2. Programming with Java Statements • Understanding Assignment Statements • Understanding Conditional Statements • Understanding Iteration Statements • Understanding Transfer of Control Statements By Fernando Gil Date: Jan 2015 Version: 1.0 Based in the book OCA Java SE 7 Programmer I Study Guide (Examn 1Z0-803)
  • 2. 1. Understanding Assignment Statements • An assignment statement sets a value within a variable • All assignment are considered to be expression statements • Expressions in Java are anything that has a value • Typically, expressions evaluate to primitive types Expression Statement Example Assignment variable = 7 Pre-increment ++variable; Pre-decrement --variable; Post-increment variable++; Post-decrement variable--; Method invocation variable = performMethod(); Object creation variable = new ClassName();
  • 3. The Assignment Expression Statements • Commonly known simply as assignment statements, are designed to assign values to variables and must be terminated with a semicolon Variable = value; • On the left is the variable that will be associated with the memory and type necessary to store the value. On the right is a literal value.
  • 4. 2. Understanding Conditional Statements • Conditional statements are used when there is a need for determining the direction of flow based on conditions
  • 5. The if conditional Statement • The if statement is designed to conditionally execute a statement or conditionally decide between a choice of statements • The if statement will execute only one statement upon the condition, unless braces are supplied. Braces allow for multiple enclosed statements to be executed. This group of statements is also known as a block • The expression that is evaluated within if statements must evaluate to a boolean value • The else clause is optional and may be omitted
  • 7. The if-then conditional Statement • The if-then statement is used when multiple conditions need to flow through a decision-based scenario
  • 8. The if-then-else conditional Statement • The main difference is that the code will fall through to the final stand-alone else when the expression fails to return true for any condition
  • 9. The switch conditional Statement • It is used to match the value from a switch statement expression against a value associated with a case keyword. Once matched, the enclosed statements associated with the matching case value are executed, unless a break statement is encountered • The break statements are optional and will cause the immediate termination of the switch conditional statement • The expression of the switch statement must evaluate to byte, short, int, char, string
  • 11. 3. Understanding Iteration Statements • Iteration statements are used when there is a need to iterate through pieces of code • Iteration statements include for loop, enhanced for loop, and the while and do-while statements. • The continue statement is used to terminate the current iteration and continue with the next iteration • The break statement is used to exit the body of any iteration statement
  • 12. The for loop Iteration Statement • It has many parts that include an initialization part, an expression part, and an iteration part • The initialization does not need to declare a variable as long as the variable is declared before the for statement. So int x=0 and x=0 are both acceptable • The expression within the for loop must be evaluated to a boolean value • The iteration, also known as the update part, provides the mechanism that will allow the iteration to occur
  • 14. The enhanced for loop Iteration Statement • It is used to iterate through an array, a collection, or an object that implements the interface iterable. • It is also commonly known as the for each loop • Here is the general usage of the for each statement: for (type variable : collection)
  • 15. The while Iteration Statement • This loop evaluates an expression and executes the loop body only if the expression evaluates to true • There is typically an expression within the body that will affect the result of the expression
  • 16. The do-while Iteration Statement • It is very similar to the while loop, except that it always executes the body at least once • The do-while loop evaluates an expression and continues to execute the body only if it evaluates to true
  • 17. 4. Understanding Transfer of Control Statements • The transfer of control statements provide a means to stop or interrupt the normal flow of control • They are always used within other types of statements • Transfer of control statements include the break, continue and return statements
  • 18. The break Transfer of Control Statement • It is used to exit or force an abrupt termination of the body of the conditional and iteration statements
  • 19. The continue Transfer of Control Statement • It is used to terminate the current iteration of a loop and continue with the next iteration
  • 20. The return Transfer of Control Statement • It is used to exit a method and optionally return a specified value as an expression • A return statement with no return value must have the keyword void in the method declaration
  • 22. 3. Programming with Java Operators Next Slide: