SlideShare a Scribd company logo
1
 Lecture 3 will introduce conditional statements that allow choices
between different actions to be made within methods. Local
variables in methods will be presented as well to let us differentiate
it from global variables later on.
2
 To learn Boolean types and operators
 To implement conditional statements using if .. else statement
 To learn how to make choices in everyday life, make choices
in Java, and make a choice in the ticket machine
 To know the meaning of scope and lifetime
 To learn about variable types and how can we differentiate
them from local variables that are used in methods
 To learn about arithmetic operator precedence
3
 Boolean expressions have only two possible values: true and
false.
 They are commonly found controlling the choice between the two
paths through a conditional statement.
 Java provides six comparison operators (also known as relational
operators) that can be used to compare two values.
boolean b = (1 > 2);
4
Operator Name
< less than
<= less than or equal to
> greater than
>= greater than or equal to
== equal to
!= not equal to
5
Operator Name
! not
&& and
|| or
^ exclusive or
6
 A conditional statement takes one of two possible actions based
upon the result of a test.
 There are two types of conditional statements in Java. They are:
◦ if statements
◦ switch statements
 Make choices in Java:
7
 The if statement (one-way if statement):
◦ An if statement consists of a Boolean expression followed by one
or more statements.
 The syntax of an if statement is:
if(Boolean_expression)
{
//Statements will execute if the Boolean expression is true
}
◦ If the Boolean expression evaluates to true then the block of code inside
the if statement will be executed.
◦ If not the first set of code after the end of the if statement (after the
closing curly brace) will be executed.
8
Example:
9
Boolean
Expression
true
Statement(s)
false
(radius >= 0)
true
area = radius * radius * PI;
System.out.println("The area for the circle of " +
"radius " + radius + " is " + area);
false
(A) (B)
Example:
10
Explanation:
 public is the visibility. This can be public, private or default (if you omit
a value).
 static is a special [optional] keyword that indicates that this method can
be called without creating an instance of this class. Without it, you have
to instantiate this class and call this method from the resulting object.
 void is the return type of this method, indicating that this method
doesn't return anything. Methods must have a return type.
 main( ... ) is the name of this method. Methods have to be named. The
parentheses indicate that this is a method.
 String[] args is a single parameter for the method. String[] is the type
of the parameter, indicating an array of Strings. args is the name of the
parameter. Parameters must be named.
11
 The if...else statement (two-way if statement):
◦ An if statement can be followed by an optional else statement, which
executes when the Boolean expression is false.
 The syntax of an if...else is:
if(Boolean_expression){
//Executes when the Boolean expression is true
}else{
//Executes when the Boolean expression is false
}
12
 If I have enough money left, I will go out for a meal
 Otherwise, I will stay home and watch a movie
if(I have enough money left) {
// go out for a meal;
}
else {
// stay home and watch a movie;
}
• The result depends on the amount of money
available at the time the decision is made
13
Example:
14
 When the conditional statement is encountered, the Boolean
expression is evaluated
◦ It returns either true or false
 If the result is true, the first statement block is executed, and the
second is skipped
 If the result is false, the first statement block is skipped, and the
second is executed
 In every case, exactly one of the blocks is executed
 In every case, execution continues with the statements following the
conditional (if any)
15
<statements1>
if(condition) {
<statements2a>
}
else {
<statements2b>
}
<statements3>
• The order of execution here is
• <statements1>, then
• <condition>, then
• either <statements2a> or <statements2b>, then
• <statements3>
16
 The syntax of an if...else is:
if(Boolean_expression 1){
//Executes when the Boolean expression 1 is true
}else if(Boolean_expression 2){
//Executes when the Boolean expression 2 is true
}else if(Boolean_expression 3){
//Executes when the Boolean expression 3 is true
}else {
//Executes when the none of the above condition is true.
}
17
Example:
18
 Nested if...else statement:
◦ It is always legal to nest if…else statements which means you can use
one if or else if statement inside another if or else if statement.
 The syntax for a nested if...else is as follows:
if(Boolean_expression 1){
//Executes when the Boolean expression 1 is true
if(Boolean_expression 2){
//Executes when the Boolean expression 2 is true
}
}
19
Example:
20
 Sometimes we want to choose what to do based on several
