Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Programming Basics

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What is wrong with the following Java variable declaration?

int 1stNumber = 23;

a)

There is no data type called 'int'

b)

Variable names can not start with a digit

c)

Variable names can not contain digits

d)

Number 23 can not be stored in an int

2.

Which of the following variable declarations are incorrect?

a. float mySalary = 3500.77;

b. int my1stSalary = 2300;

c. double salaryOne = 3450.0f;

d. double salary(1);

a)

a and b

b)

a and d

c)

c and d

d)

b and d

3.

Following set of data items are to be stored about a student

a. Students name

b. Students current age in years

c. Students weight in kg

d. Students gender

Which of the following data types will match best with these

a)

a. String

b. int

c. String

d. String

b)

a. String

b. float

d. int

d. int

c)

a. String

b. int

c. float

d. boolean

d)

a. String

b. int

c. float

d. char

4.

Which of the following data is the 'smallest' data type that can be used to hold the 'distance between Earth to Mars' in km.

(Average distance between Earth and March is 234,460,000 km)

a)

byte

b)

int

c)

long

d)

short

5.

Which of the following statement prints smith\exam1\test.txt?

a)

System.out.println("smith\exam1\test.txt");

b)

b.System.out.println("smith\\exam1\\test.txt");

c)

c.System.out.println("smith\"exam1\"test.txt");

d)

d.System.out.println("smith"\exam1"\test.txt");

6.

17. What is the output of System.out.println('z' - 'a')?

a)

25

b)

26

c)

x

d)

Generates and error

7.

What is true about the provided code?

a)

count < 100 is always true at Point A

b)

count < 100 is always true at Point B

c)

count < 100 is always false at Point B

d)

count < 100 is always true at Point C

e)

count < 100 is always false at Point C

8.

What is the output of the following code?

a)

x is 0

b)

x is 1

c)

x is 2

d)

x is 3

e)

x is 4

9.

What will be displayed when the following code is executed?

a)

6 3 0

b)

6 3

c)

3 0

d)

3 0 -3

e)

0 -3

10.

Considering the provided code , what would be the best match for the 'missing method body'?

a)

return "number";

b)

b.System.out.println(number);

c)

c.System.out.println("number");

d)

return number;