Font size
WorksheetsTest-2
Total questions: 100
Worksheet time: 2hrs 33mins
Java is a
Procedure Oriented Language
Structure Oriented Language
Object_Oriented Language
Machine Language
The name of the following should be the file name in Java
Object Name
Variable Nam
Class Name
Array Name
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
Command to run a Java program
javaa
java
jaava
jaavaa
JDK stands for
Java Developer Kit
Java Development Kit
Java Design Kit
Java Debugging Kit
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
JVM stands for
Java Vital Machine
Java Virtual Machine
Java Vendor machine
Java programs ________________
are only compiled
are only compiled not interpreted
are only interpreted
are both compiled and interpreted
Main() method is not mandatory for a Java program
True
False
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
What are the four main principles of Object-Oriented Programming?
Encapsulation, Abstraction, Inheritance, Polymorphism
Polymorphism, Data Abstraction, Class, Object
Composition, Aggregation, Delegation, Interface
Inheritance, Composition, Encapsulation, Data Hiding
Explain the concept of inheritance in Java.
Inheritance is a method of data encryption in Java.
Inheritance allows a class to create multiple instances of itself.
Inheritance in Java is used to define interfaces only.
Inheritance in Java allows a class to inherit properties and behaviors (methods) from another class, promoting code reuse and establishing a parent-child relationship between classes.
What is polymorphism and how is it implemented in Java?
Polymorphism is only achieved through inheritance in Java.
Polymorphism is a feature exclusive to C++ and not applicable in Java.
Polymorphism can only be implemented using abstract classes in Java.
Polymorphism in Java is implemented through method overriding and interfaces.
Define encapsulation and its importance in Java.
Encapsulation is the practice of bundling the data (attributes) and methods (functions) that operate on the data into a single unit or class, while restricting access to some of the object's components.
Encapsulation is only relevant for primitive data types in Java.
Encapsulation allows unrestricted access to all class components.
Encapsulation is the process of separating data from methods in Java.
What is the difference between an abstract class and an interface?
An abstract class can have implemented methods and state, while an interface cannot.
An abstract class is always public, while an interface is always private.
An interface can have state and implemented methods.
An abstract class cannot have any methods.
How does Java handle exceptions?
Java uses try-catch-finally blocks to handle exceptions.
Java does not support exception handling.
Java requires all exceptions to be handled at compile time.
Java uses only if-else statements for error handling.
What is the purpose of the try-catch block in Java?
To improve code readability.
To define variables in a method.
To handle exceptions and prevent program crashes.
To optimize memory usage.
Explain the difference between checked and unchecked exceptions.
Both checked and unchecked exceptions require handling.
Checked exceptions require handling or declaration, while unchecked exceptions do not.
Checked exceptions are always runtime errors.
Unchecked exceptions must be declared in the method signature.
What is the finally block used for in exception handling?
The finally block is only executed if an exception occurs.
The finally block ensures that specific code runs after try and catch blocks, regardless of exceptions.
The finally block is used to define a new exception type.
The finally block is used to catch exceptions before they are thrown.
What is the Java Collections Framework?
A library for network programming in Java.
A unified architecture for representing and manipulating collections of objects in Java.
A set of tools for database management in Java.
A framework for building graphical user interfaces in Java.
List the main interfaces of the Java Collections Framework.
List, Set, Queue, Map
Stack
HashTable
ArrayList
What is the difference between List and Set in Java?
The main difference is that List allows duplicates and maintains order, while Set does not allow duplicates and does not maintain order.
List and Set are the same in terms of functionality and performance.
List does not allow duplicates and maintains order, while Set allows duplicates and does not maintain order.
Both List and Set allow duplicates but List maintains order while Set does not.
How does the HashMap work in Java?
A HashMap stores data in a linear array format.
A HashMap automatically sorts the keys in ascending order.
A HashMap requires keys to be unique but allows duplicate values.
A HashMap in Java uses a hash table to store key-value pairs, allowing for efficient data retrieval.
What is the purpose of the Iterator interface?
To define a method for sorting collections
To create new collection types
The purpose of the Iterator interface is to provide a standard way to traverse and manipulate collections of objects.
To enforce data encapsulation in collections
Explain the concept of multithreading in Java.
Multithreading in Java refers to the use of multiple processes instead of threads.
Multithreading in Java is the execution of a single thread to enhance performance.
Multithreading in Java is a method to run applications sequentially without any concurrency.
Multithreading in Java is the concurrent execution of two or more threads to maximize CPU utilization and improve application performance.
What is the difference between a thread and a process?
A thread is a standalone execution unit with its own memory, while a process shares memory with other threads.
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 and processes are identical in terms of memory usage and execution.
A process is a lightweight execution unit that shares memory, while a thread is a heavy execution unit with its own memory.
How do you create a thread in Java?
You can create a thread by extending the Thread class or implementing the Runnable interface.
Threads can only be created using the synchronized keyword.
You must use the ExecutorService interface to create a thread.
You can create a thread by using the ThreadPoolExecutor class.
What is the purpose of the synchronized keyword?
To ensure that only one thread can access a block of code or an object at a time.
To automatically manage memory allocation for threads.
To improve the performance of multithreaded applications.
To allow multiple threads to access a block of code simultaneously.
What are the potential issues with multithreading?
Increased memory efficiency
Faster execution time
Potential issues with multithreading include race conditions, deadlocks, thread contention, and increased debugging complexity.
Simplified code structure
Explain the concept of deadlock in Java.
Deadlock occurs when a thread completes its execution without releasing resources.
Deadlock is a method for synchronizing threads in Java.
Deadlock happens when threads run in parallel without any resource contention.
Deadlock is a situation in Java where two or more threads are unable to proceed because each is waiting for the other to release a resource.
What is the mechanism to read/write data (bytes or characters)?
I/O Streams
File handling
Network communication
Data storage
What is the purpose of capturing user input via console?
File handling
Interactive CLI applications
Logging
Data storage
What is the definition of displaying output to the console?
Logging
User feedback
File handling
Data storage
What is the character-based output stream used for writing formatted text to files?
PrintWriter Class
BufferedReader
FileInputStream
Scanner
What is the definition of file I/O using Reader/Writer classes?
Reading and Writing Files
File handling
Data storage
Logging
What are Java programs embedded in browsers called?
Applets
Classes
Methods
Interfaces
What is the type-checking operator in Java?
instanceof Keyword
stricƞp Keyword
native Methods
String Operations
What enforces IEEE 754 floating-point standard?
stricƞp Keyword
instanceof Keyword
native Methods
String Construction
What are methods implemented in non-Java languages called?
native Methods
Java Methods
String Operations
Applet Methods
What is the process of creating string objects?
String Construction
String Operations
String Comparison
String Buffer
What are built-in string methods used for?
Formatting, parsing, transformation
Data storage
String comparison
String construction
What is the process of accessing characters by index?
Character Extraction
String Comparison
String Operations
String Construction
What is the method for comparing string values?
String Comparison
String Extraction
String Operations
String Construction
What is the process of finding substrings or characters?
Searching a String
String Comparison
String Operations
String Construction
What is the process of creating transformed strings?
Modifying a String
String Comparison
String Operations
String Construction
What is the mutable string class that is thread-safe?
StringBuffer
StringBuilder
String
String Operations
What is the root interface for data structures?
Collection Interface
List Interface
Map Interface
Set Interface
What are implementations like ArrayList and HashSet used for?
Collection Classes
Data Structures
Interfaces
Abstract Classes
What are fixed-size containers of same-type elements called?
Arrays
Collections
Lists
Sets
What is the interface for custom sorting logic?
Comparators
Collections
Arrays
Lists
Which of these cannot be used for a variable name in Java?
identifier & keyword
identifier
keyword
none of the mentioned
Which component is used to compile, debug and execute the java programs?
JRE
JIT
JDK
JVM
Which of the following is not an OOPS concept in Java?
Polymorphism
Compilation
Inheritance
Encapsulation
Which of these are selection statements in Java?
break
continue
for()
if()
What is the value stored in x in following lines of code?
int x, y, z;
x = 0;
y = 1;
x = y = z = 8;
1
9
8
0
Evaluate the following Java expression, if x=3, y=5, and z=10:
++z + y - y + z + x++
24
23
20
25
Which of the following for loop declaration is not valid?
for ( int i = 99; i >= 0; i / 9 )
for ( int i = 7; i <= 77; i += 7 )
for ( int i = 20; i >= 2; - -i )
for ( int i = 2; i <= 20; i = 2* i )
What does JVM stands for?
Java Variable Machine
Java Virtual Machine
Java Virtual Mechanism
None of the above
What are the main Distribution types of Java Software?
Java SE (Java Standard Edition)
Java EE (Java Enterprise Edition)
Java ME (Java Micro Edition)
All the above
What is JVM ?
JVM is the confined memory area
All java programs run inside JVM memory
JVM provides security to the computer by giving controlled access to Files and Memory on a computer
All the above
What are the values of var1 and var2 when the code finishes executing?
var1 = 1, var2 = 1
var1 = 2 , var2 = 0
var1 = 3, var2 = -1
var1 = 0, var2 = 2
The loop will cause a run-time error for division by zero
What are the values of x and y when the code finishes executing?
x = 5, y = 2
x = 2, y = 5
x = 3, y = 4
x = 4, y = 3
Infinite Loop
How many stars are printed?
7
3
4
5
Infinite Loop
In total, how many times is the inner loop executed?
5
10
15
50
Infinite Loop
How many times does the loop print a *
40
20
24
30
Infinite Loop
What does the following code print?
A rectangle of 8 rows with 5 stars per row
A rectangle of 8 rows with 4 stars per row
A rectangle of 6 rows with 5 stars per row
A rectangle of 6 rows with 4 stars per row
Infinite Looo
What does the following code print?
A rectangle of 9 rows with 5 stars per row
A rectangle of 6 rows with 6 stars per row
A rectangle of 7 rows with 5 stars per row
A rectangle of 7 rows with 6 stars per row
Infinite Loop
How many times is "HI!" printed?
15
12
10
8
Infinite Loop
What does the following code print?
5 6 7 8 9
4 5 6 7 8 9 10 11 12
3 5 7 9 11
3 4 5 6 7 8 9 10 11 12
How many times does the following method print a *?
9
6
7
10
What does the following code segment print?
5 4 3 2 1
-5 -4 -3 -2 -1
-4 -3 -2 -1 0
How many times does the code print a * ?
7
8
12
13
How many times does this print a * ?
4
5
6
7
How many times does this code print at * ?
5
6
7
8
What does the code print?
1 2 3 4
1 2 3 4 5
0 1 2 3 4
0 1 2 3 4 5
How many stars are printed?
10
5
25
50
What is printed when the code segment is executed?
0 2 4 6 8 10 12 14 16 18
0 6 12 18
1 4 7 10 13 16 19
4 10 16
ar, given the following declaration:int[] ar = {2, 4, 6, 8 }0, 1, 2, 31, 2, 3, 40, 2, 4, 6What is the first index of an array?
1
0
2
3
For the array:
int stats[3];
What is the range of the index?
0 to 3
0 to 2
1 to 3
0 to 4
int [] nums = {2, 3, 5, 8, 9, 11};
How would you access the fourth element in nums?
nums[4]
nums[3]
nums(4)
nums(3)
