Java Programming and Technical Programming

Column size is mandatory to create an array in java. State true or false

Read Solution (Total 0)

Java Other Question

class MyLogger
{
private StringBuilder logger = new StringBuilder();
public void log(String message, String user)
{
logger.append(message);
logger.append(user);
}
}

The programmer must guarantee that a single MyLogger object works properly for a multi threaded system. How must this code be changed to be thread-safe?

A. Replace StringBuilder with StringBuffer

B. Replace StringBuilder with just a String object and use the string concatenation (+=) within the log method.

C. No change is necessary, the current MyLogger code is already thread-safe.

D. Synchronize the log method
What is special about string objects as compared to objects of other derived types?(More than 1 may be correct)

A. Java provides string constant pool to store the string objects
B. You can concatenate two string objects using ‘+’
C. You can create string objects without or without using new operator