wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Java - Primitive Type

Total questions: 23

Worksheet time: 17mins

Name
Class
Date
1.

Which of the following is NOT a data types in java

a)

int

b)

String

c)

number

d)

double

2.

What is right way of defining String variable?

a)

String name = "John";

b)

String name = "John"

c)

String name = John;

d)

String name "John";

3.

float myFloatNum = 5.99f;

System.out.println(myFloatNum);


What will be the output?

a)

5.99

b)

5.99f

c)

"5.99"

d)

"5.99"f

4.

int x = 5;

int y = 6

int z = 50;

System.out.println(x + y + z);


What will be the output?

a)

61

b)

5650

c)

66

d)

x + y + z

5.

Which of the following are Java features?

a)

Object- oriented programming

b)

Class- based programming

c)

Bytecode is platform independent

d)

All of above

6.

Which one is correct?

a)

public static main(Strings[] args) { }

b)

public private static main(Strings[] args) { }

c)

public static void main(Strings[] args) { }

d)

public void static main(Strings[] args) { }

7.

(=) sign means

a)

equals and it is used for math problems in Java

b)

assignment operator. It used to assign a value

8.

char is 2 byte in storage?

a)

True

b)

False

9.

Long is 4 byte size in storage?

a)

True

b)

False

10.

Which one is used for remainder in Java?

a)

/

b)

%

c)

+

d)

*

11.

int x = 3; in this case, which of the following statement is true?

a)

x = x+1;

b)

x++;

c)

x += 1;

d)

All of above

12.

A developer wants to convert a smaller data type to larger data type. What is this in Java?

a)

Widening primitive

b)

Narrowing primitive

13.

Which of the following is NOT safe and can result in a loss of data?

a)

Narrowing primitive

b)

Widening primitive

14.

This data type returns true or false

a)

String

b)

boolean

c)

char

d)

int

15.

Name the data type: 1.0

a)

double

b)

int

c)

char

d)

boolean

16.

Is String a primitive data type?

a)

Yes

b)

No

c)

Both

17.

Which method to use to find length of a string?

a)

length()

b)

size()

c)

long()

d)

count()

18.

Which data type gets returned from length() method in String class?

a)

double

b)

String

c)

int

d)

number

19.

String txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";


What is the correct way to find the length of "txt" string?

a)

int len = length(txt);

b)

float len = txt.length();

c)

int len = txt.length();

d)

double len = length(txt);

20.

Which is correct method to convert String into uppercase

a)

changeUpperCase()

b)

convertUpperCase()

c)

toUpper()

d)

toUpperCase()

21.

String txt = "Hello World";

System.out.println(txt.toUpperCase());


Choose the correct output.

a)

"HELLO WORLD"

b)

HELLO WORLD

c)

Hello world

d)

Hello World

22.

Choose correct purpose of indexOf() in String class.

a)

returns the index (the position) of the last occurrence of a specified text in a string

b)

returns the character of the first occurrence of a specified character in a string

c)

returns the index (the position) of the first occurrence of a specified text in a string (excluding whitespace)

d)

returns the index (the position) of the first occurrence of a specified text in a string (including whitespace)

23.

String x = "10";

String y = "20";

String z = x + y;

System.out.println(z);

Guess the output.

a)

1020

b)

10 20

c)

30

d)

"10 20"