wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Java Basics

Total questions: 17

Worksheet time: 6mins

Name
Class
Date
1.

Java is short for "JavaScript".

a)

true

b)

false

2.

How do you insert COMMENTS in Java code?

a)

# This is a comment

b)

/* This is a comment

c)

// This is a comment

3.

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

a)

myString

b)

String

c)

Txt

d)

string

4.

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

a)

float x = 5;

b)

x = 5;

c)

int x = 5;

d)

num x = 5

5.

How do you create a variable with the floating number 2.8?

a)

byte x = 2.8f

b)

x = 2.8f;

c)

float x = 2.8f;

d)

int x = 2.8f;

6.

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

a)

getSize()

b)

getLength()

c)

length()

d)

len()

7.

Which operator is used to add together two values?

a)

The + sign

b)

The * sign

c)

The & sign

8.

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

a)

true

b)

false

9.

Which operator can be used to compare two values?

a)

><

b)

=

c)

==

d)

<>

10.

To declare an array in Java, define the variable type with:

a)

{}

b)

[]

c)

()

11.

Array indexes start with:

a)

0

b)

1

12.

How do you create a method in Java?

a)

methodName()

b)

(methodName)

c)

methodName[]

d)

methodName.

13.

How do you call a method in Java?

a)

methodName;

b)

methodName[];

c)

methodName();

d)

(methodName);

14.

Which method can be used to find the highest value of x and y?

a)

Math.largest(x,y)

b)

Math.max(x,y)

c)

Math.maximum(x,y)

d)

Math.maxNum(x,y)

15.

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

a)

import

b)

lib

c)

getlib

d)

package

16.

Which keyword is used to return a value inside a method?

a)

return

b)

void

c)

break

d)

get

17.

Which statement is used to stop a loop?

a)

exit

b)

stop

c)

return

d)

break