possible values that a number can have
public String classify (int mark) {
String grade;
if (mark >= 80) grade = “HD”;
else if (mark >= 70) grade = “D”;
else if (mark >= 60) grade = “CR”;
else if (mark >= 50) grade = “P”;
else grade = “N”;
return grade;
}
21
 That code is tedious both to write and to read!
public String classify (int mark) {
String grade;
switch (mark / 10) {
case 9: grade = “HD”; break;
case 8: grade = “HD”; break;
case 7: grade = “D”; break;
case 6: grade = “CR”; break;
case 5: grade = “P”; break;
default: grade = “N”;
}
return grade;
}
22
 The statement evaluates the int expression once
 If the result matches any of the explicit cases listed, execution
resumes at that point
 If it matches none of the explicit cases listed, execution resumes at
the default case
◦ Although the default case is optional
 A break statement causes execution to jump to the statements
following the entire switch statement
◦ If there is no break, execution just continues over multiple cases
23
 The basic form of a variable
declaration is shown here:
 The identifier is the name of
the variable.
 To declare more than one
variable of the specified
type, use a comma-
separated list.
Examples:
24
 There are three kinds of variables in Java:
◦ Local variables
◦ Instance variables
◦ Class/static variables
25
 Local variables are declared in methods or constructors.
 Local variables are created when the method or constructor is entered
and the variable will be destroyed once it exits the method, constructor
or block.
 Access modifiers cannot be used for local variables.
 Local variables are visible only within the declared methods or
constructor.
 There is no default value for local variables so local variables should be
declared and an initial value should be assigned before the first use.
 The scope of a local variable is the block in which it is declared.
26
27
Example:
Here, age is a local variable. This is defined inside pupAge() method
and its scope is limited to this method only.
28
Example:
Following example uses age without initializing it, so it would give an
error at the time of compilation.
29
 Instance variables (fields) are declared in a class, but outside a
method or constructor.
 Instance variables are created when an object is created with the
use of the keyword 'new' and destroyed when the object is
destroyed.
 Instance variables hold values that must be referenced by more
than one method or constructor or essential parts of an object's
state that must be present throughout the class.
30
 The instance variables are visible for all methods, constructors and
block in the class.
 It is recommended to make these variables private.
 Instance variables have default values.
 Instance variables can be accessed directly by calling the variable
name inside the class.
ObjectReference.VariableName.
31
32
 Class variables also known as static variables are declared with the static
keyword in a class, but outside a method, constructor or a block.
 There would only be one copy of each class variable per class, regardless
of how many objects are created from it.
 Static variables are rarely used other than being declared as constants.
 Constants are variables that are declared as public/private, final and static.
Constant variables never change from their initial value.
 Static variables are stored in static memory. It is rare to use static variables
other than declared final and used as either public or private constants.
33
 Static variables are created when the program starts and destroyed
when the program stops.
 Static variables can be accessed by calling with the class name.
ClassName.VariableName.
 When declaring class variables as public static final, then variables
names (constants) are all in upper case.
 If the static variables are not public and final the naming syntax is
the same as instance and local variables.
34
35
 +, - (plus/addition and minus/subtraction)
 *, /, % (Multiplication, division, and
remainder)
 ! (Not)
 <, <=, >, >= (Comparison)
 ==, !=; (Equality)
 && (Conditional AND)
 || (Conditional OR)
36
 The expression in the parentheses is evaluated first.
 When evaluating an expression without parentheses, the operators are
applied according to the precedence rule and the associativity rule.
 If operators with the same precedence are next to each other, their
associativity determines the order of evaluation.
 All binary operators except assignment operators are left-associative.
 When two operators with the same precedence are evaluated, the
associativity of the operators determines the order of evaluation.
 All binary operators except assignment operators are left-associative.
a – b + c – d is equivalent to ((a – b) + c) – d
 Assignment operators are right-associative. Therefore, the expression
a = b += c = 5 is equivalent to a = (b += (c = 5))
37
 The compiler uses the precedence and association rules to
determine the order of evaluation
5 * 6 + 3 * 2 - 4 + 6 * 11
becomes
(5 * 6) + (3 * 2) - 4 + (6 * 11)
because * has a higher precedence than + or -
 The resulting expression is calculated left to right
