Java Methods Part 2 Flashcards

(60 cards)

1
Q

_____ are used to carry out specific actions
and are sometimes called functions.

A

Methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
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
3
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
4
Q

The _______ is the starting point of a Java
program, and it is the first method executed by
the JVM (Java Virtual Machine).

A

main() 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

JVM (Java Virtual Machine)

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

Methods in Java are ________________ designed to perform specific tasks.

A

reusable blocks of
code

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

They help break 1.____, 2._________ into 3._________, easier-to-handle parts

A

1.large
2.complex programs
3. smaller

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

_________ are used to compare two values
or variables.

A

Relational operators

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

Relational operators are used to compare 1.________
or 2.________.

A
  1. two values
  2. variables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

They return a _______ result: true or false.

A

Boolean

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

They return a Boolean result: _________.

A

true or false

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

These operators are commonly used in________________ like if, while, and for.

A

decision-making statements

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

These operators are commonly used in decision-making statements like ___________.

A

if, while, and for

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
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
15
Q

__________ are binary operators (they work
with two operands).

A

Relational operators

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

Relational operators are __________ (they work
with two operands).

A

binary operators

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
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
18
Q

Logical operators are used to combine 1.___________ or 2._________.

A

1.multiple conditions
2.expressions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
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
20
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
21
Q

Reverses the result of a condition.

A

! (Logical NOT)

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

For 1.__, if the first condition is 2.__-e, the second condition is not evaluated.

A

1.&&
2.fals

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

For 1.___, if the first condition is true, the second condition is not evaluated.___

A
  1. ||
    2.true
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

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

A

Selection statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Selection statements are used to __________ in a program based on certain conditions.
make decisions
26
They allow the program to 1.________________________ depending on whether a condition is ___________.
1.execute specific blocks of code 2.true or false
27
1.______________ are essential for controlling the 2._______.
1.Selection statements 2.flow of a program
28
1.________________: Executes a block of code if a specified condition is true. Also known as 2.________ statement
1.if Statement 2.“if-then”
29
A shorthand for if-else that returns a value based on a condition.
Ternary Operator (? :):
30
1.__________________: Executes one block of code if the condition is 2._____and another block if the condition is 3.______
1.if-else Statement 2.true 3.false
31
Used to test multiple conditions in sequence. The first condition that evaluates to true will have its block executed.
if-else-if Ladder
32
Used to select one of many code blocks to execute based on the value of a variable or expression.
Switch Statement
33
__________ keyword is used to terminate the switch statement.
break
34
break keyword is used to terminate the _____________.
switch statement
35
When a 1.___________ is encountered, the program exits the 2._________ and continues executing the code after the 3.____________.
1.break statement 2.switch block 3.switch statement
36
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 ________________.
fall-through behavior
37
The __________ keyword is used to define a block of code that executes when none of the case values match the switch expression.
default
38
The default keyword is used to define a block of code that executes when 1.____________ match the 2.__________.
1.none of the case values 2.switch expression
39
It is ___________, but it is good practice to include a default case to handle unexpected or invalid values.
optional
40
An if statement inside another if statement.
Nested if Statements
41
An if-else statement inside another if or else block.
Nested if-else Statements
42
An if-else-if ladder inside another if, else, or else-if block.
Nested if-else-if Ladder
43
A switch statement inside another switch statement.
Nested switch Statements
44
1._______________ allow you to execute a block of code repeatedly as long as a specified condition is 2.___. They help reduce code redundancy and make programs more efficient.
Looping statements 2.true
45
Looping statements allow you to execute a block of code repeatedly as long as a specified condition is true. They help reduce 1._________ and make programs 2.___________.
1.code redundancy 2.more efficient
46
The _____ used when you know how many times you want to repeat a block of code.
For loop
47
___________: Executed once at the beginning. It is used to initialize the loop variable.
Initialization
48
____________: Evaluated before each iteration. If true, the loop continues; if false, the loop ends.
Condition
49
_______: Executed after each iteration. It updates the loop variable.
Update
50
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
51
The while loop is used when you want to repeat a block of code as long as a condition is true. The number of _____________ is not fixed.
iterations
52
The _______ 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 Loop
53
_____________ - You can omit the initialization part if the loop variable is already initialized outside the loop.
Omit Initialization
54
1. _____________ - You can omit the condition, but this will create an infinite loop unless you use a 2.__________________ to exit the loop.
1.Omit Condition 2.break statement
55
__________ - You can omit the update part and handle the update inside the loop body.
Omit Update
56
__________________________ - You can initialize and update multiple variables in the for loop.
Multiple Variables in Initialization and Update
57
________ - You can create an infinite loop by omitting all three components. This is useful in scenarios where the loop should run indefinitely until a break statement is encountered.
Infinite Loop
58
____________ - An infinite loop runs indefinitely until it is explicitly stopped (e.g., using a break statement).
Infinite while Loop
59
A ___________ consists of an outer loop and one or more inner loops. The inner loop completes all its iterations for each iteration of the outer loop
nested for loop
60
A ______________ consists of an outer loop and one or more inner loops. The inner loop completes all its iterations for each iteration of the outer loop.
nested while loop