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
Q

A shorthand for if-else that returns a value based on a condition.

A

Ternary Operator (? :)

26
Q

Executes one block of code if the condition is true and another block if the condition is false

A

if-else Statement

27
Q

Used to test multiple conditions in sequence.
The first condition that evaluates to true will have its block executed.

A

if-else-if Ladder

28
Q

Used to select one of many code blocks to execute based on the value of a variable or expression.

A

Switch Statement

29
Q

______ keyword is used to terminate the switch statement.

30
Q

When a break statement is encountered, the program _____ the switch block and _________ executing the code after the switch statement.

A

exits , continues

31
Q

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.

A

fall-through

32
Q

The _______ keyword is used to define a block of code that executes when none of the case values match the switch expression.

33
Q

An if statement inside another if statement.

A

Nested if Statements

34
Q

An if-else statement inside another if or else block.

A

Nested if-else Statements

35
Q

An if-else-if ladder inside another if, else, or else-if block.

A

Nested if-else-if Ladder

36
Q

A switch statement inside another switch
statement.

A

Nested switch Statements

37
Q

________________ allow you to execute a block of code repeatedly as long as a specified condition is true.

A

Looping statements

38
Q

The ________ is used when you know how many times you want to repeat a block of code.

39
Q
  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.
A
  1. Initialization
  2. Condition
  3. Update
40
Q

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.

A

while loop

41
Q

A while loop evaluates the ____________
inside the parenthesis ().

A

textExpression

42
Q

A while loop evaluates the textExpression
inside the __________.

A

parenthesis()

43
Q

If the textExpression evaluates to _____, the
code inside the while loop is executed.

44
Q

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.

45
Q

If the textExpression evaluates to _____, the body of the loop inside the do statement is executed again.

46
Q

Omit Initialization - You can omit the initialization part if the loop variable is already initialized _______ the loop.

47
Q

Omit Condition - You can omit the condition, but this will create an infinite loop unless you use a ______ statement to exit the loop.

48
Q

Omit Update - You can omit the update part and handle the update _______ the loop body.

49
Q

This is useful in scenarios where the loop should run indefinitely until a break statement is encountered.

A

Infinite Loop

50
Q

An infinite loop runs indefinitely until it is explicitly
stopped (e.g., using a break statement).

A

Infinite while Loop

51
Q

You can use a while loop to repeatedly prompt the user for
input until a _________ condition is met.

52
Q

A _________ consists of an outer loop and one or more inner loops.

A

nested for loop

53
Q

The inner loop _________ all its iterations for each iteration of the outer loop.

54
Q

Controls the number of times the inner
loop runs.

A

Outer Loop

55
Q

Runs independently for each iteration of
the outer loop.
Completes all its iterations before the
outer loop moves to the next iteration.

A

Inner loop