wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Java Review

Total questions: 25

Worksheet time: 8mins

Name
Class
Date
1.

IndexOutOfBoundsException is an exception that occurs when trying to access an array with an index that is either too large or too small.

a)

TRUE

b)

FALSE

2.

Syntax error is a type of compiler error that prevents a program from compiling and creating an executable file with a .class extension.

a)

TRUE

b)

FALSE

3.

Arithmetic Exception is an exception that occurs whenever a wrong mathematical or arithmetic operation appears in the code during run time.

a)

TRUE

b)

FALSE

4.

Variable is an integer contained within square brackets that indicates one of an array’s variables, or elements?

a)

TRUE

b)

FALSE

5.

Parallel array is an array with the same number of elements and for which the values in corresponding elements are related.

a)

TRUE

b)

FALSE

6.

Loop is a collection of multiple values in a single variable with a similar data type?

a)

TRUE

b)

FALSE

7.

The elements of an array are stored in a non-contiguous memory location.

a)

TRUE

b)

FALSE

8.

Logic Errors are classified as a type of runtime error that can result in a program producing an incorrect or unexpected output.

a)

TRUE

b)

FALSE

9.

Try block is a segment of code that can handle an exception that might be thrown by the try block that precedes it.

a)

TRUE

b)

FALSE

10.

Throw statement is the one that sends an Exception out of a block or a method so it can be handled elsewhere?

a)

TRUE

b)

FALSE

11.

Which of the following is not the element of catch block?

a)

Exception type

b)

Pair of parenthesis

c)

Keyword catch

d)

Initialization statement

12.

Which of the following is not the element of try block?

a)

Conditional statement

b)

Keyword try

c)

Opening curly brace

d)

Executable statement

13.

Which of the following is true about array in Java?

a)

Array is a collection of elements that consist various memory locations.

b)

Array is a collection of elements that has no memory locations.

c)

Array is a collection of different type of elements.

d)

Array is a collection of similar type of elements.

14.

Array in Java is index-based, the first element of the array is stored at the _.

a)

0

b)

1

c)

2

d)

3

15.

Refers to the property of array objects that can be used to get the size of the array.

a)

Array index

b)

Array element

c)

Array length

d)

Array count

16.

Which of the following shows the correct example of assigning an elements to a position in an array?

String arrName[] = new String[1];

a)

array[] = {"Kristel"};

b)

arrNames[1] = Kristel;

c)

arrName[0] = 'Kristel';

d)

arrName[0] = "Kristel";

17.

Which of the following statements will print the value stored in the fifth position of the arrNames array?

int arrNames[] = {"Kristel", "Kimberly", "Denmark", "Hanah","Jeraldine", "Eirene" };

a)

System.out.println(arrNames[4]);

b)

System.out.println(arrNames[5]),

c)

System.out.println(arrName[4]),

d)

System.out.println(arrName[5]);

18.

What would be the output of this code?

int month = 5;

switch(month) {

case 1: System.out.println("January"); break;

case 2: System.out.println("February"); break;

case 3: System.out.println("March"); break;

default: System.out.println("May"); break; }

a)

January

b)

February

c)

March

d)

May

19.

What would be the output of this code?

int num[][] = {{1,2,3,4,5,},

{6,7,8,9,10},

{11,12,13,14,15}};

System.out.println(num[2][2]);

a)

11

b)

8

c)

13

d)

10

20.

What would be the output of this code?

int num[][] = {{1,2,3,4,5,},

{6,7,8,9,10},

{11,12,13,14,15}};

System.out.println("Rows: " + num.length);

a)

1

b)

2

c)

3

d)

4

21.

What would be the output of this code?

int num[][] = {{1,2,3,4,5,},

{6,7,8,9,10,11,12},

{13,14,15,16}};

System.out.println("Row 2 has column length of " + num[1].length);

a)

4

b)

5

c)

6

d)

7

22.

What would be the output if the user entered a number 1?

String arrNames[] = {"Kristel", "Kimberly", "Denmark", "Hanah"};

System.out.print("Choose number from 0 to 3: ");

int input = scan.nextInt();

System.out.println("Hello, " + arrNames[input] + "!");

a)

Hello, Kristel!

b)

Hello, Kimberly!

c)

Hello, Denmark!

d)

Hello, Hanah!

23.

What would be the output if the user entered a number 5?

a)

You can only choose a number from 0 to 3!

b)

Hello, Kimberly!

c)

You can only choose a number from 0 to 4!!

d)

Hello, Hanah!

24.

What would be the output if the user entered a number 0?

a)

Hello, Kristel!

b)

Hello, Kimberly!

c)

Hello, Denmark!

d)

Hello, Hanah!

25.

What would be the output if the user entered a letter B?

a)

You can only choose a number from 0 to 4!

b)

Please input only numeric values.

c)

Please input only numeric values!

d)

You can only choose a number from 0 to 4.