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. 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.

Multiple choice technology programming languages
  1. itemID(int itemId)

  2. update(int itemId)

  3. setItemId(int itemId)

  4. mutateItemId(int itemId)

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

To solve this question, the user needs to understand the naming conventions used in JavaBeans to create setter methods for private instance variables.

According to JavaBeans conventions, setter methods for private instance variables should be named in the format setVariableName. Therefore, the correct method signature to modify the itemId instance variable in the Inventoryltem class should be:

C. setItemId(int itemId)

Option A: itemID(int itemId) is not following the JavaBeans naming standards for setter methods. The method name should start with the prefix set followed by the variable name.

Option B: update(int itemId) does not follow the JavaBeans naming conventions. The method name should start with the prefix set followed by the variable name.

Option D: mutateItemId(int itemId) is not a standard JavaBeans naming convention. The method name should start with the prefix set followed by the variable name.

Therefore, the correct answer is:

The Answer is: C. setItemId(int itemId)

Multiple choice technology programming languages
  1. Closing the stream

  2. flushing the stream

  3. writing to the stream

  4. writing a line separator to the stream

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

BufferedWriter has the newLine() method to write a platform-dependent line separator to the stream. FileWriter does not have a specific line-separator method and inherits standard write methods from OutputStreamWriter and Writer. Both classes support closing, flushing, and writing.

Multiple choice technology enterprise content management
  1. A Text Object by Name:- MyHello and text value:- MyHello gets created in the database.

  2. A Text Object by Name:- MyHello and text value:- Hello gets created in the database.

  3. A Text Object by Name:- Hello and text value:- MyHello gets created in the database.

  4. Nothing is created, as one 'key/important statement' is missing in the code.

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

In this specific object manager API, the first parameter of createTextObject represents the text content ("Hello") and the second represents the name ("MyHello"). The subsequent assignments swap these values, setting the name to "Hello" and text to "MyHello".

Multiple choice technology enterprise content management
  1. true, true

  2. true. false

  3. false, true

  4. true, undefined

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

This question relies on a proprietary API (likely Livelink/OpenText WCM). In this API, instantiating a WebObject with a type parameter activates it, whereas the default constructor leaves it inactive, resulting in true, false.

Multiple choice technology enterprise content management
  1. A cookie by Name cookie-myCookie is created.

  2. The cookie will expire exactly 15 days from the time it is created.

  3. The cookie will expire exactly 30 days from the time it is created.

  4. A cookie by Name myCookie is created.

  5. Since the setTime function will fail, the cookie will never expire.

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

The code calculates milliseconds for 30 days (1000 * 3600 * 24 * 30) and adds it to the current time, setting the cookie to expire in 30 days. The setCookie call creates a cookie named "myCookie".

Multiple choice technology enterprise content management
  1. String representation of current date, in US format.

  2. String representation of current date, in UK format.

  3. String representation of the current date, formatted according to the runtime's (browser/system) locale settings.

  4. Will return an empty string.

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

The toLocaleDateString() method returns a string representation of the date formatted according to the locale settings of the runtime environment (browser or operating system). This means the format varies based on the user's regional settings (e.g., MM/DD/YYYY for US, DD/MM/YYYY for UK, etc.), not a fixed US or UK format.

Multiple choice technology enterprise content management
  1. 11, 10, 12

  2. 10, 11, 12

  3. 11, 10, 0

  4. compile time error. Wrong Date signature

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

In JavaScript, months are 0-indexed (0 is January, 11 is December). Thus, new Date(2009, 11, 10) represents December 10, 2009. getMonth() returns 11, getDate() returns 10, and since no time is specified, getHours() defaults to 0.

Multiple choice technology architecture
  1. Declarative

  2. Structured

  3. Programmatic

  4. Both 1 and 3

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

Struts supports both declarative exception handling (configured in struts-config.xml using global-exceptions or exception mappings) and programmatic handling (try-catch blocks in Action classes). Declarative handling centralizes configuration while programmatic gives fine-grained control.

Multiple choice technology web technology
  1. ListResultSet

  2. ResultSet

  3. ScrollableResultSet

  4. ScrollableResult

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

To understand what session.createQuery("Query").scroll() returns, the user needs to have understanding of Hibernate, Java and SQL.

Explanation of each option:

A. ListResultSet: This option is incorrect because ListResultSet is not a valid class in Hibernate.

B. ResultSet: This option is incorrect because ResultSet is a class in Java that represents a table of data representing a database result set, and it is not returned by the scroll() method in Hibernate.

C. ScrollableResultSet: This option is incorrect because ScrollableResultSet is not a valid class in Hibernate.

D. ScrollableResult: This option is correct. The scroll() method in Hibernate returns a ScrollableResult object, which is used to traverse a result set. It provides methods to move the cursor forward and backward, as well as methods to retrieve the current row or a subset of rows.

Therefore, the answer is: D. ScrollableResult.

Multiple choice technology web technology
  1. lazy=false;

  2. lazy=true;

  3. lazy=yes;

  4. lazy=no;

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

Hibernate uses lazy loading by default with lazy=true. This means associations and collections are not loaded from the database until they are actually accessed in code, which improves performance by avoiding unnecessary queries.

Multiple choice technology programming languages
  1. It is possible for a program to free memory at a given time.

  2. Garbage Collection feature of Java ensures that the program never runs out of memory.

  3. It is possible for a program to make an object available for Garbage Collection.

  4. The finalize method of an object is invoked before garbage collection is performed on the object.

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

A: False - programs cannot directly free memory; GC handles it automatically. B: False - GC doesn't prevent OutOfMemoryError if memory is exhausted faster than GC runs. C: True - programs can make objects eligible for GC by removing references (setting to null, reassigning). D: True - finalize() is called before GC, though it's deprecated since Java 9.