Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Quiz_1

Total questions: 48

Worksheet time: 48mins

Name
Class
Date
1.

What is the process of converting a variable of one data type into another in Java?

a)

Type casting

b)

Data transformation

c)

Behavioral Modeling

d)

Type conversion

2.

Which type of casting occurs automatically when assigning a value of a smaller data type to a variable of a larger data type?

a)

Explicit casting

b)

Implicit casting

c)

Type conversion

d)

Data transformation

3.

When is explicit casting required in Java?

a)

When declaring a variable

b)

When performing arithmetic operations

c)

When converting a variable of a larger data type to a smaller data type

d)

When converting a variable of a smaller data type to a larger data type

4.

What method is used to find the length of a string in Java?

a)

lengthOf()

b)

size()

c)

length()

d)

count()

5.

Which method is used to concatenate two strings in Java?

a)

concat()

b)

combine()

c)

merge()

d)

join()

6.

What is the escape sequence character used to insert a double quote in a string?

a)

\s

b)

\"

c)

\d

d)

\q

7.

In Java, how can you take input from the user?

a)

Using the Input class

b)

Using the Scanner class

c)

Using the Console class

d)

Using the UserInput class

8.

Which conditional statement in Java allows you to provide an alternative block of code to be executed if the if condition is false?

a)

else if

b)

switch

c)

for

d)

while

9.

What keyword is used to exit the switch statement once a matching case is found?

a)

exit

b)

stop

c)

break

d)

end

10.

What is the default case used for in a switch statement?

a)

To specify the code that should be executed if none of the case values match the value of the expression being evaluated

b)

To specify the first case that should be executed

c)

To specify the last case that should be executed

d)

To specify the case with the highest value

11.

Which method is used to compare two strings in Java?

a)

compare()

b)

equals()

c)

match()

d)

verify()

12.

What is the value stored in x?

double x = (int) (1.8 * 2.0)

a)

3.0

b)

3

c)

3.6

d)

Error

13.

What is the value stored in x?

int x = 1.8 * 2.0

a)

3

b)

2

c)

3.6

d)

Error

14.

What is the value of:

(int) (1 + 1 + 1 + 1 + 1.0 + 1 + 1 / 8)

a)

1

b)

0

c)

0.875

15.
For Modular Arithmetic what value is the most important?
a)
The Modulo
b)
The Given Number
c)
The Remainder
d)
The Divisor
16.

Which of these is valid?

line 1 int x = 2/2;

line 2 double y = 2;

a)

line 1

b)

line 2

c)

neither of these

d)

both of these

17.

double x = 2.0;

int y = 3;

int z = 4;

x=( (double) y + z) /2

translates to:

a)

(3.0 + 4) /2 = 3.0

b)

(3.0 + 4) /2 = 3.5

c)

(3.0 + 4.0)/2 = 3.5

d)

7.0/2 =3.5

18.

Which of the following are relational operators. Select all that apply.

a)

<=

b)

>

c)

!

d)

#

e)

=

19.

Java was originally named:

a)

Coffee

b)

Oak

c)

New C++

d)

Duke

20.

Which of the following is NOT a numeric data type

a)

int

b)

double

c)

float

d)

decimal

21.
A variable that holds words
a)
String
b)
boolean
c)
int
d)
float
22.
A variable that holds a decimal number
a)
String
b)
boolean
c)
int
d)
float
23.
A variable that holds a character
a)
String
b)
boolean
c)
int
d)
char
24.
When we want to print in Java, we use the code ......
a)
system.out.print();
b)
System.out.println();
c)
System.Out.Printf();
d)
System.out.show();
25.
We are use Scanner Library in java for...
a)
Give permissions to the user
b)
Correcting software errors
c)
Allows user to read data
d)
Allows the user to enter data
26.

Where does a java program start executing instructions from:

a)

class

b)

source file

c)

main method

d)

object

27.

The name of the following should be the file name in Java

a)

Object Name

b)

Variable Nam

c)

Class Name

d)

Array Name

28.

Java program does not run without below function

a)

user()

b)

system()

c)

main()

d)

void()

29.

JDK stands for

a)

Java Developer Kit

b)

Java Development Kit

c)

Java Design Kit

d)

Java Debugging Kit