(((30 + 6) - 4) + 66)
 The programmer can use parentheses if a different order is required
38
Example:
Applying the operator precedence and associativity rule, the
expression 3 + 4 * 4 > 5 * (4 + 3) - 1 is evaluated as follows:
39
 A conditional statement gives us a means to perform a test and
then, on the basis of the result of that test, perform one or the other
of two distinct actions.
 Local variables allow us to calculate and store temporary values
within a constructor or method. They contribute to the behavior that
their defining method implements, but their values are lost once that
constructor or method finishes its execution
40
 Barnes, David J., and Kölling, Michael. 2012. Objects First with
Java, A practical Introduction Using BlueJ (5th Edition). Boston:
Preston.
 Liang, Y. Daniel. 2011. Introduction to Java Programming,
Comprehensive (8th Ed.) Prentice Hall.
 http://www.tutorialspoint.com/java/java_decision_making.htm
 http://www.homeandlearn.co.uk/java/java.html
41

More Related Content

PPT
Control structures selection
PPT
Control structures i
PDF
Control structures in Java
PPT
Control structures in C++ Programming Language
DOCX
Chapter 4(1)
PPT
Control Structures
PPTX
Selection statements
PPTX
Selection Statements in C Programming
Control structures selection
Control structures i
Control structures in Java
Control structures in C++ Programming Language
Chapter 4(1)
Control Structures
Selection statements
Selection Statements in C Programming

What's hot (20)

PPTX
Flow of control C ++ By TANUJ
PPTX
Lecture - 3 Variables-data type_operators_oops concept
PPTX
If and select statement
PPT
Control Structures: Part 1
PPT
The Three Basic Selection Structures in C++ Programming Concepts
PPSX
Control Structures in Visual Basic
PPTX
Flow of control by deepak lakhlan
PPTX
Control statement-Selective
PPTX
Chapter 2 : Programming with Java Statements
PDF
itft-Decision making and branching in java
PPTX
C# conditional branching statement
PPTX
Control Statements in Java
PPT
C language control statements
PPTX
Ppt on java basics
PPT
Control structures ii
PPTX
Lecture 4_Java Method-constructor_imp_keywords
PPT
Mesics lecture 6 control statement = if -else if__else
PPTX
Lecture 6 inheritance
PPSX
Conditional statement
Flow of control C ++ By TANUJ
Lecture - 3 Variables-data type_operators_oops concept
If and select statement
Control Structures: Part 1
The Three Basic Selection Structures in C++ Programming Concepts
Control Structures in Visual Basic
Flow of control by deepak lakhlan
Control statement-Selective
Chapter 2 : Programming with Java Statements
itft-Decision making and branching in java
C# conditional branching statement
Control Statements in Java
C language control statements
Ppt on java basics
Control structures ii
Lecture 4_Java Method-constructor_imp_keywords
Mesics lecture 6 control statement = if -else if__else
Lecture 6 inheritance
Conditional statement
Ad

Viewers also liked (20)

PDF
Event loops in java script 01 - stack
PPTX
Lecture 10 semantic analysis 01
PPSX
Type conversion
PPTX
Intermediate code generation1
PDF
Loops in JavaScript
PPTX
Type checking
PPT
Type Checking(Compiler Design) #ShareThisIfYouLike
PPTX
PPT
Java Programming: Loops
PPTX
compiler and their types
PPTX
Lecture 12 intermediate code generation
PPTX
Loops in java script
PPTX
Syntax directed-translation
PPT
Code generator
PPT
Chapter 6 intermediate code generation
PPTX
Lecture 11 semantic analysis 2
PPTX
Intermediate code- generation
PDF
Syntax directed translation
PPTX
Abstract syntax semantic analyze
PPTX
Three address code In Compiler Design
Event loops in java script 01 - stack
Lecture 10 semantic analysis 01
Type conversion
Intermediate code generation1
Loops in JavaScript
Type checking
Type Checking(Compiler Design) #ShareThisIfYouLike
Java Programming: Loops
compiler and their types
Lecture 12 intermediate code generation
Loops in java script
Syntax directed-translation
Code generator
Chapter 6 intermediate code generation
Lecture 11 semantic analysis 2
Intermediate code- generation
Syntax directed translation
Abstract syntax semantic analyze
Three address code In Compiler Design
Ad

