Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

51.

Which of the following code is used to get an attribute in a HTTP Session object in servlets?(a) session.getAttribute(String name)(b) session.alterAttribute(String name)(c) session.updateAttribute(String name)(d) session.setAttribute(String name)

Answer» Right choice is (a) session.getAttribute(String name)

Easiest explanation: session has various methods for use.
52.

How is the dynamic interception of requests and responses to transform the information done?(a) servlet container(b) servlet config(c) servlet context(d) servlet filter

Answer» Right option is (d) servlet filter

The best explanation: Servlet has various components like container, config, context, filter. Servlet filter provides the dynamic interception of requests and responses to transform the information.
53.

Which of the following leads to high network traffic?(a) URL rewriting(b) Hidden form fields(c) SSL sessions(d) Cookies

Answer» Correct answer is (a) URL rewriting

Explanation: WRL rewriting requires large data transfer to and from the server which leads to network traffic and access may be slow.
54.

Which of the following is not true about session?(a) All users connect to the same session(b) All users have same session variable(c) Default timeout value for session variable is 20 minutes(d) New session cannot be created for a new user

Answer» The correct choice is (c) Default timeout value for session variable is 20 minutes

To explain I would say: Default timeout value for session variable is 20 minutes. This can be changed as per requirement.
55.

Which of the following is used for session migration?(a) Persisting the session in database(b) URL rewriting(c) Create new database connection(d) Kill session from multiple sessions

Answer» Right option is (a) Persisting the session in database

Easy explanation: Session migration is done by persisting session in database. It can also be done by storing session in memory on multiple servers.
56.

Which of these keywords must be used to monitor for exceptions?(a) try(b) finally(c) throw(d) catch

Answer» The correct option is (a) try

Easiest explanation: None.
57.

When does Exceptions in Java arises in code sequence?(a) Run Time(b) Compilation Time(c) Can Occur Any Time(d) None of the mentioned

Answer» The correct choice is (a) Run Time

To explain I would say: Exceptions in Java are run-time errors.
58.

Which concept of Java is a way of converting real world objects in terms of class?(a) Polymorphism(b) Encapsulation(c) Abstraction(d) Inheritance

Answer» Right option is (c) Abstraction

Explanation: Abstraction is the concept of defining real world objects in terms of classes or interfaces.
59.

Which of the following method is used inside session only?(a) merge()(b) update()(c) end()(d) kill()

Answer» Right choice is (b) update()

Explanation: update() method can only be used inside session. update() should be used if session does not contain persistent object.
60.

Which feature of java 8 enables us to create a work stealing thread pool using all available processors at its target?(a) workPool(b) newWorkStealingPool(c) threadPool(d) workThreadPool

Answer» The correct option is (b) newWorkStealingPool

For explanation: Executors newWorkStealingPool() method to create a work-stealing thread pool using all available processors as its target parallelism level.
61.

Which of these method wakes up the first thread that called wait()?(a) wake()(b) notify()(c) start()(d) notifyAll()

Answer» Correct option is (b) notify()

The best explanation: None.
62.

Which of these keywords is not a part of exception handling?(a) try(b) finally(c) thrown(d) catch

Answer» Correct answer is (c) thrown

Best explanation: Exceptional handling is managed via 5 keywords – try, catch, throws, throw and finally.
63.

Which component is responsible for converting bytecode into machine specific code?(a) JVM(b) JDK(c) JIT(d) JRE

Answer» Correct option is (a) JVM

To elaborate: JVM is responsible to converting bytecode to the machine specific code. JVM is also platform dependent and provides core java functions like garbage collection, memory management, security etc.
64.

Which component is used to compile, debug and execute java program?(a) JVM(b) JDK(c) JIT(d) JRE

Answer» Right choice is (b) JDK

Explanation: JDK is a core component of Java Environment and provides all the tools, executables and binaries required to compile, debug and execute a Java Program.
65.

Which component is responsible to optimize bytecode to machine code?(a) JVM(b) JDK(c) JIT(d) JRE

Answer» The correct choice is (c) JIT

The best I can explain: JIT optimizes bytecode to machine specific language code by compiling similar bytecodes at the same time. This reduces overall time taken for compilation of bytecode to machine specific language.
66.

Which of these keywords are used for generating an exception manually?(a) try(b) catch(c) throw(d) check

Answer» Right choice is (c) throw

The explanation: None.
67.

What is the use of try & catch?(a) It allows us to manually handle the exception(b) It allows to fix errors(c) It prevents automatic terminating of the program in cases when an exception occurs(d) All of the mentioned

