wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Mastering Java Programming Concepts

Total questions: 60

Worksheet time: 33mins

Name
Class
Date
1.

What is the main entry point of a Java application?

a)

static void main(String[] args)

b)

void main(String[] args)

c)

public static void main(String[] args)

d)

public void main(String[] args)

2.

Which of the following is a primitive data type in Java?

a)

float

b)

boolean

c)

char

d)

int

3.

What is the purpose of the 'this' keyword in Java?

a)

The 'this' keyword is used to create static methods.

b)

The 'this' keyword refers to the current instance of a class.

c)

The 'this' keyword refers to a superclass instance.

d)

The 'this' keyword is used for defining global variables.

4.

How do you handle exceptions in Java?

a)

Use try-catch blocks to handle exceptions in Java.

b)

Ignore exceptions and continue execution.

c)

Throw exceptions without handling them.

d)

Use if-else statements to handle exceptions in Java.

5.

What is the difference between checked and unchecked exceptions?

a)

Unchecked exceptions must be declared in the method signature.

b)

Checked exceptions require handling or declaration, while unchecked exceptions do not.

c)

Checked exceptions are always runtime errors.

d)

Both checked and unchecked exceptions require handling.

6.

What is the Java Collections Framework?

a)

A unified architecture for representing and manipulating collections of objects in Java.

b)

A library for network programming in Java.

c)

A framework for building graphical user interfaces in Java.

d)

A set of tools for database management in Java.

7.

Which interface does the List collection implement?

a)

Set interface

b)

List interface

c)

Queue interface

d)

Map interface

8.

What is the purpose of the synchronized keyword in Java?

a)

To provide thread-safe access to shared resources.

b)

To automatically manage memory allocation for objects.

c)

To allow multiple threads to execute simultaneously without restrictions.

d)

To enhance performance of single-threaded applications.

9.

What is the difference between a thread and a process?

a)

A process is an independent execution unit with its own memory, while a thread is a lightweight execution unit that shares memory with other threads in the same process.

b)

Threads cannot communicate with each other, while processes can share data easily.

c)

A process is always faster than a thread because it has its own memory space.

d)

A thread is a standalone execution unit with its own memory, while a process shares memory with other threads.

10.

What is the Stream API used for in Java?

a)

The Stream API is used for managing database connections.

b)

The Stream API is used for compiling Java code.

c)

The Stream API is used for creating graphical user interfaces.

d)

The Stream API is used for processing sequences of elements in a functional style.

11.

How do you create a package in Java?

a)

Declare the package in a separate configuration file.

b)

Use the 'import' statement to include the package.

c)

Create a package by naming the folder with the class name.

d)

Use the 'package' keyword followed by the package name at the top of your Java file.

12.

What is the purpose of an interface in Java?

a)

To provide a default implementation for methods in a class.

b)

The purpose of an interface in Java is to define a contract for classes to implement, allowing for abstraction and multiple inheritance.

c)

To store data in a structured format.

d)

To create a new data type that cannot be instantiated.

13.

What is an abstract class in Java?

a)

An abstract class is a class that has no fields.

b)

An abstract class can be instantiated directly.

c)

An abstract class in Java is a class that cannot be instantiated and may contain abstract methods that must be implemented by subclasses.

d)

An abstract class cannot contain any methods.

14.

What is method overriding in Java?

a)

Method overriding allows a subclass to provide a specific implementation of a method already defined in its superclass.

b)

Method overriding is when a superclass provides a new implementation of a method from its subclass.

c)

Method overriding allows a class to inherit methods from multiple superclasses.

d)

Method overriding is a way to create multiple methods with the same name in the same class.

15.

What is polymorphism in Java?

a)

Polymorphism refers to the process of converting data types in Java.

b)

Polymorphism is the ability to create multiple classes with the same name.

c)

Polymorphism is a feature that allows Java to run on different operating systems.

d)

Polymorphism is the ability of a single function or method to operate in different ways based on the object it is acting upon.

16.

What is the difference between compile-time and runtime polymorphism?

a)

Both compile-time and runtime polymorphism are resolved during program execution.

b)

Compile-time polymorphism is resolved during compilation, while runtime polymorphism is resolved during program execution.

c)

Compile-time polymorphism is a type of dynamic binding, while runtime polymorphism is static binding.