Similar to Lecture 3 Conditionals, expressions and Variables (20)

PPTX
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
PPTX
Java Decision Control
PPT
Flow of Control
PDF
PPT
slides03.ppt
PPT
_Java__Expressions__and__FlowControl.ppt
PPT
_Java__Expressions__and__FlowControl.ppt
PPT
03a control structures
PPS
Programming in Arduino (Part 2)
DOCX
C# language basics (Visual Studio)
DOCX
C# language basics (Visual studio)
PPTX
Control structures in java
PDF
[C++][a] tutorial 2
PDF
Java input Scanner
PPTX
ICSE Class X Conditional Statements in java
PPT
Md04 flow control
PPT
M C6java5
PPTX
CSE-1203-Lecture-05-Branching. for c programmepptx
PPT
Decision making in C(2020-2021) statements
PPTX
Introduction to Java
Unit 2-data types,Variables,Operators,Conitionals,loops and arrays
Java Decision Control
Flow of Control
slides03.ppt
_Java__Expressions__and__FlowControl.ppt
_Java__Expressions__and__FlowControl.ppt
03a control structures
Programming in Arduino (Part 2)
C# language basics (Visual Studio)
C# language basics (Visual studio)
Control structures in java
[C++][a] tutorial 2
Java input Scanner
ICSE Class X Conditional Statements in java
Md04 flow control
M C6java5
CSE-1203-Lecture-05-Branching. for c programmepptx
Decision making in C(2020-2021) statements
Introduction to Java

More from Syed Afaq Shah MACS CP (7)

PDF
Lecture 8 Library classes
PDF
Lecture 7- Iterator and for loop over arrays
PDF
Lecture 6 - Arrays
PDF
Lecture 5 - Interaction with for each and while loops
PDF
Lecture 4 - Object Interaction and Collections
PDF
Lecture 2 - Classes, Fields, Parameters, Methods and Constructors
PDF
Lecture 1 - Objects and classes
Lecture 8 Library classes
Lecture 7- Iterator and for loop over arrays
Lecture 6 - Arrays
Lecture 5 - Interaction with for each and while loops
Lecture 4 - Object Interaction and Collections
Lecture 2 - Classes, Fields, Parameters, Methods and Constructors
Lecture 1 - Objects and classes

Recently uploaded (20)

PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
top salesforce developer skills in 2025.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
System and Network Administration Chapter 2
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
ai tools demonstartion for schools and inter college
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Digital Strategies for Manufacturing Companies
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
Transform Your Business with a Software ERP System
PDF
Nekopoi APK 2025 free lastest update
PPTX
Introduction to Artificial Intelligence
PDF
AI in Product Development-omnex systems
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Softaken Excel to vCard Converter Software.pdf
CHAPTER 2 - PM Management and IT Context
top salesforce developer skills in 2025.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
System and Network Administration Chapter 2
Design an Analysis of Algorithms II-SECS-1021-03
ai tools demonstartion for schools and inter college
VVF-Customer-Presentation2025-Ver1.9.pptx
Understanding Forklifts - TECH EHS Solution
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Digital Strategies for Manufacturing Companies
wealthsignaloriginal-com-DS-text-... (1).pdf
Odoo POS Development Services by CandidRoot Solutions
Transform Your Business with a Software ERP System
Nekopoi APK 2025 free lastest update
Introduction to Artificial Intelligence
AI in Product Development-omnex systems