30.

JRE stands for

a)

Java Run Environment

b)

Java Run Execution

c)

Java Runtime Environment

d)

Java Ready Execution

31.

Java is

a)

Machine dependent language

b)

Machine independent language

32.

How would you declare a variable that tells you that someone passed a class?

a)

boolean passed = 'true';

b)

boolean passed = true;

c)

passed = true;

d)

String passed = "true";

33.

Which declaration will throw an error?

a)

double num = 8;

b)

int averageGrade = 89.7;

c)

boolean done = false;

d)

String done = "true";

34.

Java is a

a)

Procedure Oriented Language

b)

Structure Oriented Language

c)

Object_Oriented Language

d)

Machine Language

35.

What is the output of the following code?

int x = 5;

while (x > 0) {

  System.out.print(x);

  x--;

}

a)

54321

b)

5432

c)

54321

d)

5432

36.

What is the value of x after the following code is executed?

int x = 2;

for (int i = 0; i < 3; i++) {

  x += 2;

}

a)

6

b)

8

c)

10

d)

12

37.

What is the purpose of 'continue' statement in Java?

a)

To skip the remaining code in the loop and move to the next iteration

b)

To terminate the loop and move to the next statement after the loop

c)

To restart the loop from the beginning

d)

To check a condition and decide whether to continue the loop or not

38.

In Java, what is the use of 'do-while' loop?

a)

To execute a block of code as long as the specified condition is true

b)

To execute a block of code at least once and then repeatedly execute it as long as the specified condition is true

c)

To execute a block of code a specific number of times

d)

To execute a block of code based on multiple conditions

39.

What is the purpose of 'for-each' loop in Java?

a)

To iterate through a collection of elements such as arrays or lists

b)

To execute a block of code as long as the specified condition is true

c)

To execute a block of code a specific number of times

d)

To execute a block of code based on multiple conditions

40.

What is the output of the following code snippet?

int[][] arr = {{1, 2, 3}, {4, 5, 6}};

System.out.println(arr[1][2]);

a)

3

b)

4

c)

5

d)

6

41.

How do you declare a 2D array in Java?

a)

int[] arr = new int[3][3];

b)

int[][] arr = new int[3][3];

c)

int[3][3] arr;

d)

int arr[][] = new int[3][3];

42.

What is the output of the following code?

int[][] arr = {{1, 2, 3}, {4, 5, 6}};

for (int i = 0; i < arr.length; i++) {

  for (int j = 0; j < arr[i].length; j++) {

    System.out.print(arr[i][j] + " ");

  }

}

a)

1 2 3 4 5 6

b)

1 4 2 5 3 6

c)

1 2 3

d)

1 4 2 5 3

43.

What is the purpose of a nested loop in Java?

a)

To iterate through a collection of elements such as arrays or lists

b)

To execute a block of code as long as the specified condition is true

c)

To execute a block of code a specific number of times

d)

To execute a block of code based on multiple conditions

44.

What is the value of x after the following code is executed?

int x = 0;

do {

  System.out.print(x);

  x++;

} while (x < 5);

a)

01234

b)

12345

c)

43210

d)

54321

45.

What is the output of the following code?

for (int i = 0; i < 3; i++) {
  for (int j = 0; j < 2; j++) {
    System.out.print(i + j);
  }
}

a)

012345

b)

0123

c)

001122

d)

0012

46.

What is the output of the following code snippet?

int[][] arr = {{1, 2, 3}, {4, 5, 6}};

for (int i = 0; i < arr.length; i++) {

  for (int j = 0; j < arr[i].length; j++) {

    System.out.print(arr[i][j] + " ");

  }

}

a)

1 2 3 4 5 6

b)

1 4 2 5 3 6

c)

1 2 3

d)

1 4 2 5 3

47.

What is the purpose of 'continue' statement in Java?

a)

To skip the remaining code in the loop and move to the next iteration

b)

To terminate the loop and move to the next statement after the loop

c)

To restart the loop from the beginning

d)

To check a condition and decide whether to continue the loop or not

48.

What is the output of the following code?

int[][] arr = {{1, 2, 3}, {4, 5, 6}};

System.out.println(arr[1][2]);

a)

3

b)

4

c)

5

d)

6