exam Flashcards

1
Q

What is a return type in a method?

A

Example: int, double, String, boolean, etc. If the method does not return any value, the return type is void.

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

syntax of declaring a method:

A

public void methodName(parameters) { // method body }

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

.length method:

A

The .length method is used to get the length of arrays and strings in Java.

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

.substring() method:

A

The .substring() method is used to extract a substring from a string.

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

.toUpperCase() method:

A

The .toUpperCase() method is used to convert all characters in a string to uppercase.

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

.toLowerCase() method:

A

The .toLowerCase() method is used to convert all characters in a string to lowercase.

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

.equals() method:

A

The .equals() method is used to compare the contents of two strings.

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

.indexOf() method:

A

The .indexOf() method is used to find the index of a specified character or substring within a string.

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

How to create an ArrayList?

A

ArrayList<Type> listName = new ArrayList<Type>();</Type></Type>

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

Adding elements to an ArrayList:

A

Elements can be added to an ArrayList using the add() method:

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

Getting the size of an ArrayList:

A

the size() method:

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

Accessing elements in an ArrayList:

A

get() method and specifying the index:

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

Checking if an ArrayList contains an element:

A

using the contains() method:

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

Syntax of a for loop:

A

for (initialization; condition; update) {

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

Nested for loops:

A

You can have one or more for loops inside another for loop.
Useful for iterating over multi-dimensional arrays or performing repetitive tasks.
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++)

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

What is a while loop in Java?

A

A while loop in Java is a control flow statement that repeatedly executes a block of code as long as a condition is true.

17
Q

while loops syntax

A

while (condition) {

18
Q

Difference between for and while loops:

A

For loops are used when the number of iterations is known.
While loops are used when the number of iterations is not known beforehand or when looping based on a condition.

19
Q

When to use while loops:

A

While loops are often used when you want to repeat a block of code until a specific condition is met, such as reading input until the user enters a certain value.

20
Q

Arrays:

A

An array in Java is a fixed-size data structure that stores elements of the same type sequentially in memory.

21
Q

arrays example

A

int[] numbers = new int[5];

22
Q

Accessing Elements:

A

Elements in an array are accessed using an index.

23
Q

Accessing elements using a for loop for array

A

for (int i = 0; i < numbers.length; i++) {
System.out.println(numbers[i]);

24
Q

ArrayList:

A

ArrayList is a dynamic array implementation of the List interface in Java that allows resizing and manipulation of elements.

25
Q

array list of Declaration:

A

ArrayList<Integer> list = new ArrayList<>();</Integer>

26
Q
A