wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

java basics

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

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

a)

echo("Hello World");

b)

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

c)

print("Hello World");

d)

console.log("Hello World");

2.

Java is short for "JavaScript".

a)

True

b)

False

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)

myString

c)

string

d)

char

5.

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

a)

num x = 5

b)

float x = 5;

c)

x = 5;

d)

int x = 5;

6.

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;

7.

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

a)

len()

b)

getSize()

c)

length()

d)

getLength()

8.

Which operator is used to add together two values?

a)

The * sign

b)

The + sign

c)

The & sign

d)

The && sign

9.

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

a)

True

b)

False

10.

Which method can be used to return a string in upper case letters?

a)

touppercase()

b)

toUpperCase()  

c)

upperCase()

d)

tuc()

11.

Which operator can be used to compare two values?

a)

><

b)

=

c)

==

d)

<>

12.

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

a)

()

b)

[]

c)

{}

d)

<>

13.

Array indexes start with:

a)

null

b)

0

c)

1

14.

How do you create a method in Java?

a)

(methodName)

b)

methodName()  

c)

methodName.

d)

methodName[]

15.

How do you call a method in Java?

a)

methodName;

b)

(methodName);

c)

methodName[];

d)

methodName();  

16.

Which keyword is used to create a class in Java?

a)

class()

b)

className

c)

class

d)

object

17.

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

a)

class myObj = new MyClass();

b)

class MyClass = new myObj();

c)

new myObj = MyClass();

d)

MyClass myObj = new MyClass();  

18.

In Java, it is possible to inherit attributes and methods from one class to another.

a)

True

b)

False

19.

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

a)

Math.maximum(x,y)

b)

Math.maxNum(x,y)

c)

Math.max(x,y)  

d)

Math.largest(x,y)

20.

Which operator is used to multiply numbers?

a)

#

b)

*

c)

%

d)

x

21.

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

a)

import

b)

package

c)

lib

d)

getlib

22.

How do you start writing an if statement in Java?

a)

if (x > y)  

b)

if x > y then:

c)

if x > y:

23.

How do you start writing a while loop in Java?

a)

x > y while {

b)

while x > y {

c)

while x > y:

d)

while (x > y)  

24.

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

a)

break

b)

return

c)

get

d)

void

25.

Which statement is used to stop a loop?

a)

stop

b)

break

c)

exit

d)

return