Which of the following statements is preferred to create a string "Welcome to Java"?

a. String s = "Welcome to Java";
b. String s = new String("Welcome to Java");
c. String s; s = "Welcome to Java";
d. String s; s = new String("Welcome to Java");

a. String s = "Welcome to Java";
(a) is better than (b) because the string created in (a) is interned. Since strings are immutable and are ubiquitous in programming, to improve efficiency and save memory, the JVM uses a unique instance for string literals with the same character sequence. Such an instance is called interned. The JVM (a) is simpler than (c).

Computer Science & Information Technology

You might also like to view...

Select the code below that uses CSS to configure a class called “offer” with blue text that uses the Arial or sans-serif font typeface.

a. ``` #offer { color:blue; font-family:Arial,sans-serif;} ``` b. ``` .offer { color:blue; font-family:Arial,sans-serif;} ``` c. ``` .offer { text:blue; font-family:Arial,sans-serif;} ``` d. ``` #offer { color:blue; font-family:Arial,sans-serif;} ```

Computer Science & Information Technology

Which of the following is a process of borrowing identity information, such as an IP address, domain name, NetBIOS name, or TCP or UDP port numbers to hide or deflect interest in attack activities?

A. Ingress filtering B. Data authentication C. Network sniffing D. Spoofing

Computer Science & Information Technology