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

Multiple choice technology web technology
  1. Fragment I compiles

  2. Fragment II compiles

  3. Fragment III compiles

  4. Fragment I executes without exception

  5. Fragment II executes without exception

  6. Fragment III executes without exception

Reveal answer Fill a bubble to check yourself
A,B,C,D,F Correct answer
Explanation

All three fragments compile since raw sets allow adding any Object. At runtime, HashSet and LinkedHashSet only require hashing, so they run without issues. However, TreeSet sorts elements, requiring them to be mutually comparable, throwing a ClassCastException when inserting an Object after a String.

Multiple choice technology programming languages
  1. Stateless session beans doesn’t preserve any state across method calls

  2. Stateful session beans can be accesses by multiple users at the same time

  3. None of the above

  4. Allof the above

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

Stateless session beans do not maintain conversational state across method calls - each call is independent. Stateful session beans maintain state for a specific client and cannot be accessed by multiple users simultaneously.

Multiple choice technology programming languages
  1. event-inheritance model

  2. event-delegation model

  3. Both a & b

  4. Event-polymorhism model

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

The event-inheritance model uses subclasses to handle events (older AWT approach), while the event-delegation model uses listeners where event sources delegate handling to separate listener objects (modern Java approach). Both models are valid event handling strategies.

Multiple choice technology
  1. getAllResponseHeaders()

  2. getResponseHeader(header)

  3. getResponseHeader(All)

  4. getAllHttpResponseHeaders()

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

getAllResponseHeaders() is the correct XMLHttpRequest method that retrieves all HTTP response headers as a single string. getResponseHeader(header) gets a specific header. Options C and D are non-existent methods.

Multiple choice technology programming languages
  1. The signature of a method is the name of the method the type of its return value.

  2. The signature of a method is the name of the method and the names of its parameters.

  3. The signature of a method is the name of the method and the data types of its parameters.

  4. The signature of a method is the name of the method, its parameter list, and its return type.

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

A method's signature consists of the method name and the data types of its parameters (in order). This uniquely identifies overloaded methods. The return type is NOT part of the signature in most languages (Java, C++). Parameter names don't matter for overloading resolution, only their types.

Multiple choice technology programming languages
  1. Visitor

  2. Observer

  3. Builder

  4. Proxy

  5. Iterator

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

The Iterator pattern provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation. This is the exact mechanism used by Java Collections. Patterns like Visitor, Observer, Builder, and Proxy serve entirely different architectural purposes.

Multiple choice technology programming languages
  1. Hashtable

  2. Hashmap

  3. Linked Hashmap

  4. Hashset

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

Hashtable is the only inherently synchronized option among these classes, making it thread-safe for concurrent access. HashMap and its variant LinkedHashMap are not synchronized by design, while HashSet cannot store key-value pairs. Hashtable's built-in synchronization makes it suitable for multi-threaded environments without requiring additional synchronization code.