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 testing
  1. True

  2. False

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

The statement claims that .Object method is not applicable in Firefox, which is false. Firefox supports standard JavaScript object methods like those on Object.prototype (toString, hasOwnProperty, etc.). The question likely refers to a proprietary IE-specific method, but as written, False is the correct answer.

Multiple choice technology web technology
  1. Vector is synchronized whereas arraylist is not

  2. ArrayList is synchronized whereas Vector is not

  3. Both are same

  4. None of the Above

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

Vector is a legacy Java collection class that is synchronized (thread-safe), whereas ArrayList is not synchronized, making ArrayList faster but not safe for unsynchronized multi-threaded access.

Multiple choice technology web technology
  1. Yes

  2. No

  3. Cannot be determined

  4. None of the above

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

When System.exit(0) is called, the JVM terminates immediately. This bypasses all normal flow control including the finally block - the finally block will NOT execute. System.exit() halts the JVM completely, so no further code runs. Option A is incorrect because finally is only guaranteed for normal control flow and exceptions, not JVM termination. Option C is incorrect - the behavior is deterministic and well-defined.

Multiple choice technology web technology
  1. destroy()

  2. start()

  3. run()

  4. none of the above

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

In Java, every Thread must implement the run() method, which contains the code that executes in the thread. The start() method is called to begin execution but is not implemented by subclasses - run() is the method you override with your thread's logic.

Multiple choice technology web technology
  1. Transient variables are variable that cannot be serialized.

  2. Transient variables are variable that can be serialized.

  3. Transient variables has no special feature

  4. None of the above

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

The transient keyword in Java marks fields that should be skipped during serialization. When an object is serialized, transient fields are not written to the output stream and will have default values when deserialized.

Multiple choice technology web technology
  1. In a treeset data are placed in order

  2. In a hashset data are placed in order

  3. Both are same

  4. None of the above

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

TreeSet implements the SortedSet interface and maintains elements in ascending order using a red-black tree. HashSet does not guarantee any order and uses hash codes for storage, providing O(1) average case performance.

Multiple choice technology programming languages
  1. CWnd Destroy member function

  2. Explicitly deleting with the delete operator.

  3. Manually closing the windows

  4. Calling CWnd::DestroyWindow or the Windows API DestroyWindow.

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

Windows objects can be destroyed either by explicitly using the delete operator (which calls the destructor) or by calling the DestroyWindow API function (which destroys the window but not the C++ object). The CWnd::DestroyWindow member function wraps the Windows API. 'Manually closing windows' is ambiguous, and there is no 'CWnd Destroy' member function.

Multiple choice technology programming languages
  1. Response to a specific event.

  2. Events that handle response

  3. Handle screen event.

  4. Handle specific function.

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

An event handler is a callback function that executes in response to a specific event, such as a button click or keyboard input. Event handlers are fundamental to GUI programming and enable interactive user interfaces by responding to user actions.

Multiple choice technology programming languages
  1. Applet version has main method

  2. GUI components are added explicitly to the Applet

  3. Aplet class is declared private

  4. None of the above

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

All statements A, B, and C are false. Applets do not have a main method (they use init(), start(), etc.), GUI components can be added to containers in various ways, and the Applet class is public. Therefore D is correct.

Multiple choice technology programming languages
  1. Applet version has main method

  2. GUI components are added explicitly to the Applet

  3. Aplet class is declared private

  4. None of the above

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

Applets do not have a main method, their classes must be declared public, and GUI components are typically added to them. Thus, none of the specific statements about applets are true, making 'None of the above' correct.

Multiple choice technology web technology
  1. Sets all properties to their initial value

  2. Sets all properties to null

  3. Repopulates all properties from the request parameters

  4. none

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

The reset method on an ActionForm does not set properties to initial values, null, or repopulate from request parameters. The reset method is meant to reset properties to default values but must be implemented by the developer.

Multiple choice technology programming languages
  1. Locale loc = Locale.getLocale();System.out.println(loc.getDisplayCountry()+ “ “+ df.format(d));

  2. Locale bc = Locale.getLocale();System.out.println(loc.getDisplayCountry()+ “ “+ df.setDateFormat(d));

  3. Locale loc = Locale.getDefault();System.out.println(loc.getDisplayCountry()+ “ “+ df.setDateFormat(d));

  4. Locale loc = Locale.getDefault(); System.out.println(loc.getDisplayCountry()+ “ “ + df.format(d));

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

To solve this question, the user needs to understand the concepts of Locale, Date, and DateFormat objects.

Option A is incorrect because there is no such method as getLocale() in the Locale class. The correct method is getDefault(). Additionally, df.format(d) is used to format the date object d using the date format df. This option is incorrect because df.format(d) is called with a space between the method name and the parentheses.

Option B is incorrect because Locale.getLocale() is not a valid method in the Locale class. Also, df.setDateFormat(d) is not a valid method in the DateFormat class. Instead, df.format(d) should be used to format the Date object using the appropriate format.

Option C is incorrect because Locale.getDefault() is not used to get the current locale. Instead, Locale.getLocale() is used, which is not a valid method in the Locale class. df.setDateFormat(d) is also not a valid method in the DateFormat class. Instead, df.format(d) should be used to format the Date object using the appropriate format.

Option D is correct. Locale.getDefault() is used to get the current locale, and df.format(d) is used to format the Date object d using the appropriate date format. This option will output the current locale's country name and the appropriate version of the date object d.

Therefore, the correct answer is:

The Answer is: D

Multiple choice technology programming languages
  1. The time to determine whether a Person object is contained in a HashSet is constant and does NOT depend on the size of the map

  2. Deleting a Person key from a HashMap will delete all map entries for all keys of type Person

  3. Inserting a second Person object into a HashSet will cause the first Person object to be removed as a duplicate.

  4. The time to find the value from HashMap with a Person key depends on the size of the map.

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

A constant hashCode() implementation causes all Person objects to hash to the same bucket. While HashSet/HashMap insertion is constant-time (to the bucket), finding an object requires traversing all objects in that bucket (linear search with equals()), making lookup time O(n) dependent on map size.