wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Mastering Java Basics

Total questions: 8

Worksheet time: 4mins

Name
Class
Date
1.

What is the correct way to declare a variable in Java?

a)

var variableName int;

b)

float variableName = 0;

c)

string variableName;

d)

int variableName;

2.

How do you print a string to the console in Java?

a)

console.log('Your string here');

b)

print('Your string here');

c)

System.out.println("Your string here");

d)

echo 'Your string here';

3.

Which of the following is a valid Java data type?

a)

int

b)

float

c)

boolean

d)

string

4.

What symbol is used to end a statement in Java?

a)

;

b)

!

c)

:

d)

.

5.

How do you create a single-line comment in Java?

a)

# This is a comment

b)

/* This is a comment */

c)

// This is a single-line comment

d)

-- This is a comment

6.

What is the output of System.out.println(5 + 3);?

a)

6

b)

8

c)

10

d)

9

7.

What keyword is used to define a class in Java?

a)

define

b)

object

c)

class

d)

function

8.

What is the result of System.out.println("Hello" + " World");?

a)

HelloWorld

b)

Hello, World

c)

Hello World!

d)

Hello World