wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

BASIC JAVA

Total questions: 50

Worksheet time: 25mins

Name
Class
Date
1.

Which Scanner class method that closes the scanner?

a)

void remove()

b)

void close()

c)

nextLong()

d)

String next()

2.

Which Scanner class method that resets the scanner?

a)

nextFloat()

b)

int radix()

c)

Scanner skip(String pattern)

d)

short nextShort()

3.

Which Scanner class method is used to read th Integer value from the user?

a)

next()

b)

nextInteger()

c)

nextInt()

d)

readInt()

4.

Which Scanner class method is used to read long value from the user?

a)

long()

b)

nextLong()

c)

nextValue()

d)

none of the choices

5.

Which Scanner class method is used to read string value from the user?

a)

next()

b)

nextString()

c)

nextLine()

d)

none of the choices

6.

Which is the correct syntax to declare Scanner class object?

a)

Scanner X = new Scanner (System.in);

b)

Scanner X = Scanner( );

c)

Scanner X = new( );

d)

Scanner X = new Scanner (System.in)

7.

Which Scanner class method is used to read boolean value from the user?

a)

next()

b)

readBoolean()

c)

nextBoolean()

d)

none of the choices

8.

Which Scanner class method is used to read double value from the user?

a)

next()

b)

readDouble()

c)

nextDouble()

d)

none of the choices

9.

Which Scanner class method is used to read short value from the user?

a)

next()

b)

readShort()

c)

nextShort()

d)

none of the choices

10.

Which Scanner class method is used to read byte value from the user?

a)

next()

b)

readByte()

c)

nextByte()

d)

none of the choices

11.

It is used to store a collection of data?

a)

string

b)

array

c)

variables

d)

syntax

12.

Which of the following is the correct syntax of ARRAY?

a)

dataType [] arrayRefVar;

b)

dataType [] array;

c)

dataType [array];

d)

dataType [arrayRefVar];

13.

Which of the following String Class method that can use to compares this String to another object?

a)

char charAt(int index)

b)

int compareTo(String anotherString)

c)

String concat(String str)

d)

int compareTo(Object o)

14.

Which of the following String Class method that can concatenates the specified string to the end of this string?

a)

int compareTo(Object o)

b)

char charAt(int index)

c)

String concat(String str)

d)

boolean endsWith(String suffix)

15.

Which of the following String Class method that can compares this string to the specified object?

a)

Boolean equals(Object anObject)

b)

boolean endsWith(String suffix)

c)

boolean endsWith(String suffix)

d)

boolean endsWith(String suffix)

16.

Which of the following String Class method that returns a String that represents the character sequence in the array

specified?

a)

String concat(String str)

b)

int compareTo(Object o)

c)

char charAt(int index)

d)

static String copyValueOf(char[] data)

17.

Which of the following Array Class method that searches the specified array of Object?

a)

public static int binarySearch(Object[] a, Object key)

b)

public static boolean equals(long[] a, long[] a2)

c)

public static void fill(int[] a, int val)

d)

public static void sort(Object[] a)

18.

Which of the following Array Class method that returns true if the two specified arrays of longs are equal to one

another?

a)

public static int binarySearch(Object[] a, Object key)

b)

public static boolean equals(long[] a, long[] a2)

c)

public static void fill(int[] a, int val)

d)

public static void sort(Object[] a)

19.

Which of the following Array Class method that assigns the specified int value to each element of the specified array

of ints?

a)

public static int binarySearch(Object[] a, Object key)

b)

public static boolean equals(long[] a, long[] a2)

c)

public static void fill(int[] a, int val)

d)

public static void sort(Object[] a)

20.

Which of the following Array Class method that sorts the specified array of objects into an ascending order,

according to the natural ordering of its elements?

a)

public static int binarySearch(Object[] a, Object key)

b)

public static boolean equals(long[] a, long[] a2)

c)

public static void fill(int[] a, int val)

d)

public static void sort(Object[] a)

21.

What will be the output of this program?

a)

Got the Exception 10

b)

Got the Exception 0

c)

Compiler Error

d)

Got the Exception 11

22.

What will be the output of this program?

a)

Got the Exception 10

b)

Got the Exception 0

c)

Compiler Error

d)

Got the Exception 11

23.

What will be the output of this program?

a)

Got the Test Exception Inside finally block

b)

Got the Test Exception

c)

Inside finally block

d)

Compiler Error