Answer» Correct answer is (d) All of the mentioned

Best explanation: None.
68.

Which of these method of Locale class can be used to obtain country of operation?(a) getCountry()(b) whichCountry()(c) DisplayCountry()(d) getDisplayCountry()

Answer» Right choice is (d) getDisplayCountry()

The best I can explain: None.
69.

Which component is responsible to run java program?(a) JVM(b) JDK(c) JIT(d) JRE

Answer» Correct choice is (d) JRE

The explanation is: JRE is the implementation of JVM, it provides platform to execute java programs.
70.

Which page directive should be used in JSP to generate a PDF page?(a) contentType(b) generatePdf(c) typePDF(d) contentPDF

Answer» Right choice is (a) contentType

The best I can explain: <%page contentType=”application/pdf”> tag is used in JSP to generate PDF.
71.

What is synchronization in reference to a thread?(a) It’s a process of handling situations when two or more threads need access to a shared resource(b) It’s a process by which many thread are able to access same shared resource simultaneously(c) It’s a process by which a method is able to access many different threads simultaneously(d) It’s a method that allow too many threads to access any information require

Answer» Right choice is (a) It’s a process of handling situations when two or more threads need access to a shared resource

The best I can explain: When two or more threads need to access the same shared resource, they need some way to ensure that the resource will be used by only one thread at a time, the process by which this is achieved is called synchronization
72.

Which of these keywords is used to define packages in Java?(a) pkg(b) Pkg(c) package(d) Package

Answer» Right choice is (c) package

To elaborate: None.
73.

Which of these is used to perform all input & output operations in Java?(a) streams(b) Variables(c) classes(d) Methods

Answer» The correct choice is (a) streams

To elaborate: Like in any other language, streams are used for input and output operations.
74.

What happens if IP Address of host cannot be determined?(a) The system exit with no message(b) UnknownHostException is thrown(c) IOException is thrown(d) Temporary IP Address is assigned

Answer» Right choice is (b) UnknownHostException is thrown

The explanation: UnknownHostException is thrown when IP Address of host cannot be determined. It is an extension of IOException.
75.

Which of these class can generate pseudorandom numbers?(a) Locale(b) Rand(c) Random(d) None of the mentioned

Answer» Correct choice is (c) Random

Best explanation: None.
76.

Which of these process occur automatically by java run time system?(a) Serialization(b) Memory allocation(c) Deserialization(d) All of the mentioned

Answer» Correct option is (d) All of the mentioned

Easy explanation: Serialization, deserialization and Memory allocation occur automatically by java run time system.
77.

Which class is used to generate random number?(a) java.lang.Object(b) java.util.randomNumber(c) java.util.Random(d) java.util.Object

Answer» Correct option is (c) java.util.Random

For explanation I would say: java.util.random class is used to generate random numbers in java program.
78.

Which of the following is not a segment of memory in java?(a) Stack Segment(b) Heap Segment(c) Code Segment(d) Register Segment

Answer» Correct answer is (d) Register Segment

Explanation: There are only 3 types of memory segment. Stack Segment, Heap Segment and Code Segment.
79.

Which of these class is necessary to implement datagrams?(a) DatagramPacket(b) DatagramSocket(c) All of the mentioned(d) None of the mentioned

Answer» Right option is (c) All of the mentioned

The best explanation: None.
80.

Which of these methods returns the total number of bytes of memory available to the program?(a) getMemory()(b) TotalMemory()(c) SystemMemory()(d) getProcessMemory()

Answer» Right option is (b) TotalMemory()

To elaborate: TotalMemory() returns the total number of bytes available to the program.
81.

Which of these is used to read a string from the input stream?(a) get()(b) getLine()(c) read()(d) readLine()

Answer» Right option is (c) read()

To explain I would say: None.
82.

Which of these classes are used by character streams for input and output operations?(a) InputStream(b) Writer(c) ReadStream(d) InputOutputStream

Answer» The correct choice is (b) Writer

For explanation: Character streams uses Writer and Reader classes for input & output operations.
83.

Which of these method of DatagramPacket class is used to find the destination address?(a) findAddress()(b) getAddress()(c) Address()(d) whois()

Answer» Correct option is (b) getAddress()

Easy explanation: None.
84.

Which of these class must be used to send a datagram packets over a connection?(a) InetAdress(b) DatagramPacket(c) DatagramSocket(d) All of the mentioned

Answer» The correct option is (d) All of the mentioned

Explanation: By using 5 classes we can send and receive data between client and server, these are InetAddress, Socket, ServerSocket, DatagramSocket, and DatagramPacket.
85.

