Computer Knowledge

Java Core Classes and Threads

1,935 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

Multiple choice technology programming languages
  1. You forgot the hashCode method

  2. You didn't handle circular references properly

  3. Could be any / both of above

  4. None of above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Hashtable relies on both equals() and hashCode() to store and locate keys. If you override equals() but not hashCode(), equal objects will have different hash codes, preventing Hashtable from finding them. Circular references can also cause infinite loops or incorrect behavior during lookup.

Multiple choice technology web technology
  1. Throws an exception.

  2. Executes the action method and throws an exception.

  3. Executes the action method and renders current view.

  4. Controller will be in the same page

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The claimed answer is C. When a commandLink or commandButton action method returns null, JSF executes the action method but then re-renders the current view instead of navigating to a different page. Option A and B are incorrect because no exception is thrown. Option D is misleading - it's not just 'same page', it's explicitly re-rendering the current view after action execution.

Multiple choice technology web technology
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The processDecodesWithoutValidation method in JSF does exactly what its name suggests: it executes the Apply Request Values phase and decodes parameters without running validation. This is useful for scenarios where you want to process submitted data but skip validation logic. The method will handle RuntimeExceptions appropriately, but its key characteristic is bypassing the validation phase for immediate components.

Multiple choice technology platforms and products
  1. call_form

  2. new_form

  3. open_form

  4. both b) & c)

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

OPEN_FORM is the correct method when you need to use both the calling form and called form simultaneously. CALL_FORM replaces the calling form and control returns only after the called form exits, while NEW_FORM replaces the calling form completely without returning.

Multiple choice technology web technology
  1. Unchecked

  2. Checked

  3. All of the Above

  4. None of the Above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The Struts 2 exception handling mechanism primarily handles unchecked exceptions (RuntimeException and its subclasses). Checked exceptions need to be caught and handled by the application code or wrapped in runtime exceptions. The exception mapping in struts.xml works with unchecked exceptions.

Multiple choice technology platforms and products
  1. java.lang.Error

  2. java.lang.Throwable

  3. java.lang.Util

  4. java.lang.CheckedException

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In Java's exception hierarchy, Throwable is the base class for all throwable objects. Exception inherits directly from Throwable, while Error is a separate subclass of Throwable for serious system errors that applications typically shouldn't catch.

Multiple choice technology platforms and products
  1. UncheckedException

  2. CheckedException

  3. Error

  4. UnspecifiedException

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

StackOverflowError and OutOfMemoryError are both subclasses of java.lang.Error, not Exception. Errors represent serious problems that applications should not typically catch - they indicate JVM-level issues rather than application logic problems.

Multiple choice technology platforms and products
  1. It will go for Garbage Collector

  2. It remains in Stack

  3. It will not create any object

  4. Exception objects will not put load on JVM

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

After an exception is handled and no references to the exception object remain, it becomes eligible for garbage collection like any other dereferenced Java object. It does not remain permanently on the stack.

Multiple choice technology platforms and products
  1. UncheckedException

  2. CheckedException

  3. Error

  4. UnspecifiedException

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

NullPointerException extends RuntimeException, making it an unchecked exception. This means developers aren't required to catch or declare it - it typically indicates programming errors like attempting to use a null reference where an object is required.

Multiple choice technology testing
  1. GetVisibleText

  2. GetROProperty

  3. SetROProperty

  4. GetTOProperty

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

GetROProperty (Get Run-Time Object Property) is the QTP/UFT method used to retrieve the current property value of a test object from the application during a run session. GetTOProperty retrieves properties from the test repository, and SetROProperty is not a valid method.

Multiple choice technology programming languages
  1. Session.Close ( )

  2. Session.Discard ( )

  3. Session.Abandon ( )

  4. Session.Exit ( )

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Session.Abandon() is the correct method to explicitly terminate a user's session in ASP.NET. It ends the current session, releases session resources, and fires the Session_End event. The other methods (Close, Discard, Exit) do not exist in the Session API.

Multiple choice technology platforms and products
  1. Thread.start()

  2. Thread.run()

  3. Thread.yield()

  4. A dead thread cannot be restarted.

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Once a Java thread completes its execution (exits its run() method) or is terminated, its state becomes 'TERMINATED' (dead). In JVM, you cannot restart a dead thread; attempting to call start() on it again will throw an IllegalThreadStateException.

Multiple choice technology platforms and products
  1. StringBuilder is immutable but StringBuffer is mutable.

  2. StringBuffer is immutable but StringBuilder is mutable.

  3. StringBuffer is Synchronized but StringBuilder is not.

  4. They both are immutable.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

StringBuffer is synchronized (thread-safe) while StringBuilder is not. Both classes are mutable - they can be modified after creation. StringBuilder is faster when you don't need thread safety.

Multiple choice technology platforms and products
  1. Implementing Thread interface.

  2. Implementing Cloneable interface.

  3. Implementing the Runnable interface.

  4. We can not create a Thread, JVM has to create it by it's own.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

A Thread can be created either by extending the Thread class or by implementing the Runnable interface. Option A is wrong because Thread is a class, not an interface. Option D is wrong - we can and do create Threads programmatically.