Java Questions and Answers Part-26

1. Which of the following is not a memory classification in java?
a) Young
b) Old
c) Permanent
d) Temporary

Answer: d
Explanation: Young generation is further classified into Eden space and Survivor space. Old generation is also the tenured space. The permanent generation is the non heap space.

2. What is the Java 8 update of PermGen?
a) Code Cache
b) Tenured Space
c) Metaspace
d) Eden space

Answer: c
Explanation: Metaspace is the replacement of PermGen in Java 8. It is very similar to PermGen except that it resizes itself dynamically. Thus, it is unbounded.

3. Classes and Methods are stored in which space?
a) Eden space
b) Survivor space
c) Tenured space
d) Permanent space

Answer: d
Explanation: The permanent generation holds objects which JVM finds convenient to have the garbage collector. Objects describing classes and methods, as well as the classes and methods themselves, are a part of Permanent generation.

4. Where is String Pool stored?
a) Java Stack
b) Java Heap
c) Permanent Generation
d) Metaspace

Answer: b
Explanation: When a string is created; if the string already exists in the pool, the reference of the existing string will be returned, else a new object is created and its reference is returned.

5. The same import package/class be called twice in java?
a) true
b) false

Answer: a
Explanation: We can import the same package or same class multiple times. Neither compiler nor JVM complains will complain about it. JVM will internally load the class only once no matter how many times we import the same class or package.

6. Which of these exceptions handles the situations when an illegal argument is used to invoke a method?
a) IllegalException
b) Argument Exception
c) IllegalArgumentException
d) IllegalMethodArgumentExcepetion

Answer: c
Explanation: IllegalArgumentException

7. Which of these exceptions will be thrown if we declare an array with negative size?
a) IllegalArrayException
b) IllegalArraySizeExeption
c) NegativeArrayException
d) NegativeArraySizeExeption

Answer: d
Explanation: Array size must always be positive if we declare an array with negative size then built in exception “NegativeArraySizeException” is thrown by the java’s run time system.

8. Which of these packages contain all the Java’s built in exceptions?
a) java.io
b) java.util
c) java.lang
d) java.net

Answer: c
Explanation: java.lang

9. Which of these exceptions will be thrown if we use null reference for an arithmetic operation?
a) ArithmeticException
b) NullPointerException
c) IllegalAccessException
d) IllegalOperationException

Answer: b
Explanation: If we use null reference anywhere in the code where the value stored in that reference is used then NullPointerException occurs.

10. Which of these class is used to create user defined exception?
a) java.lang
b) Exception
c) RunTime
d) System

Answer: b
Explanation: Exception class contains all the methods necessary for defining an exception. The class contains the Throwable class.