d)

Compile-time polymorphism occurs at runtime, while runtime polymorphism occurs at compile-time.

17.

How do you create a HashMap in Java?

a)

HashMap map = new HashMap();

b)

HashMap map = new HashMap<>();

c)

HashMap map = new HashMap<>()

d)

HashMap map = new HashMap<>();

18.

What is the purpose of the 'final' keyword in Java?

a)

The 'final' keyword is used to create abstract classes.

b)

The 'final' keyword is used to define interfaces.

c)

The 'final' keyword allows multiple inheritance in Java.

d)

The 'final' keyword is used to declare constants, prevent method overriding, and prevent inheritance.

19.

What is the significance of the 'super' keyword in Java?

a)

The 'super' keyword is used to define a new class in Java.

b)

The 'super' keyword is used to create an instance of the superclass.

c)

The 'super' keyword is used to access static methods of the superclass.

d)

The 'super' keyword is used to call the constructor of the superclass.

20.

What is the difference between a HashMap and a TreeMap in Java?

a)

HashMap is ordered, while TreeMap is unordered.

b)

HashMap allows null keys, while TreeMap does not.

c)

TreeMap is faster for retrieval operations compared to HashMap.

d)

HashMap is sorted based on keys, while TreeMap is not.

21.

What is the purpose of the 'static' keyword in Java?

a)

The 'static' keyword is used to create instance variables.

b)

The 'static' keyword is used to create private methods.

c)

The 'static' keyword allows methods to be called without creating an instance of the class.

d)

The 'static' keyword is used to define abstract methods.

22.

What is the difference between an interface and an abstract class in Java?

a)

Interfaces can extend multiple classes, while abstract classes cannot.

b)

Both can be instantiated directly.

c)

An abstract class can have constructors, while an interface cannot.

d)

An interface can have method implementations, while an abstract class cannot.

23.

What is the purpose of the 'transient' keyword in Java?

a)

The 'transient' keyword is used to indicate that a variable should not be serialized.

b)

The 'transient' keyword is used to prevent method overriding.

c)

The 'transient' keyword is used to create static variables.

d)

The 'transient' keyword is used to define constants.

24.

Which type of loop is best known for its boolean condition that controls entry to the loop?

a)

A. do-while loop

b)

B. for (traditional)

c)

C. for-each

d)

D. while

25.

1. Which of this method is given parameter via command line arguments?

a)

a) main()

b)

b) recursive() method

c)

c) Any method

d)

d) System defined methods

26.

What are the Type Conversions available in Java language?

a)

A) Narrowing Type Conversion

b)

B) Widening Type Conversion

c)

A and B

d)

D) None of the above

27.

What is the output of the below Java code snippet?

char ch = 'A';//ASCII 65

int a = ch + 1;

ch = (char)a;

System.out.println(ch);

a)

A) 66

b)

B) A

c)

C) B

d)

D) 65

28.

Which type of loop is best known for its boolean condition that controls entry to the loop?

a)

A. do-while loop

b)

B. for (traditional)

c)

C. for-each

d)

D. while

29.

What will be the Output of the below code:

public class Demo{

public static void main(String[] arr){

}

public static void main(String arr){

}

}

a)

a) Nothing

b)

b) Error

c)

C) Finite

d)

d) Hii

30.

What is the output of the below Java code snippet?

char ch = 'A';//ASCII 65

int a = ch + 1;

ch = (char)a;

System.out.println(ch);

a)

A) 66

b)

B) A

c)

C) B

d)

D) 65

31.

What is the output of the following code snippet?

int i = 0; for(i = 0 ; i < 5; i++)

{ }

System.out.println(i);

a)

A. 5

b)

B. 0

c)

C. 4

d)

D. Compilation Error

32.

Function of the Scanner class to accept a float literal from the user is

a)

nextInt( )

b)

hasNext( )

c)

next( )

d)

nextFloat( )

33.

Predict the value of k,

int k =10;

k=k+k++;

a)

11

b)

20

c)

21

d)

22

34.
Which of these is not a Thread state?
a)
New
b)
Runnable
c)
sleep
d)
terminated
35.

What is an exception

a)

Error occurred during the execution of a program

b)

Bug occurred during the compile time of a program

c)