Lecture 3 Conditionals, expressions and Variables

  • 1. 1
  • 2.  Lecture 3 will introduce conditional statements that allow choices between different actions to be made within methods. Local variables in methods will be presented as well to let us differentiate it from global variables later on. 2
  • 3.  To learn Boolean types and operators  To implement conditional statements using if .. else statement  To learn how to make choices in everyday life, make choices in Java, and make a choice in the ticket machine  To know the meaning of scope and lifetime  To learn about variable types and how can we differentiate them from local variables that are used in methods  To learn about arithmetic operator precedence 3
  • 4.  Boolean expressions have only two possible values: true and false.  They are commonly found controlling the choice between the two paths through a conditional statement.  Java provides six comparison operators (also known as relational operators) that can be used to compare two values. boolean b = (1 > 2); 4
  • 5. Operator Name < less than <= less than or equal to > greater than >= greater than or equal to == equal to != not equal to 5
  • 6. Operator Name ! not && and || or ^ exclusive or 6
  • 7.  A conditional statement takes one of two possible actions based upon the result of a test.  There are two types of conditional statements in Java. They are: ◦ if statements ◦ switch statements  Make choices in Java: 7
  • 8.  The if statement (one-way if statement): ◦ An if statement consists of a Boolean expression followed by one or more statements.  The syntax of an if statement is: if(Boolean_expression) { //Statements will execute if the Boolean expression is true } ◦ If the Boolean expression evaluates to true then the block of code inside the if statement will be executed. ◦ If not the first set of code after the end of the if statement (after the closing curly brace) will be executed. 8
  • 9. Example: 9 Boolean Expression true Statement(s) false (radius >= 0) true area = radius * radius * PI; System.out.println("The area for the circle of " + "radius " + radius + " is " + area); false (A) (B)
  • 11. Explanation:  public is the visibility. This can be public, private or default (if you omit a value).  static is a special [optional] keyword that indicates that this method can be called without creating an instance of this class. Without it, you have to instantiate this class and call this method from the resulting object.  void is the return type of this method, indicating that this method doesn't return anything. Methods must have a return type.  main( ... ) is the name of this method. Methods have to be named. The parentheses indicate that this is a method.  String[] args is a single parameter for the method. String[] is the type of the parameter, indicating an array of Strings. args is the name of the parameter. Parameters must be named. 11
  • 12.  The if...else statement (two-way if statement): ◦ An if statement can be followed by an optional else statement, which executes when the Boolean expression is false.  The syntax of an if...else is: if(Boolean_expression){ //Executes when the Boolean expression is true }else{ //Executes when the Boolean expression is false } 12
  • 13.  If I have enough money left, I will go out for a meal  Otherwise, I will stay home and watch a movie if(I have enough money left) { // go out for a meal; } else { // stay home and watch a movie; } • The result depends on the amount of money available at the time the decision is made 13
  • 15.  When the conditional statement is encountered, the Boolean expression is evaluated ◦ It returns either true or false  If the result is true, the first statement block is executed, and the second is skipped  If the result is false, the first statement block is skipped, and the second is executed  In every case, exactly one of the blocks is executed  In every case, execution continues with the statements following the conditional (if any) 15
  • 16. <statements1> if(condition) { <statements2a> } else { <statements2b> } <statements3> • The order of execution here is • <statements1>, then • <condition>, then • either <statements2a> or <statements2b>, then • <statements3> 16
  • 17.  The syntax of an if...else is: if(Boolean_expression 1){ //Executes when the Boolean expression 1 is true }else if(Boolean_expression 2){ //Executes when the Boolean expression 2 is true }else if(Boolean_expression 3){ //Executes when the Boolean expression 3 is true }else { //Executes when the none of the above condition is true. } 17
  • 19.  Nested if...else statement: ◦ It is always legal to nest if…else statements which means you can use one if or else if statement inside another if or else if statement.  The syntax for a nested if...else is as follows: if(Boolean_expression 1){ //Executes when the Boolean expression 1 is true if(Boolean_expression 2){ //Executes when the Boolean expression 2 is true } } 19
  • 21.  Sometimes we want to choose what to do based on several possible values that a number can have public String classify (int mark) { String grade; if (mark >= 80) grade = “HD”; else if (mark >= 70) grade = “D”; else if (mark >= 60) grade = “CR”; else if (mark >= 50) grade = “P”; else grade = “N”; return grade; } 21
  • 22.  That code is tedious both to write and to read! public String classify (int mark) { String grade; switch (mark / 10) { case 9: grade = “HD”; break; case 8: grade = “HD”; break; case 7: grade = “D”; break; case 6: grade = “CR”; break; case 5: grade = “P”; break; default: grade = “N”; } return grade; } 22
  • 23.  The statement evaluates the int expression once  If the result matches any of the explicit cases listed, execution resumes at that point  If it matches none of the explicit cases listed, execution resumes at the default case ◦ Although the default case is optional  A break statement causes execution to jump to the statements following the entire switch statement ◦ If there is no break, execution just continues over multiple cases 23
  • 24.  The basic form of a variable declaration is shown here:  The identifier is the name of the variable.  To declare more than one variable of the specified type, use a comma- separated list. Examples: 24
  • 25.  There are three kinds of variables in Java: ◦ Local variables ◦ Instance variables ◦ Class/static variables 25
  • 26.  Local variables are declared in methods or constructors.  Local variables are created when the method or constructor is entered and the variable will be destroyed once it exits the method, constructor or block.  Access modifiers cannot be used for local variables.  Local variables are visible only within the declared methods or constructor.  There is no default value for local variables so local variables should be declared and an initial value should be assigned before the first use.  The scope of a local variable is the block in which it is declared. 26
  • 27. 27
  • 28. Example: Here, age is a local variable. This is defined inside pupAge() method and its scope is limited to this method only. 28
  • 29. Example: Following example uses age without initializing it, so it would give an error at the time of compilation. 29
  • 30.  Instance variables (fields) are declared in a class, but outside a method or constructor.  Instance variables are created when an object is created with the use of the keyword 'new' and destroyed when the object is destroyed.  Instance variables hold values that must be referenced by more than one method or constructor or essential parts of an object's state that must be present throughout the class. 30
  • 31.  The instance variables are visible for all methods, constructors and block in the class.  It is recommended to make these variables private.  Instance variables have default values.  Instance variables can be accessed directly by calling the variable name inside the class. ObjectReference.VariableName. 31
  • 32. 32
  • 33.  Class variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block.  There would only be one copy of each class variable per class, regardless of how many objects are created from it.  Static variables are rarely used other than being declared as constants.  Constants are variables that are declared as public/private, final and static. Constant variables never change from their initial value.  Static variables are stored in static memory. It is rare to use static variables other than declared final and used as either public or private constants. 33
  • 34.  Static variables are created when the program starts and destroyed when the program stops.  Static variables can be accessed by calling with the class name. ClassName.VariableName.  When declaring class variables as public static final, then variables names (constants) are all in upper case.  If the static variables are not public and final the naming syntax is the same as instance and local variables. 34
  • 35. 35
  • 36.  +, - (plus/addition and minus/subtraction)  *, /, % (Multiplication, division, and remainder)  ! (Not)  <, <=, >, >= (Comparison)  ==, !=; (Equality)  && (Conditional AND)  || (Conditional OR) 36
  • 37.  The expression in the parentheses is evaluated first.  When evaluating an expression without parentheses, the operators are applied according to the precedence rule and the associativity rule.  If operators with the same precedence are next to each other, their associativity determines the order of evaluation.  All binary operators except assignment operators are left-associative.  When two operators with the same precedence are evaluated, the associativity of the operators determines the order of evaluation.  All binary operators except assignment operators are left-associative. a – b + c – d is equivalent to ((a – b) + c) – d  Assignment operators are right-associative. Therefore, the expression a = b += c = 5 is equivalent to a = (b += (c = 5)) 37
  • 38.  The compiler uses the precedence and association rules to determine the order of evaluation 5 * 6 + 3 * 2 - 4 + 6 * 11 becomes (5 * 6) + (3 * 2) - 4 + (6 * 11) because * has a higher precedence than + or -  The resulting expression is calculated left to right (((30 + 6) - 4) + 66)  The programmer can use parentheses if a different order is required 38
  • 39. Example: Applying the operator precedence and associativity rule, the expression 3 + 4 * 4 > 5 * (4 + 3) - 1 is evaluated as follows: 39
  • 40.  A conditional statement gives us a means to perform a test and then, on the basis of the result of that test, perform one or the other of two distinct actions.  Local variables allow us to calculate and store temporary values within a constructor or method. They contribute to the behavior that their defining method implements, but their values are lost once that constructor or method finishes its execution 40
  • 41.  Barnes, David J., and Kölling, Michael. 2012. Objects First with Java, A practical Introduction Using BlueJ (5th Edition). Boston: Preston.  Liang, Y. Daniel. 2011. Introduction to Java Programming, Comprehensive (8th Ed.) Prentice Hall.  http://www.tutorialspoint.com/java/java_decision_making.htm  http://www.homeandlearn.co.uk/java/java.html 41