24.

What will be the output of this program?

a)

Compiler Error

b)

Compiles and runs fine

c)

Compiles fine but throws

ArithmeticException exception

d)

No output

25.

What will be the output of this program?

a)

Caught base class exception

b)

Caught derived class exception

c)

Compiler Error because derived is not

throwable

d)

Compiler Error because base class

exception is caught before derived class

26.

These are not exceptions at all, but problems that arise beyond the control of the user or the programmer?

a)

Unchecked exceptions

b)

Checked exceptions

c)

Throwable

d)

Error

27.

It is an exception that occurs at the time of execution?

a)

Throwable

b)

Checked exceptions

c)

Unchecked exceptions

d)

Error

28.

It is an exception that is checked (notified) by the compiler at compilation-time, these are also called as compile

time exceptions?

a)

Checked exceptions

b)

Throwable

c)

Unchecked exceptions

d)

Error

29.

It returns a detailed message about the exception that has occurred. This message is initialized in the Throwable

constructor?

a)

public Throwable getCause()

b)

public String getMessage()

c)

public void printStackTrace()

d)

public String toString()

30.

It returns the cause of the exception as represented by a Throwable object?

a)

public String getMessage()

b)

public Throwable getCause()

c)

public void printStackTrace()

d)

public String toString()

31.

Which exception is raised when a method could not convert a string into a numeric format?

a)

ArithmeticException

b)

NumberFormatException

c)

IOException

d)

ClassNotFoundException

32.

It is thrown when a class does not contain the field (or variable) specified?

a)

NoSuchFieldException

b)

NumberFormatException

c)

IOException

d)

ClassNotFoundException

33.

It is thrown when accessing a method which is not found?

a)

NoSuchFieldException

b)

NumberFormatException

c)

NoSuchMethodException

d)

ClassNotFoundException

34.

Which exception is raised when referring to the members of a null object?

a)

NoSuchFieldException

b)

NumberFormatException

c)

NoSuchMethodException

d)

NullPointerException

35.

Which exception is raised when a file is not accessible or does not open?

a)

NoSuchFieldException

b)

FileNotFoundException

c)

NoSuchMethodException

d)

NullPointerException

36.

It is thrown when an input-output operation failed or interrupted?

a)

NoSuchFieldException

b)

FileNotFoundException

c)

IOException

d)

NullPointerException

37.

It is thrown when a thread is waiting , sleeping , or doing some processing , and it is interrupted?

a)

NoSuchFieldException

b)

InterruptedException

c)

IOException

d)

NullPointerException

38.

It is thrown when an exceptional condition has occurred in an arithmetic operation?

a)

NoSuchFieldException

b)

InterruptedException

c)

IOException

d)

ArithmeticException

39.

It is thrown to indicate that an array has been accessed with an illegal index?

a)

ArrayIndexOutOfBoundsException

b)

InterruptedException

c)

IOException

d)

ArithmeticException

40.

Which exception is raised when we try to access a class whose definition is not found?

a)

ArrayIndexOutOfBoundsException

b)

InterruptedException

c)

ClassNotFoundException

d)

ArithmeticException

41.

It is a mechanism where you bind your data and code together as a single unit?

a)

Interface

b)

Inheritance

c)

Abstraction

d)

Encapsulation

42.

When the Java Project is initiated?

a)

June 1937

b)

June 1991

c)

June 1946

d)

June 1976

43.

They named ______ after that tree stood outside Gosling’s office.

a)

Tea

b)

Tree

c)

Oak

d)

OOP

44.

It is the OOP concept for inheriting class?

a)

Encapsulation

b)

Interface

c)

Inheritance

d)

Abstraction

45.

Who is the founder of JAVA creation?

a)

James Gosling

b)

John Gosling

c)

Jawhead Gosling

d)

Luke Gosling

46.

This operator “()” also known as?

a)

Parenthesis

b)

Braces

c)

Brackets

d)

Semicolon

47.

This operator “.”also known as?

a)

Colons

b)

Comma

c)

Period

d)

d. Braces

48.

This operator ”::” also known as?

a)

Semicolons

b)

Braces

c)

Parenthesis

d)

Colons

49.

This operator “{}” also known as?

a)

Period

b)

Brackets

c)

Parenthesis

d)

Braces

50.

What is the name of this operator “[]“?

a)

Brackets

b)

Comma

c)

Semicolons

d)

Period