Java Programming and Technical Programming

What is the output of the following program?

import java.util.regex.*;

class Test
{
public static void main(String args[])
{
Pattern p = Pattern.compile(".ech");
Matcher m = p.matcher("tech");
boolean b = m.matches();
System.out.println(b);
}
}

A. true
B. false
C. Compilation Error
D. Runtime Error

Read Solution (Total 1)

Java Other Question

StringBuilder is less efficient and slower than StringBuffer. State true or false. 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