SCJP Study Notes


Fundamental Classes in the java.lang Package

  • String class is final, immutable and overrides equals() method.
  • Wrapper classes are final, immutable and overrides equals() method.
  • StringBuffer does NOT override the equals() method.
  • The | , & , || , && operators can not be used with wrapper types.
  • The class Math is final and the constructor is private so an instance of this class can not be constructed.
  • String[] s="hello".split("") => {"h","e","l","l","o"}
  • The output for the random() method is a random number greater than or equal to 0.0 and less than 1.0
  • Instances of wrapper classes can not be manipulated as if they were primivites.
  • The comparison between String object and StringBuffer object is always false, even when they are wrapping the same contents.
  • Methods of Math class:
    • int abs (int i)
    • long abs (long l)
    • float abs (float f)
    • double abs (double d)
    • double ceil (double d)
    • double floor (double d)
    • double srqt (double d)
    • double signum (double d)
    • double pow (double d, double e)
    • int round (float f)
    • long round (double d)
    • double random()
    • double sin (double d)
    • double cos (double d)
    • double tan (double d)
    • double exp (double d)
    • double log (double d)
  • Methods of Boolean wrapper class:
    • boolean booleanValue()
    • static boolean parseBoolean (String s)
    • static Boolean valueOf (boolean b)
    • static Boolean valueOf (String s)
  • All wrapper classes, except Character, have a constructor which takes String as a parameter.
  • Methods of Byte, Short, Integer, Long, Float, Double classes:
    • byte byteValue()
    • short shortValue()
    • int intValue()
    • long longValue()
    • float floatValue()
    • double doubleValue()
    • static xxx parseXxx (String s) // xxx can be byte, short, int, long, float, double
    • static xxx parseXxx (String s, int radix)
    • static Xxx valueOf (String s) // return type is wrapper instance.
    • static Xxx valueOf (String s,int radix) // return type is wrapper instance.
    • static Xxx valueOf (byte b) // return type is wrapper instance.
  • Additional methods in Long and Integer classes:
    • static String toBinaryString (int i)
    • static String toBinaryString (long l)
    • static String toHexString (int i)
    • static String toHexString (long l)
    • static String toOctalString (int i)
    • li> static String toOctalString (long l)
  • Methods in String class: charAt, concat, endsWith, indexOf, lastIndexOf, length, replace, startsWith, subString, trim, toCharArray, toUpperCase, valueOf, toLowerCase, getChars
  • The Byte class has only two constructors: one accepts a primitive byte; the other accepts a String.
  • The Float constructor is overloaded: one version accepts a primitive of type float; one accepts a primitive of type double; one accepts a String representation of a floating-point literal.
    All numeric values can be promoted to type double; so all numeric values are accepted by the float constructor.
  • System.out.print(Math.round(Float.NaN)); // prints: 0

contents | previous | next