● Boolean logic: answers can be true or false (no middle ground)
● George Boole
o Inventor of the concept of Boolean logic
o He also developed the idea of what computers can use to make decisions – condition statements.
● An if statement tells the computer that if a condition is true, then it should execute the block of code within the function.
o Most basic control flow statement
o If it’s false, the computer should skip the code and continue with the rest of the program.
● Control flow statements
o Can modify or break the flow of the execution
▪ Implementing decision making
▪ Looping
▪ Branching program
o To execute certain blocks of code in your program.
● Switch statements
o Can test a range of values
o Can use these statements if the if-else chain is too long.
● Three types of control flow supported by Java
o Decision making statements
▪ if – then
▪ if – then – else
o Looping statements
▪ for
▪ while
▪ do-while
o Branching statements
▪ break
▪ return
▪ continue
● if-else statements
o If the condition is true, the computer executes the block of code but if the condition is false, the computer executes the else action.
o Will always take some action because the condition has to be either true or false (not in the middle).
o Optional else statement
▪ Alternate path if the boolean value might be false
● if-else-if statements
o In Java, once a block of code is executed, it doesn’t check for the other else-if conditions
▪ Breaks the loop
Equivalent Boolean Expressions
o not (a and b) -> (not a) or (not b)
o not (a or b) -> (not a) and (not b)
● How De Morgan’s Laws are expressed in programming languages!
o !(a && b) is equivalent to !a || !b
o !(a || b) is equivalent to !a && !b
● Negating boolean expressions
o You can do this with relational operators
o <, >, or ==
● Truth Tables are used to prove boolean expressions.
● Equivalent boolean expressions result in the same value in any case.
● Object – characterized by state, attributes, and behavior.
o Instance of a class
● Class – Software blueprint
o Implement Objects of a specific data type
● Methods
o Provide behaviors of the object
o Provide operations which manipulate the object
o Using the equals method
▪ If (string1.equals(string2))…
o Using the compareTo method
▪ Int compareTo (string otherStringYouAreComparing)
▪ stringOne. compareTo (stringTwo) < 0
● stringOne precedes stringTwo in a dictionary
▪ stringOne. compareTo (stringTwo) > 0
● stringTwo precedes stringOne in a dictionary
▪ stringOne. compareTo (stringTwo) == 0
● both Strings are identical
o String Objects – immutable
▪ No methods can change them after they are constructed
o You can create a new String object which can be a modified form of an existing String object.
● Characters in the String objects
o Compared based on their position in the ASCII chart.
● Don’t use (==) for testing or comparing String Objects.