Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Basics

Total questions: 22

Worksheet time: 17mins

Name
Class
Date
1.

Which of the following statements about Java's primitive data types is false?

a)

Java defines eight primitive types, also referred to as simple types

b)

The int type is a signed 32-bit type

c)

The char type is a 16-bit Unicode type with a range of 0 to 65,536

d)

A boolean value can be implicitly converted to an integer (0 or 1) for use in arithmetic expressions

2.

What will be the output of the following code snippet: System.out.println(10 + 20 + "30");?

a)

600

b)

10 20 30

c)

102030

d)

3030

3.

Which of the following is true regarding numeric literals?

a)

An integer literal, by default, is of type long

b)

Underscores can be embedded in numeric literals (e.g., 9_423_497_862.0) to improve readability, and they are discarded by the compiler

c)

A floating-point literal, by default, is of type float

d)

Character literals are enclosed in double quotes

4.

Which statement correctly describes the declaration and initialization of variables in Java?

a)

Variables can only be initialized with values that are already known at compile time

b)

All variables must be initialized at the time of their declaration

c)

A variable is defined by an identifier, a type, and an optional initializer

d)

Arrays in Java must always be one-dimensional

5.

Java's bitwise operators can be applied to which of the following data types?

a)

float and double only

b)

Integer types: long, int, short, char, and byte

c)

boolean only

d)

All primitive types except boolean

6.

What is the outcome of a relational operator in Java?

a)

An integer value indicating the relationship (e.g., 0 for equality, 1 for greater than)

b)

A string describing the relationship

c)

A boolean value (true or false)

d)

All primitive types except boolean

7.

Consider the following Java code snippet: int result = (value > 10) ? 100 : 50; What does result hold if value is 7?

a)

100

b)

true

c)

false

d)

50

8.

To change the default order of evaluation in an expression, such as forcing an addition to occur before multiplication, which lexical element should be used

a)

Commas

b)

Semicolons

c)

Parentheses

d)

Square brackets

9.

Which of the following describes a limitation of Java's switch statement compared to the if statement?

a)

The switch statement can evaluate any type of Boolean expression, while if is restricted to equality tests

b)

The switch statement can only test for equality between the expression's value and its case constants

c)

The if statement does not support else clauses, whereas switch does

d)

switch statements are generally less efficient than a set of nested if statements

10.

What is a characteristic of the do-while loop in Java?

a)

The loop's condition is evaluated before the body of the loop is executed for the first time

b)

It is primarily used for iterating over collections and arrays (the "for-each" style)

c)

The body of the loop is executed at least once, regardless of the initial condition

d)

It can only be controlled by an integer counter

11.

In Java, which statement is used to terminate the execution of the current loop (e.g., for, while, do-while) or switch statement and transfer control to the statement immediately following the loop or switch?

a)

continue

b)

return

c)

throw

d)

break

12.

Predict the output

a)

21

b)

23

c)

24

d)

24.33

13.

Predict the Ouput

a)

a2

b)

c

c)

99

d)

Error

14.
a)

Condition met.

b)

Condition not met.

c)

true

d)

Error

15.

Predcit the output

a)

1 2 3 4

b)

1 2 3

c)

1 2 3 4 5

d)

No Output

16.
a)

5 6

5 6

b)

5 6 5 6

c)

Compilation Error

d)

5 6

17.

Predict the output

a)

1 2 3

b)

2 2 4

c)

224

d)

2 4 4

18.

Predict the output

a)

1 3 4

b)

1 2 3 4

c)

1 2 3

d)

1 3 4 5

19.

Predict the output

a)

One

b)

One Two

c)

One Two Default

d)

Error

20.

Predict the output

a)

Hi

Hi

HI

b)

Hi

c)

No Output

d)

Error

21.

Predict The Output

a)

0 1 2

b)

1 2 3

c)

1 2 3 4

d)

0 1 2 3

22.

Predict the Output

a)

A

b)

B

c)

Error

d)

No Output