wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Basic Java

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

What is a correct syntax to output "Hello World" in Java?

a)

System.out.println("Hello World");

b)

Console.WriteLine("Hello World");

c)

echo("Hello World");

d)

print ("Hello World");

2.

Java is short for "JavaScript".

a)

False

b)

True

3.

How do you insert COMMENTS in Java code?

a)

// This is a comment

b)

# This is a comment

c)

/* This is a comment

4.

Which data type is used to create a variable that should store text?

a)

String

b)

string

c)

Txt

d)

myString

5.

How do you create a variable with the numeric value 5?

a)

x = 5;

b)

num x = 5

c)

float x = 5;

d)

int x = 5;

6.

Which method can be used to find the length of a string?

a)

len()

b)

getLength()

c)

length()

d)

getSize()

7.

The value of a string variable can be surrounded by single quotes.

a)

False

b)

True

8.

Which operator can be used to compare two values?

a)

==

b)

=

c)

<>

d)

><

9.

Array indexes start with:

a)

1

b)

0

10.

How do you create a method in Java?

a)

methodName.

b)

methodName[]

c)

methodName()

d)

(methodName)

11.

Which keyword is used to create a class in Java?

a)

className

b)

class

c)

class()

d)

MyClass

12.

What is the correct way to create an object called myObj of MyClass?

a)

new myObj = MyClass();

b)

class MyClass = new myObj();

c)

class myObj = new MyClass();

d)

MyClass myObj = new MyClass();

13.

How do you start writing a while loop in Java?

a)

while x > y {

b)

while (x > y)

c)

while x > y:

d)

x > y while {

14.

Which statement is used to stop a loop?

a)

return

b)

break

c)

stop

d)

exit

15.

Which keyword is used to import a package from the Java API library?

a)

lib

b)

import

c)

getlib

d)

package