Simply an Error

d)

It is related to input values

36.

Exception classes belongs to following package

a)

import java.io.*

b)

import java.lang.*

c)

import java.util.*

d)

import java.lang.Exception.*

37.

Choose an exception if attempt to divide number by zero


int number = 89 / 0;

System.out.println("The answer is " + number);

a)

ArithmeticException

b)

NullPointerException

c)

NumberFormatException

d)

ArrayIndexOutOfBoundException

38.

class exception_handling

{ public static void main(String args[])

{ try

{ int a, b;

b = 0;

a = 5 / b;

System.out.print("A");

} catch(ArithmeticException e)

{ System.out.print("B");

}

finally

{ System.out.print("C");

}

}

}

a)

A

b)

B

c)

AC

d)

BC

39.

Find the output for the following.

public class IncDec

{

public static void main(String s[])

{

int a = 1;

int b = 2;

int c;

int d;


c = ++b;

d = a++;


c++;


System.out.println("a = " + a);

System.out.print("b = " + b);

System.out.println("c = " + c);

System.out.print("d = " + d);

}

}

a)

a = 2 b = 3 c = 4 d = 1

b)

a = 2 b = 3 c = 4 d = 1

c)

Program does not compile.

d)

a = 1 b = 2 c = 4 d = 2

40.

Java is a

a)

Procedure Oriented Language

b)

Structure Oriented Language

c)

Object_Oriented Language

d)

Machine Language

41.

Java program is

a)

Interpreted

b)

Compiled

42.

A ___________ file is created after successful compilation of a Java program.

a)

Object file

b)

Array file

c)

Class file

d)

String file

43.

Command to compile Java program

a)

javax

b)

javay

c)

javac

d)

Java

44.

JRE stands for

a)

Java Run Environment

b)

Java Run Execution

c)

Java Runtime Environment

d)

Java Ready Execution

45.

Java is

a)

Machine dependent language

b)

Machine independent language

46.

Java was originally named:

a)

Coffee

b)

Oak

c)

New C++

d)

Duke

47.
When we want to print in Java, we use the code ......
a)
system.out.print();
b)
System.out.println();
c)
System.Out.Printf();
d)
System.out.show();
48.

In Java WORA stands for

a)

Write Once Recall Anywhere

b)

Write Once Return Anywhere

c)

Write Once Read Anywhere

d)

Write Once Run Anywhere

49.

Java programs ________________

a)

are only compiled

b)

are only compiled not interpreted

c)

are only interpreted

d)

are both compiled and interpreted

50.

Java Programming was designed by ______

a)

Sun MicroSystems

b)

Mozilla Corporation

c)

Microsoft

d)

Amazon Inc.

51.

Earlier name of Java Programming language was –

a)

Eclipse

b)

D

c)

Oak

d)

Netbean

52.

Which of the following personality is called as father of Java Programming language –

a)

Guido vom Russom

b)

Larry Page

c)

Bjarne Stroustrup

d)

James Gosling

53.

Which of the following is not OOPS concept in Java?

a)

Inheritance

b)

Encapsulation

c)

Polymorphism

d)

Compilation

54.

Which concept of Java is a way of converting real world objects in terms of class?

a)

Polymorphism

b)

Encapsulation

c)

Abstraction

d)

Inheritance

55.

Which concept of Java is achieved by combining methods and attribute into a class?

a)

Encapsulation

b)

Inheritance

c)

Polymorphism

d)

Abstraction

56.

Java was developed in which year

a)

1992

b)

1993

c)

1994

d)

1995

57.

Which component is used to compile, debug and execute java program?

a)

JDK

b)

JRE

c)

JVM

d)

JIT

58.

The icon of Java program is taken from ___.

a)

a cup of coffee

b)

a tornado that spits fire

c)

a volcano under water

d)

a candle with a flame

59.

In Java EE, EE stands for ___.

a)

Entertainment Edition

b)

Entrepreneur Edition

c)

Enterprise Emperor

d)

Enterprise Edition

60.

Which of these statements is incorrect about tread ?

a)

Start() method is used to begin execution of the thread

b)

Run () method is used to begin execution of a thread before start() method in special cases

c)

A thread can be formed by implementing runnable interface only

d)

A thread can be formed by a class that extends thread class