Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Basics

Total questions: 15

Worksheet time: 10mins

Name
Class
Date
1.

___________ is a collection of elements used to store the same type of data.

a)

Array

b)

Switch

c)

Case

d)

Loop

2.

For the array: int a[3]; What is the range of the index?

a)

0 to 3

b)

0 to 2

c)

1 to 3

d)

0 to 4

3.

Create an array of 12 strings called months

(a)  

4.

What is the correct way to create an array with these 3 numbers: 12 8 15

a)

int[] = {12,8,15};

b)

int[] nums = { 12 8 15 };

c)

int[] nums = {12,8,15}

d)

int[] nums = {12,8,15};

5.

An array can store different types of data like double and ints

a)

True

b)

False

6.

Which of the following is a valid variable declaration in Java?

a)

int 1myinteger=0;

b)

int int=0;

c)

Int my Integer=0;

d)

int myIntger=0;

7.

The import statement used to access the Scanner class is:

(a)  

8.

Is String a primitive datatype?

a)

Yes

b)

No

c)

Both

9.

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

a)

double

b)

number

c)

String

d)

int

10.

What will be the output of

System.out.println("Computer".substring(3,6));

(a)  

11.

What is the return type of equalsIgnorecase() method?

a)

int

b)

boolean

c)

char

d)

String

12.

What is the most appropriate way to check if 2 strings are identical?

a)

str1 == str2

b)

str1.equals(str2)

c)

str1.same(str2)

d)

str1.equalsIgnorecase(str2)

13.

Scanner s = new Scanner(System.in);

int a = (a)   ;

14.

User Defined Exceptions are sub classes of the base class

a)

SystemException

b)

Exception

c)

MyException

d)

None of the above

15.

Where do we close all objects?

a)

try block

b)

catch block

c)

finally block

d)

anywhere - doesn't matter