IT103 - Java Methods II Flashcards

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

It is group of code that performs a specific task or operation. It is a collection of statements that work together to complete a particular job.

A

Method in Java/ Method

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

What are the benefits of using methods in Java?

A
  • They keep code organized and neat.
  • They allow code reuse.
  • They save time and reduce mistakes.
  • They keep your code organized and neat.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

It is the starting point of a Java program and is the first method executed by the Java Virtual Machine (JVM).

A

main() method

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

JVM stands for

A

Java Virtual Machine

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

Methods in Java are _______ _________ of ________ 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

Methods help break ______ , ______
programs into ______ , easier-to-handle parts.

A
  • large
  • complex
  • smaller
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

public static int add (int a, int b) {
int result;
result = a +b;
return result;
}

What do you call the:
1. public
2. int (after the static)
3. (int a, int b)
4. return result;

A
  1. Access Modifier
  2. Return Type
  3. List of Parameters
  4. Return Value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

public static int add (int a, int b) {
int result;
result = a +b;
return result;
}

What do you call the “public static int add (int a, int b) { “ part ?

A

Method Header

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

public static int add (int a, int b) {
int result;
result = a +b;
return result;
}

What do you call the “int result; up to return result; “ part ?

A

Method Body

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

What are the components of a Java method?

A
  • Access specifier
  • Return type
  • Method name
  • Parameters
  • Method body
  • Return statement
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

It determines who can use the class, method, or field (e.g., public, private).

A

accessSpecifier

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

It specifies the type of value the method returns. If no value is returned, the keyword void is used.

A

returnType

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

The name of the method, written in camelCase (e.g., calculateSum).

A

methodName

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

Input values that the method can accept. A method can have zero or more parameters, each with a data
type and name.

A

parameter

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

The code inside curly braces {} that defines what the method does.

A

method body

17
Q

If the method has a return type (not void), it must include a ________ _________ followed by the value to be sent back.

A

return statement

18
Q

What are relational operators in Java?

A

1) == (Equal To): Checks if two values are equal.

2) != (Not Equal To): Checks if two values are not equal.

3) > (Greater Than): Checks if the left operand is greater.

4) < (Less Than): Checks if the left operand is lesser.

5) >= (Greater Than or Equal To)

6) <= (Less Than or Equal To)

19
Q

What are the logical operators in Java?

A

1) && (AND): Returns true only if both conditions are true.

2) || (OR): Returns true if at least one condition is true.

3) ! (NOT): Reverses the result of a condition.

20
Q

________ _________ help make decisions in a program using conditions.

A

Selection statements

21
Q

What selection statement is used for multiple conditions?

A

if-else-if ladder

22
Q

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

A

if-else Statement

23
Q

A selection statement that executes code if a condition is true

A

if Statement

24
Q

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

A

Ternary Operator (? :)

25
It allow you to execute a block of code repeatedly as long as a specified condition is true. They help reduce code redundancy and make programs more efficient.
Looping Statements
26
The ____ loop is used when you know how many times you want to repeat a block of code.
for
27
In a for loop, what are the 3 components for a code to repeat?
1. Initialization 2. Condition 3. update
28
The ______ loop 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
29
A while loop evaluates the ________ inside the parenthesis ().
textExpression
30
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