Friday 19 May 2017

Java Features_3

The Object class is at the top of the hierarchy. Due to this default inheritance of object class, we can pass an object of any class as an argument to any method.
the methods of object class
  • equals(Object ref) - returns if both objects are equal
  • finalize( ) - method called when an object’s memory is destroyed
  • getClass( ) - returns class to which the object belongs
  • hashCode( ) - returns the hashcode of the class
  • notify( ) - method to give message to a synchronized methods
  • notifyAll( ) - method to give message to all synchronized methods.
  •  
  • toString() - return the string equivalent of the object name
  •    - produce something like "ClassName@123456" (where the number is the hashcode representation of the object). To make meaning full, we can override this functions.
  • wait() - suspends a thread for a while
  • wait(...) - suspends a thread for specified time in seconds

java.util package provides

  • Date & calendar operations
  • String manipulations
  • Collections Operations....etc


Convertions...
  1) String to Object. ....toString()     
String arg1 = new Integer(1 + 2).toString();

 2) Object to String....valueOf(String Variable) method
int i = Integer.valueOf("22").intValue(); 
long l = Long.valueOf("22").longValue(); 

 Regular expression
Regular expressions or Java Regex is an API to search or manipulate string based on a certain pattern. 
 java.util.regex package primarily consists of three classes: Pattern, Matcher, and PatternSyntaxException.


 big advantage of Generics?
Big advantage: collections are now type safe. For example, you can create a Stack that holds only Strings as follows:
Stack names = new Stack();

No comments:

Post a Comment