Computer Knowledge
Java Core Classes and Threads
1,473 Questions
Java core classes and threads form the foundation of object oriented programming and are crucial for IT officer and programming exams. This includes concepts like string mutability, collections, and multithreading. Solve these questions to test your practical coding and theoretical knowledge.
String and StringBuffer classesThread execution methodsJava collections frameworkCharacter streams input outputVariable serialization rules
Java Core Classes and Threads Questions
-
to update the working document with the results of service
-
to update the screen input in working document
-
to specify the next event to be executed
-
to format the working document
B
Correct answer
Explanation
In client events, which handle user interaction, the Out parameter is responsible for updating screen-related input data in the working document. Option A describes service events, not client events. Option C refers to flow control. Option D is not the standard terminology for client event Out parameters.
-
Trap it with a Handler
-
Propagate it to the Calling Environment
-
A & Then B
-
B & Then A
C
Correct answer
Explanation
Exception handling involves first trapping the exception with a handler in the EXCEPTION block, then optionally propagating it to the calling environment if the handler cannot resolve it. This two-step approach (handle then propagate if needed) is the standard pattern.
-
doGet()
-
doPost()
-
execute()
-
validate()
B
Correct answer
Explanation
In Struts Action classes, doPost() handles POST requests and doPost() is indeed used for posting information. doGet() handles GET requests. execute() is the older Struts 1.x method, and validate() is for input validation, not posting data.
-
doGet()
-
doPost()
-
execute()
-
validate()
B
Correct answer
Explanation
In Struts/MVC frameworks, doPost() handles HTTP POST requests for submitting form data to Action classes. doGet() handles GET requests (read operations). execute() is a Struts 1 method, validate() is for input validation. The question specifically asks about 'posting'.
-
log.debug
-
log.info
-
log.error
-
System.out.println
A
Correct answer
Explanation
For debugging purposes, log.debug is the most appropriate choice as it provides fine-grained diagnostic information that can be enabled in development and disabled in production without performance impact. The info level is for significant application events, error for problems requiring attention, and System.out.println bypasses the logging framework entirely.
-
Session.Close()
-
Session.discard()
-
Session.Abandon()
-
Session.Exit()
C
Correct answer
Explanation
In ASP.NET, the Session.Abandon() method is the standard way to destroy a user's session and release its resources. Alternative methods like Session.Close(), Session.discard(), or Session.Exit() do not exist as valid session termination APIs in the framework.
-
Viewlet
-
Applet
-
Servlet
-
Object
B
Correct answer
Explanation
An Applet is a specialized Java program designed to run within web browsers, transmitted over the Internet and executed client-side. Unlike Servlets which run server-side, Applets provided early web interactivity before modern JavaScript frameworks emerged.
-
OnItemChanged();
-
OnFieldChanged();
-
OnPropertyChanged();
-
All of the above
C
Correct answer
Explanation
OnPropertyChanged() is the standard method called when a property value changes in data binding scenarios. This method implements INotifyPropertyChanged and notifies the UI that bound data has changed, triggering UI updates. OnItemChanged and OnFieldChanged are not standard Silverlight/WPF patterns.
-
getMethod
-
get () method
-
getMethod()
-
get.Method()
C
Correct answer
Explanation
The standard convention for method names in Java uses camelCase followed by parentheses representing the parameter list, such as getMethod(). Names without parentheses or containing spaces or dots are invalid method identifiers.
-
To provide access to the Java runtime system.
-
To avoid run time exception.
-
To provide the capability to execute code no matter whether or not an exception is thrown or caught.
-
Both 2 & 3
A
Correct answer
Explanation
The Runtime class in Java provides access to the Java runtime environment. It allows applications to interface with the environment in which they are running. Common uses include executing system commands (exec), forcing garbage collection (gc), getting free memory (freeMemory), and terminating the JVM (exit). It does not handle exceptions or provide finally-like behavior.
-
all sub-classes of Throwable
-
not the sub classes of RuntimeException
-
all sub-classes of Error
-
None of these
B
Correct answer
Explanation
Checked exceptions are exceptions that must be either caught or declared in a throws clause. They are all subclasses of Throwable EXCEPT RuntimeException and its subclasses (unchecked exceptions) and Error and its subclasses (system errors). So checked exceptions are 'not the subclasses of RuntimeException' (and also not Error subclasses).
-
the heap space occupied by an un-referenced object can be recycled and made available for subsequent new objects
-
When the total memory allocated to a Java program exceeds some threshold the garbage coollector is invoked
-
the program does not suspend during garbage collection
-
garbage collection requires extra memory
C
Correct answer
Explanation
Java garbage collection typically suspends all application threads during the collection phase, causing 'stop-the-world' pauses. This is necessary to safely identify and reclaim unreachable objects without concurrent modifications.
-
Session.saveorupdate()
-
Session.remove()
-
Session.load()
-
Session.save()
B
Correct answer
Explanation
Standard Hibernate Session methods include save(), saveOrUpdate(), load(), get(), delete(), update(), and others. There is no remove() method in the Session interface - deletion is done via delete().
-
FaultException
-
RESTException
-
WebFaultException
-
WebHttpFaultException
C
Correct answer
Explanation
WebFaultException is the specific exception type for WCF RESTful services (WebHttpBinding). It allows returning HTTP status codes along with fault information. FaultException is for SOAP services. RESTException and WebHttpFaultException do not exist in WCF.