JAVA METHOD PART 2 Flashcards

1
Q

________ in Java are like the basic units or building
blocks of a Java program.

A

Methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A method is a group of code that performs a
specific _____ or __________.

A

task or operation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Methods are used to carry out specific actions
and are sometimes called _________.

A

functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In Java, a method runs only when it is called from
another _______.

A

method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The main() method is the starting point of a Java
program, and it is the first method executed by
the __________________.

A

Java Virtual Machine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Checks if two values are equal

A

== (Equal To)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Checks if two values are not equal.

A

!= (Not Equal To)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Checks if the left operand is greater than the right operand

A

> (Greater Than)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Checks if the left operand is less than the right operand.

A

< (Less Than)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Checks if the left operand is greater than or equal to the right operand.

A

> = (Greater Than or Equal To)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Checks if the left operand is less than or equal to the right
operand.

A

<= (Less Than or Equal To)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

_________ can be of any numeric type (int, double, etc.) or
even Strings/Text (for == and !=).

A

Operands

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

____________ operators are _______ operators (they work
with two operands).

A

RELATIONAL operators are BINARY operators (they work
with two operands)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

____________ are used to combine multiple conditions or expressions.

A

Logical operators

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Returns true only if both conditions are true

A

&& (Logical AND)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Returns true if at least one condition is true

A

|| (Logical OR)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Reverses the result of a condition.
Returns true if the condition is false, and vice versa.

A

! (Logical NOT)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

For &&, if the first condition is _____, the second condition is
not evaluated

A

false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

For ||, if the first condition is _____, the second condition is not evaluated.

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Logical operators can combine multiple ________ or________
expressions.

A

relational or Boolean

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Selection statements are used to make ________ in a program based on certain conditions.

A

decisions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Selection statements are essential for controlling the ____ of a program.

A

flow

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

_______________ are used to make decisions in a program based on certain conditions.

A

Selection statements

24
Q

Executes a block of code if a specified condition is true.

A

if Statement

25
A shorthand for if-else that returns a value based on a condition.
Ternary Operator (? :)
26
Executes one block of code if the condition is true and another block if the condition is false
if-else Statement
27
Used to test multiple conditions in sequence. The first condition that evaluates to true will have its block executed.
if-else-if Ladder
28
Used to select one of many code blocks to execute based on the value of a variable or expression.
Switch Statement
29
______ keyword is used to terminate the switch statement.
break
30
When a break statement is encountered, the program _____ the switch block and _________ executing the code after the switch statement.
exits , continues
31
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
32
The _______ keyword is used to define a block of code that executes when none of the case values match the switch expression.
default
33
An if statement inside another if statement.
Nested if Statements
34
An if-else statement inside another if or else block.
Nested if-else Statements
35
An if-else-if ladder inside another if, else, or else-if block.
Nested if-else-if Ladder
36
A switch statement inside another switch statement.
Nested switch Statements
37
________________ allow you to execute a block of code repeatedly as long as a specified condition is true.
Looping statements
38
The ________ is used when you know how many times you want to repeat a block of code.
For loop
39
1. ____________: Executed once at the beginning. It is used to initialize the loop variable. 2. _________: Evaluated before each iteration. If true, the loop continues; if false, the loop ends. 3. ______: Executed after each iteration. It updates the loop variable.
1. Initialization 2. Condition 3. Update
40
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
41
A while loop evaluates the ____________ inside the parenthesis ().
textExpression
42
A while loop evaluates the textExpression inside the __________.
parenthesis()
43
If the textExpression evaluates to _____, the code inside the while loop is executed.
true
44
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
45
If the textExpression evaluates to _____, the body of the loop inside the do statement is executed again.
true
46
Omit Initialization - You can omit the initialization part if the loop variable is already initialized _______ the loop.
outside
47
Omit Condition - You can omit the condition, but this will create an infinite loop unless you use a ______ statement to exit the loop.
break
48
Omit Update - You can omit the update part and handle the update _______ the loop body.
inside
49
This is useful in scenarios where the loop should run indefinitely until a break statement is encountered.
Infinite Loop
50
An infinite loop runs indefinitely until it is explicitly stopped (e.g., using a break statement).
Infinite while Loop
51
You can use a while loop to repeatedly prompt the user for input until a _________ condition is met.
specific
52
A _________ consists of an outer loop and one or more inner loops.
nested for loop
53
The inner loop _________ all its iterations for each iteration of the outer loop.
completes
54
Controls the number of times the inner loop runs.
Outer Loop
55
Runs independently for each iteration of the outer loop. Completes all its iterations before the outer loop moves to the next iteration.
Inner loop