WorksheetsMastering Java Programming Concepts
Total questions: 60
Worksheet time: 33mins
What is the main entry point of a Java application?
static void main(String[] args)
void main(String[] args)
public static void main(String[] args)
public void main(String[] args)
Which of the following is a primitive data type in Java?
float
boolean
char
int
What is the purpose of the 'this' keyword in Java?
The 'this' keyword is used to create static methods.
The 'this' keyword refers to the current instance of a class.
The 'this' keyword refers to a superclass instance.
The 'this' keyword is used for defining global variables.
How do you handle exceptions in Java?
Use try-catch blocks to handle exceptions in Java.
Ignore exceptions and continue execution.
Throw exceptions without handling them.
Use if-else statements to handle exceptions in Java.
What is the difference between checked and unchecked exceptions?
Unchecked exceptions must be declared in the method signature.
Checked exceptions require handling or declaration, while unchecked exceptions do not.
Checked exceptions are always runtime errors.
Both checked and unchecked exceptions require handling.
What is the Java Collections Framework?
A unified architecture for representing and manipulating collections of objects in Java.
A library for network programming in Java.
A framework for building graphical user interfaces in Java.
A set of tools for database management in Java.
Which interface does the List collection implement?
Set interface
List interface
Queue interface
Map interface
What is the purpose of the synchronized keyword in Java?
To provide thread-safe access to shared resources.
To automatically manage memory allocation for objects.
To allow multiple threads to execute simultaneously without restrictions.
To enhance performance of single-threaded applications.
What is the difference between a thread and a process?
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.
Threads cannot communicate with each other, while processes can share data easily.
A process is always faster than a thread because it has its own memory space.
A thread is a standalone execution unit with its own memory, while a process shares memory with other threads.
What is the Stream API used for in Java?
The Stream API is used for managing database connections.
The Stream API is used for compiling Java code.
The Stream API is used for creating graphical user interfaces.
The Stream API is used for processing sequences of elements in a functional style.
How do you create a package in Java?
Declare the package in a separate configuration file.
Use the 'import' statement to include the package.
Create a package by naming the folder with the class name.
Use the 'package' keyword followed by the package name at the top of your Java file.
What is the purpose of an interface in Java?
To provide a default implementation for methods in a class.
The purpose of an interface in Java is to define a contract for classes to implement, allowing for abstraction and multiple inheritance.
To store data in a structured format.
To create a new data type that cannot be instantiated.
What is an abstract class in Java?
An abstract class is a class that has no fields.
An abstract class can be instantiated directly.
An abstract class in Java is a class that cannot be instantiated and may contain abstract methods that must be implemented by subclasses.
An abstract class cannot contain any methods.
What is method overriding in Java?
Method overriding allows a subclass to provide a specific implementation of a method already defined in its superclass.
Method overriding is when a superclass provides a new implementation of a method from its subclass.
Method overriding allows a class to inherit methods from multiple superclasses.
Method overriding is a way to create multiple methods with the same name in the same class.
What is polymorphism in Java?
Polymorphism refers to the process of converting data types in Java.
Polymorphism is the ability to create multiple classes with the same name.
Polymorphism is a feature that allows Java to run on different operating systems.
Polymorphism is the ability of a single function or method to operate in different ways based on the object it is acting upon.
What is the difference between compile-time and runtime polymorphism?
Both compile-time and runtime polymorphism are resolved during program execution.
Compile-time polymorphism is resolved during compilation, while runtime polymorphism is resolved during program execution.
Compile-time polymorphism is a type of dynamic binding, while runtime polymorphism is static binding.
Compile-time polymorphism occurs at runtime, while runtime polymorphism occurs at compile-time.
How do you create a HashMap in Java?
HashMap map = new HashMap();
HashMap
HashMap
HashMap
What is the purpose of the 'final' keyword in Java?
The 'final' keyword is used to create abstract classes.
The 'final' keyword is used to define interfaces.
The 'final' keyword allows multiple inheritance in Java.
The 'final' keyword is used to declare constants, prevent method overriding, and prevent inheritance.
What is the significance of the 'super' keyword in Java?
The 'super' keyword is used to define a new class in Java.
The 'super' keyword is used to create an instance of the superclass.
The 'super' keyword is used to access static methods of the superclass.
The 'super' keyword is used to call the constructor of the superclass.
What is the difference between a HashMap and a TreeMap in Java?
HashMap is ordered, while TreeMap is unordered.
HashMap allows null keys, while TreeMap does not.
TreeMap is faster for retrieval operations compared to HashMap.
HashMap is sorted based on keys, while TreeMap is not.
What is the purpose of the 'static' keyword in Java?
The 'static' keyword is used to create instance variables.
The 'static' keyword is used to create private methods.
The 'static' keyword allows methods to be called without creating an instance of the class.
The 'static' keyword is used to define abstract methods.
What is the difference between an interface and an abstract class in Java?
Interfaces can extend multiple classes, while abstract classes cannot.
Both can be instantiated directly.
An abstract class can have constructors, while an interface cannot.
An interface can have method implementations, while an abstract class cannot.
What is the purpose of the 'transient' keyword in Java?
The 'transient' keyword is used to indicate that a variable should not be serialized.
The 'transient' keyword is used to prevent method overriding.
The 'transient' keyword is used to create static variables.
The 'transient' keyword is used to define constants.
Which type of loop is best known for its boolean condition that controls entry to the loop?
A. do-while loop
B. for (traditional)
C. for-each
D. while
1. Which of this method is given parameter via command line arguments?
a) main()
b) recursive() method
c) Any method
d) System defined methods
What are the Type Conversions available in Java language?
A) Narrowing Type Conversion
B) Widening Type Conversion
A and B
D) None of the above
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) 66
B) A
C) B
D) 65
Which type of loop is best known for its boolean condition that controls entry to the loop?
A. do-while loop
B. for (traditional)
C. for-each
D. while
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) Nothing
b) Error
C) Finite
d) Hii
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) 66
B) A
C) B
D) 65
What is the output of the following code snippet?
int i = 0; for(i = 0 ; i < 5; i++)
{ }
System.out.println(i);
A. 5
B. 0
C. 4
D. Compilation Error
Function of the Scanner class to accept a float literal from the user is
nextInt( )
hasNext( )
next( )
nextFloat( )
Predict the value of k,
int k =10;
k=k+k++;
11
20
21
22
What is an exception
Error occurred during the execution of a program
Bug occurred during the compile time of a program
Simply an Error
It is related to input values
Exception classes belongs to following package
import java.io.*
import java.lang.*
import java.util.*
import java.lang.Exception.*
Choose an exception if attempt to divide number by zero
int number = 89 / 0;
System.out.println("The answer is " + number);
ArithmeticException
NullPointerException
NumberFormatException
ArrayIndexOutOfBoundException
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
B
AC
BC
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 = 2 b = 3 c = 4 d = 1
a = 2 b = 3 c = 4 d = 1
Program does not compile.
a = 1 b = 2 c = 4 d = 2
Java is a
Procedure Oriented Language
Structure Oriented Language
Object_Oriented Language
Machine Language
Java program is
Interpreted
Compiled
A ___________ file is created after successful compilation of a Java program.
Object file
Array file
Class file
String file
Command to compile Java program
javax
javay
javac
Java
JRE stands for
Java Run Environment
Java Run Execution
Java Runtime Environment
Java Ready Execution
Java is
Machine dependent language
Machine independent language
Java was originally named:
Coffee
Oak
New C++
Duke
In Java WORA stands for
Write Once Recall Anywhere
Write Once Return Anywhere
Write Once Read Anywhere
Write Once Run Anywhere
Java programs ________________
are only compiled
are only compiled not interpreted
are only interpreted
are both compiled and interpreted
Java Programming was designed by ______
Sun MicroSystems
Mozilla Corporation
Microsoft
Amazon Inc.
Earlier name of Java Programming language was –
Eclipse
D
Oak
Netbean
Which of the following personality is called as father of Java Programming language –
Guido vom Russom
Larry Page
Bjarne Stroustrup
James Gosling
Which of the following is not OOPS concept in Java?
Inheritance
Encapsulation
Polymorphism
Compilation
Which concept of Java is a way of converting real world objects in terms of class?
Polymorphism
Encapsulation
Abstraction
Inheritance
Which concept of Java is achieved by combining methods and attribute into a class?
Encapsulation
Inheritance
Polymorphism
Abstraction
Java was developed in which year
1992
1993
1994
1995
Which component is used to compile, debug and execute java program?
JDK
JRE
JVM
JIT
The icon of Java program is taken from ___.
a cup of coffee
a tornado that spits fire
a volcano under water
a candle with a flame
In Java EE, EE stands for ___.
Entertainment Edition
Entrepreneur Edition
Enterprise Emperor
Enterprise Edition
Which of these statements is incorrect about tread ?
Start() method is used to begin execution of the thread
Run () method is used to begin execution of a thread before start() method in special cases
A thread can be formed by implementing runnable interface only
A thread can be formed by a class that extends thread class
