public class StringComparison { public static class Point { public int x, y; } public static void main(String[] args) { /* Difference between value and reference */ int a1 = 1; int a2 = a1; a1 = 2; System.out.println(a1 + " " + a2); Point p1 = new Point(); p1.x = 1; Point p2 = p1; p1.x = 2; System.out.println(p1.x + " " + p2.x); /* String comparison and interned strings */ String s1 = "ab"; String s2 = "ab"; String s3 = "abc".substring(0, 2); System.out.println(s1); System.out.println(s2); System.out.println(s3); System.out.println(s1 == s2); System.out.println(s2 == s3); System.out.println(s2.equals(s3)); /* Additional string comparisons */ System.out.println(s1.startsWith(s2)); System.out.println(s2.contains(s3)); } }