Compiler versus Interpreter, and the JVM
Using the Java compiler, determine the output of the following program:
class Str{ public static void main(String[] args) { String p = "XYZ"; String q = "XYZ"; System.out.println(p == q); System.out.println(p.equals(q)); q = new String("XYZ"); System.out.println(p == q); q = "XYZ"; System.out.println(p == q); }}The following segment is identical to the Str class (above), but without the class wrapper Str . If you have access to an interactive Java interpreter such as Dr. Java (http://drjava.org/), enter:
String p = "XYZ"; String q = "XYZ"; System.out.println(p == q); System.out.println(p.equals(q)); q = new String("XYZ"); System.out.println(p == q); q = "XYZ"; System.out.println(p == q);directly to the interactive interpreter and check the output.
The interpreter probably did not give you the same results as the compiler. An interpreter translates and executes each statement before it sees the next one, and a compiler translates every statement before it executes any. How does this difference affect the output of these two segments?
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.