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. 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 web technology
  1. start();

  2. service();

  3. init();

  4. destroys();

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

The Java Applet lifecycle has standard methods: init(), start(), stop(), paint(), and destroy(). The option 'destroys()' is incorrect because the actual method is 'destroy()' (not 'destroys()'), making it the option that is NOT a phase of the applet lifecycle.

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.

Multiple choice technology databases
  1. PreparedStatement

  2. ParameterizedStatement

  3. ParameterizedStatement and CallableStatement

  4. All kinds of Statements (i.e. which implement a sub interface of Statement)

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

PreparedStatement is the JDBC Statement type designed for executing parameterized queries with placeholders (?). It precompiles SQL statements, allowing efficient reuse with different parameter values. Statement (basic) doesn't support parameters, and CallableStatement is for stored procedures. ParameterizedStatement is not a valid JDBC interface.

Multiple choice technology programming languages
  1. A

  2. C

  3. D

  4. None of the Above

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

The intValue() method converts an Integer object to a primitive int. Among the listed options, valueOf() converts String/int to an Integer object, getInt() is not a standard Integer method, and getInteger() returns the Integer value of a system property. Therefore None of the Above is correct.

Multiple choice technology programming languages
  1. True

  2. False

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

Every class in Java inherits from the Object class, which defines the toString() method. Because of this, any object passed to System.out.println() can be printed, as the method automatically invokes the object's toString() representation.

Multiple choice technology programming languages
  1. public void logIt(String * msgs)

  2. public void logIt(String [] msgs)

  3. public void logIt(String... msgs)

  4. public void logIt(String msg1, String msg2, String msg3)

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

Java's varargs feature uses the ... syntax to accept a variable number of arguments. The declaration String... msgs allows zero or more String arguments to be passed, while still being compatible with passing an explicit String array.