Basics
Syntax
Vocabulary
Code
Bonus
100

What is the term for a collection of elements of the same type in Java?

Array

100

What is wrong with this code?
int[] arr = {1, 2, 3, 4}

Missing semicolon at the end. 

Correct code: int[] arr = {1, 2, 3, 4};

100

What is the term for the fixed size of an array in Java?

Array length

100

What will this code output? int[] arr = {1, 2, 3}; System.out.println(arr[0]);

1

100

Can the size of a Java array be changed after it is created?

No, the size of an array in Java is fixed once initialized

200

What do you call the position of an element in an array?

Index

200

How do you assign a value of 10 to the second element of an array arr in Java?

arr[1] = 10;

200

What is an "index out of bounds" error in Java?

Accessing an array element with an invalid index

200

What will this code output? int[] arr = {4, 5, 6}; System.out.println(arr.length);

3

200

When do you use .length() and when do you use .length? 

.length() is a method that you call to find the length of a String. 

.length is a public instance variable that you have access to with the length of an Array. 

300

What does it mean when an array is "empty" in Java?

he array has no elements or is initialized with no values.

300

How do you access the third element in an array arr in Java?

arr[2]

300

What is the shorthand or slang way of saying an Enhanced For Loop? 

A for-each loop

300

What is wrong with this code? int[] arr = new int[5]; arr[5] = 10;

It causes an "IndexOutOfBoundsException" because the valid indices are 0 to 4.

300

What is the difference between a String[] and an int[] array in Java?

A String[] holds string values, and an int[] holds integer values.

400

What is the value of this array at index 3? 

String[] arr = new String[10]

The value is null, since the default value of a String is null. 

400

What is wrong with this code?
int[] arr = new int[];

The array size or elements are missing. It should be int[] arr = new int[5]; or int[] arr = {1, 2, 3};

400

int[] grades = {100, 90, 75, 95}

If we wanted to use an enhanced for loop to iterate through this array, what would the Enhanced For Loop Variable be? 

The Enhanced For Loop Variable should be: 

grade

for ( grade: grades ) 

400

What will this code print? 

  1. int[ ] scores = { 80, 92, 91, 68, 88}

  2. for (int score : scores) {

  3.      System.out. print(score);

  4. }

8092916888

400

How do you insert the value 50 at the second position of an array arr = {10, 20, 30, 40} in Java?

In Java, arrays have a fixed size, so you cannot directly insert into an existing array. You would need to create a new array and copy the elements.

500

What is an "index out of bounds" error in Java?

Accessing an array element with an invalid index

500

What will this code print?
int[] arr = {10, 20, 30}; System.out.println(arr[3]);

It will throw an ArrayIndexOutOfBoundsException because the index 3 is out of bounds.

500

What are the 2 downsides of using an Enhanced For Loop? 

An Enhanced For Loop cannot change any values in an array (works with a copy of the values), and it cannot do anything involving an index. 

500

What will this code print?
int[] arr = {10, 20, 30}; for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); }

10

20

30

500

Can you give a real-life example of how arrays are used in daily life?

A bookshelf. Each position on the shelf (index) holds a book (element), and the number of books is fixed (array size). If you have a shelf with 5 spaces, you can only store 5 books.

M
e
n
u