1.
The ………………………. loop is especially useful when you process a menu selection.
Correct Answer
B. Do-while
Explanation
The do-while loop is especially useful when you process a menu selection because it guarantees that the loop will be executed at least once, regardless of the initial condition. This is important when processing a menu selection because you want to ensure that the user has the opportunity to make a selection before the loop terminates.
2.
. By using …………………….., you can force immediate termination of loop, bypassing the conditional expression and any remaining code in the body of the loop.
Correct Answer
B. Break
Explanation
By using "break", you can force immediate termination of the loop, bypassing the conditional expression and any remaining code in the body of the loop. This means that when the "break" statement is encountered, the program will exit the loop and continue with the next statement after the loop. It is commonly used to exit a loop early when a certain condition is met or when a specific outcome is desired.
3.
Which of the following option leads to the portability and security of Java?
Correct Answer
A. Bytecode is executed by JVM
Explanation
Bytecode is executed by JVM leads to the portability and security of Java. The Java programming language is compiled into bytecode, which is a platform-independent code. This means that the bytecode can be executed on any device that has a Java Virtual Machine (JVM) installed, regardless of the underlying hardware or operating system. This portability allows Java programs to run on different platforms without the need for recompilation. Additionally, the JVM provides a secure execution environment by enforcing various security measures, such as sandboxing and access control, to prevent malicious code from causing harm to the system.
4.
Which of the following is not a Java features?
Correct Answer
C. Use of pointers
Explanation
The use of pointers is not a feature in Java. Pointers are used in programming languages like C and C++ to directly manipulate memory addresses, allowing for more fine-grained control over memory management. However, Java was designed to be a safer and more secure language, and therefore does not support the use of pointers. Instead, Java uses references to objects, which provide a level of abstraction and automatic memory management.
5.
_____ is used to find and fix bugs in the Java programs.
Correct Answer
D. JDB
Explanation
JDB (Java Debugger) is used to find and fix bugs in Java programs. It is a command-line tool provided by the JDK (Java Development Kit) that allows developers to step through their code, set breakpoints, and inspect variables to identify and resolve issues. JDB helps in the debugging process by providing features like stack trace, breakpoints, and variable monitoring, making it an essential tool for Java programmers.
6.
Which of the following is a valid declaration of a char?
Correct Answer
A. Char ch = '\utea';
Explanation
The given declaration "char ch = '\utea';" is a valid declaration of a char. In Java, a char can be represented by a single character enclosed in single quotes. The '\u' escape sequence is used to represent Unicode characters. In this case, '\utea' represents a Unicode character with the hexadecimal value of 'tea'. Therefore, the declaration is valid.
7.
What is the return type of the hashCode() method in the Object class?
Correct Answer
B. Int
Explanation
The return type of the hashCode() method in the Object class is int. This method is used to generate a unique hash code value for an object, which is an integer representation of the object's memory address. It is commonly used in data structures like hash tables to efficiently store and retrieve objects.
8.
What does the expression float a = 35 / 0 return?
Correct Answer
D. Run time exception
Explanation
The expression "float a = 35 / 0" will return a runtime exception. This is because dividing any number by zero is undefined in mathematics, and therefore, it is not allowed in programming. When attempting to divide by zero, a runtime exception is thrown, indicating an error in the program.
9.
Which of the following for loop declaration is not valid?
Correct Answer
A. For ( int i = 99; i >= 0; i / 9 )
Explanation
The given for loop declaration is not valid because the increment or decrement expression is missing. In a for loop, the third part is responsible for updating the loop variable after each iteration. In this case, the expression "i / 9" does not modify the value of "i", which will result in an infinite loop.
10.
Which method of the Class.class is used to determine the name of a class represented by the class object as a String?
Correct Answer
C. GetName()
Explanation
The getName() method is used to determine the name of a class represented by the class object as a String. This method returns the fully qualified name of the class, including the package name, in the form of a String.
11.
In which process, a local variable has the same name as one of the instance variables?
Correct Answer
B. Variable Shadowing
Explanation
Variable shadowing occurs when a local variable within a certain scope has the same name as an instance variable. This can happen in any process or programming language, not specifically related to serialization, abstraction, or multi-threading. It is a common practice to use variable shadowing to differentiate between local and instance variables and avoid naming conflicts.
12.
Which package contains the Random class?
Correct Answer
A. Java.util package
Explanation
The Random class is part of the java.util package. This package contains utility classes and interfaces, including those for handling collections, dates, and random number generation. The java.lang package contains fundamental classes and interfaces that are automatically imported into every Java program. The java.awt package is used for creating graphical user interfaces, and the java.io package is used for input and output operations.
13.
An interface with no fields or methods is known as a ______.
Correct Answer
B. Marker Interface
Explanation
A marker interface is an interface with no fields or methods. It is used to mark classes that implement it as having certain characteristics or capabilities. In this case, an interface with no fields or methods is referred to as a marker interface.
14.
Which of the following is an immediate subclass of the Panel class?
Correct Answer
A. Applet class
Explanation
The immediate subclass of the Panel class is the Applet class. This means that the Applet class directly extends the Panel class.
15.
Which option is false about the final keyword?
Correct Answer
C. A final class cannot extend other classes.
Explanation
The final keyword is used to restrict the modification of a class, method, or variable. It ensures that the class cannot be extended and the method cannot be overridden in its subclasses. However, a final method can still be inherited by its subclasses. Therefore, the false option is "A final class cannot extend other classes."
16.
Which of these classes are the direct subclasses of the Throwable class?
Correct Answer
C. Error and Exception class
Explanation
The direct subclasses of the Throwable class are Error and Exception class. This means that both Error and Exception class inherit directly from the Throwable class. The other classes mentioned in the options, such as RuntimeException, VirtualMachineError, and IOException, may be subclasses of either Error or Exception, but they are not direct subclasses of Throwable.
17.
What do you mean by chained exceptions in Java?
Correct Answer
B. An exception caused by other exceptions
Explanation
Chained exceptions in Java refer to an exception that is caused by another exception. When an exception occurs, it can be caught and then rethrown as a different exception, with the original exception being set as the cause of the new exception. This allows for a more detailed and informative error message, as the chain of exceptions provides a trace of what caused the error. By including the original exception as the cause, developers can easily identify the root cause of the problem and handle it accordingly.
18.
In which memory a String is stored, when we create a string using new operator?
Correct Answer
C. Heap memory
Explanation
When we create a string using the new operator, the string is stored in the heap memory. The heap memory is a region of the computer's memory where dynamically allocated memory is stored. Strings created using the new operator are stored in the heap because they are dynamically allocated and can be of variable length. This allows for flexibility in memory allocation and deallocation, as the heap memory can be managed by the programmer.
19.
Which keyword is used for accessing the features of a package?
Correct Answer
B. Import
Explanation
The keyword "import" is used for accessing the features of a package. When we want to use classes, interfaces, or other members from a package in our code, we need to import the package using the "import" keyword. This allows us to access and use the classes and other elements defined within the package in our program.
20.
In java, jar stands for_____.
Correct Answer
D. None of the above