Core Classes

Related slides on offer

Figure 399. Superclass Object Slide presentation Create comment in forum
  • Superclass of all Java classes.

  • Common methods to be redefined by derived classes.


Figure 400. String literals Slide presentation Create comment in forum

Figure 401. OpenJDK String implementation Slide presentation Create comment in forum

Implementation of java.lang.String:

public final class String ... {
  private final char value[];
  private int hash;
  private static final long serialVersionUID = -6849794470754667710L;
...
}

Figure 402. String copy constructor Slide presentation Create comment in forum
String s = new String("Eve");

Uses constructor public String(String original).


Figure 403. Copy constructor and heap Slide presentation Create comment in forum

Figure 404. Operator == and equals() Slide presentation Create comment in forum
Primitive type Object
int a = 12, b = 12;  // equal values

System.out.println("==: " + (a == b));
// No equals(...) method equivalent 
// for primitive types
String s1 = new String("Kate"),
       s2 = new String("Kate");

System.out.println("    ==: " + (s1 == s2));
System.out.println("equals: " + s1.equals(s2));
==: true
    ==: false
equals: true

Figure 405. Remarks == vs. equals() Slide presentation Create comment in forum
  • The == operator acting on primitive types compares expression values.

  • The == operator acting on objects compares for equality of reference values and thus for object identity.

  • The == operator acting on objects does not check whether two objects carry semantically equal values.

  • The equals() method compares two object's values.