wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Java Basics: Data Types and Operators

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is the size of an int data type in Java?

a)

2 bytes

b)

8 bytes

c)

16 bytes

d)

4 bytes

2.

Which of the following is not a primitive data type in Java?

a)

Integer

b)

Boolean

c)

String

d)

Float

3.

What will be the output of the expression 5 + 10 * 2?

a)

15

b)

25

c)

30

d)

20

4.

What is the result of the expression 10 > 5?

a)

true

b)

false

c)

10 < 5

d)

5 > 10

5.

Which operator is used to compare two values for equality?

a)

<>

b)

<=

c)

== or ===

d)

!=

6.

What will be the output of the following code: int a = 5; int b = 10; System.out.println(a + b);?

a)

15

b)

10

c)

5

d)

20

7.

What is the result of the expression true && false?

a)

true || false

b)

false && true

c)

false

d)

true

8.

Which of the following is a logical operator in Java?

a)

==

b)

&&, ||, !

c)

<=

d)

!=

9.

What will be the output of the expression 15 % 4?

a)

2

b)

4

c)

1

d)

3

10.

What is the default value of a boolean variable in Java?

a)

false

b)

1

c)

null

d)

true

11.

What will happen if you try to divide an integer by zero in Java?

a)

The result will be zero.

b)

A NullPointerException is thrown.

c)

An ArithmeticException is thrown.

d)

The program will crash immediately.

12.

What is the result of the expression 10 <= 10?

a)

false

b)

true

c)

10 == 9

d)

10 > 10

13.

Which data type is used to store a single character in Java?

a)

int

b)

boolean

c)

char

d)

string

14.

What will be the output of the following code: int x = 10; x += 5; System.out.println(x);?

a)

15

b)

20

c)

10

d)

5

15.

What is the result of the expression !(true || false)?

a)

!(false && true)

b)

false || false

c)

true

d)

false

16.

Which of the following is a valid declaration of a float variable in Java?

a)

float myFloat = '5.0f';

b)

float myFloat = 5.0F;

c)

float myFloat = 5.0f;

d)

float myFloat = 5.0;

17.

What will be the output of the expression 3 * (4 + 5)?

a)

15

b)

20

c)

27

d)

12

18.

What is the result of the expression 7 != 7?

a)

false

b)

true

c)

7

d)

falsehood

19.

What will be the output of the following code: String str = "Hello"; System.out.println(str.length());?

a)

6

b)

4

c)

5

d)

Hello

20.

What is the purpose of the try-catch block in Java?

a)

To handle exceptions and prevent program crashes.

b)

To optimize performance of the program.

c)

To define variables in a method.

d)

To improve code readability.