Which of these events is generated when the component is added or removed?(a) ComponentEvent(b) ContainerEvent(c) FocusEvent(d) InputEvent

Answer» The correct answer is (b) ContainerEvent

For explanation: A ContainerEvent is generated when a component is added to or removed from a container. It has two integer constants COMPONENT_ADDED & COMPONENT_REMOVED.
86.

Which of these class can generate an array which can increase and decrease in size automatically?(a) ArrayList()(b) DynamicList()(c) LinkedList()(d) MallocList()

Answer» The correct choice is (a) ArrayList()

For explanation: None.
87.

Which of these class can be used to implement the input stream that uses a character array as the source?(a) BufferedReader(b) FileReader(c) CharArrayReader(d) FileArrayReader

Answer» Correct choice is (c) CharArrayReader

Best explanation: CharArrayReader is an implementation of an input stream that uses character array as a source. Here array is the input source.
88.

Which of these class is not related to input and output stream in terms of functioning?(a) File(b) Writer(c) InputStream(d) Reader

Answer» Right option is (a) File

The explanation: A File describes properties of a file, a File object is used to obtain or manipulate the information associated with a disk file, such as the permissions, time date, and directories path, and to navigate subdirectories.
89.

Which of these method of DatagramPacket is used to obtain the byte array of data contained in a datagram?(a) getData()(b) getBytes()(c) getArray()(d) recieveBytes()

Answer» Correct answer is (a) getData()

Easiest explanation: None.
90.

Which of these classes can schedule task for execution in future?(a) Thread(b) Timer(c) System(d) Observer

Answer» The correct choice is (b) Timer

To explain I would say: Timer and TimerTask are the classes that support the ability to schedule tasks for execution at some future time.
91.

Which of these methods can be used to obtain the reference to the container that generated a ContainerEvent?(a) getContainer()(b) getContainerCommand()(c) getActionEvent()(d) getContainerEvent()

Answer» Correct answer is (d) getContainerEvent()

For explanation I would say: None.
92.

Which of these methods are used to register a mouse motion listener?(a) addMouse()(b) addMouseListener()(c) addMouseMotionListner()(d) eventMouseMotionListener()

Answer» The correct answer is (c) addMouseMotionListner()

To explain: None.
93.

Which of these methods will respond when you click any button by mouse?(a) mouseClicked()(b) mouseEntered()(c) mousePressed()(d) all of the mentioned

Answer» The correct answer is (d) all of the mentioned

Best explanation: when we click a button, first we enter the region of button hence mouseEntered() method responds then we press the button which leads to respond from mouseClicked() and mousePressed().
94.

Which of these events is generated when the window is closed?(a) TextEvent(b) MouseEvent(c) FocusEvent(d) WindowEvent

Answer» Right option is (d) WindowEvent

Easiest explanation: A WindowEvent is generated when a window is opened, close, activated or deactivated.
95.

Which of these is specified by a File object?(a) a file in disk(b) directory path(c) directory in disk(d) none of the mentioned

Answer» Right answer is (c) directory in disk

The explanation: None.
96.

Which of these method of Array class is used sort an array or its subset?(a) binarysort()(b) bubblesort()(c) sort()(d) insert()

Answer» Right option is (c) sort()

Explanation: None.
97.

Which of these are legacy classes?(a) Stack(b) Hashtable(c) Vector(d) All of the mentioned

Answer» The correct option is (d) All of the mentioned

To explain: Stack, Hashtable, Vector, Properties and Dictionary are legacy classes.
98.

Which of these methods can be used to obtain the coordinates of a mouse?(a) getPoint()(b) getCoordinates()(c) getMouseXY()(d) getMouseCordinates()

Answer» Correct choice is (a) getPoint()

The explanation is: getPoint() method can be used to obtain coordinates of a mouse, alternatively we can use getX() and getY() methods for x and y coordinates of mouse respectively.
99.

Which of these methods can be used to know the type of focus change?(a) typeFocus()(b) typeEventFocus()(c) isTemporary()(d) isPermanent()

Answer» Correct answer is (c) isTemporary()

Explanation: There are two types of focus events – permanent and temporary. The isTemporary() method indicates if this focus change is temporary, it returns a Boolean value.
100.

Which of these is a method of class Date which is used to search whether object contains a date before the specified date?(a) after()(b) contains()(c) before()(d) compareTo()

Answer» Right option is (c) before()

Explanation: before() returns true if the invoking Date object contains a date that is earlier than one specified by date, otherwise it returns false.