JAVA METHOD PART 2 Flashcards
________ in Java are like the basic units or building
blocks of a Java program.
Methods
A method is a group of code that performs a
specific _____ or __________.
task or operation
Methods are used to carry out specific actions
and are sometimes called _________.
functions
In Java, a method runs only when it is called from
another _______.
method
The main() method is the starting point of a Java
program, and it is the first method executed by
the __________________.
Java Virtual Machine
Checks if two values are equal
== (Equal To)
Checks if two values are not equal.
!= (Not Equal To)
Checks if the left operand is greater than the right operand
> (Greater Than)
Checks if the left operand is less than the right operand.
< (Less Than)
Checks if the left operand is greater than or equal to the right operand.
> = (Greater Than or Equal To)
Checks if the left operand is less than or equal to the right
operand.
<= (Less Than or Equal To)
_________ can be of any numeric type (int, double, etc.) or
even Strings/Text (for == and !=).
Operands
____________ operators are _______ operators (they work
with two operands).
RELATIONAL operators are BINARY operators (they work
with two operands)
____________ are used to combine multiple conditions or expressions.
Logical operators
Returns true only if both conditions are true
&& (Logical AND)
Returns true if at least one condition is true
|| (Logical OR)
Reverses the result of a condition.
Returns true if the condition is false, and vice versa.
! (Logical NOT)
For &&, if the first condition is _____, the second condition is
not evaluated
false
For ||, if the first condition is _____, the second condition is not evaluated.
true
Logical operators can combine multiple ________ or________
expressions.
relational or Boolean
Selection statements are used to make ________ in a program based on certain conditions.
decisions
Selection statements are essential for controlling the ____ of a program.
flow
_______________ are used to make decisions in a program based on certain conditions.
Selection statements
Executes a block of code if a specified condition is true.
if Statement
A shorthand for if-else that returns a value based on a condition.
Ternary Operator (? :)
Executes one block of code if the condition is true and another block if the condition is false
if-else Statement
Used to test multiple conditions in sequence.
The first condition that evaluates to true will have its block executed.
if-else-if Ladder
Used to select one of many code blocks to execute based on the value of a variable or expression.
Switch Statement
______ keyword is used to terminate the switch statement.
break
When a break statement is encountered, the program _____ the switch block and _________ executing the code after the switch statement.
exits , continues
If break is omitted, the program will fall through to the next case (or default) and execute its code, even if the condition doesn’t match. This is called ____________ behavior.
fall-through
The _______ keyword is used to define a block of code that executes when none of the case values match the switch expression.
default
An if statement inside another if statement.
Nested if Statements
An if-else statement inside another if or else block.
Nested if-else Statements
An if-else-if ladder inside another if, else, or else-if block.
Nested if-else-if Ladder
A switch statement inside another switch
statement.
Nested switch Statements
________________ allow you to execute a block of code repeatedly as long as a specified condition is true.
Looping statements
The ________ is used when you know how many times you want to repeat a block of code.
For loop
- ____________: Executed once at the
beginning. It is used to initialize the loop
variable. - _________: Evaluated before each
iteration. If true, the loop continues; if false,
the loop ends. - ______: Executed after each iteration. It
updates the loop variable.
- Initialization
- Condition
- Update
The ___________ is used when you want to repeat a block of code as long as a condition is true. The number of iterations is not fixed.
while loop
A while loop evaluates the ____________
inside the parenthesis ().
textExpression
A while loop evaluates the textExpression
inside the __________.
parenthesis()
If the textExpression evaluates to _____, the
code inside the while loop is executed.
true
The ________ loop is similar to the while loop, but it guarantees at least one execution of the loop body, even if the condition is false.
Do-while
If the textExpression evaluates to _____, the body of the loop inside the do statement is executed again.
true
Omit Initialization - You can omit the initialization part if the loop variable is already initialized _______ the loop.
outside
Omit Condition - You can omit the condition, but this will create an infinite loop unless you use a ______ statement to exit the loop.
break
Omit Update - You can omit the update part and handle the update _______ the loop body.
inside
This is useful in scenarios where the loop should run indefinitely until a break statement is encountered.
Infinite Loop
An infinite loop runs indefinitely until it is explicitly
stopped (e.g., using a break statement).
Infinite while Loop
You can use a while loop to repeatedly prompt the user for
input until a _________ condition is met.
specific
A _________ consists of an outer loop and one or more inner loops.
nested for loop
The inner loop _________ all its iterations for each iteration of the outer loop.
completes
Controls the number of times the inner
loop runs.
Outer Loop
Runs independently for each iteration of
the outer loop.
Completes all its iterations before the
outer loop moves to the next iteration.
Inner loop