Thursday 5 April 2012

Class - StringToKenizer


StringToKenizer

The processing of text consist of parsing a formatted. input string, which is the division of text into a set of discrete parts,or tokens.

String Tokenizer, specify an input string  and a string that contains delimeters. Delimeters are characters that separate tokens. StringTokenizer implements the enumeration interface.

Constructors:

  StringTokenizer(String str)
  StringTokenizer(String str,string delimeters)
StringTokenizer(String str,string delimeters,boolean delimAsToken)

In all constructor, str is the string that will be tokenized.

In first version, the default delimeters are used.

In second & third version delimeters is a string that specifies the delimeters.

In third version delimAsToken is true, then the delimeters are also returned as tokens when the string is pursed. Otherwise, the delimeters are not returned as token by the first two forms.

Methods:

int countTokens()
Using the current set of delimeters the method delemeters, the method determines the number of tokens left to be parsed and returns the result.

boolean hasMoreElements()
Returns true if one or more tokens remain in the string and returns false if there are none.

boolean hasMoreTokens()
Returns true if one or more tokens remain in the string and returns false if there are none.

object nextElement()
            Returns the next token as an object.

string nextToken()
            Returns the next token as a string.

string nextToken(string delimeters)
Returns the next token as a string and sets the delimeters string to that specified by delimeters.


import java.util.*;
class StringTokenDemo 
{
    public static void main(String args[]) 
    {
  
String str = "Name = Ruchita;" +
"Age=24;" +
"Educational Qualification = Msc(IT);" +
"Hobby = Reading,Dancing,Writing";

StringTokenizer st = new StringTokenizer(str, "=;");

while(st.hasMoreTokens()) 
{
String key = st.nextToken();
String val = st.nextToken();
System.out.println(key+ "----->" + val);
}
    }
}








Posted By  : Ruchita Pandya

Class - Random Class


Random

The Random class is a generator of pseudorandom numbers.

Constructors
     Random ()
     Random (long seed)

The first version creates a number generated that uses the current time as the string, or seed, value.

The second version allows to specify a seed value manually.

Methods:

boolean nextBoolean()
            Returns the next boolean random numbers.

void nextBytes(byte vals[])
            Fills vals with randomly generated values.

double nextDouble()
            Returns the next double random number.

float nextFloat()
            Returns the next float random number.

double nextGaussian()
            Returns the next Gaussian random.

int nextInt()
            Returns the next int random number.

int nextInt(int n)
            Returns the next int random number within the range zero to n.

long nextLong()
            Returns the next long random number.

void SetsSeed(long newSeed)
            Sets the seed value to that specified by newSeed.

Posted By : Ruchita Pandya

Class - Hashtable


Hashtable


Hashtable was part of the original java.util and is a concrete implementation of a Dictionary.

Hash table stores key/value pairs in a has table. In Hash table object is used as a key, and the value is that which want linked to that key. The key is then hashed, and the resulting hash code is used as the index at which the value is stored within the table.

A Hash table can only store objects that override the hashcode(). This method must compute and return the hash code for the object. The equals() method is also override which compares two objects. These method defined by object.

Constructors:

  Hashtable()
  Hashtable(int size)
  Hashtable(int size,float fillRatio)
  Hashtable(Map m)

The first version is default constructor.

The second version creates a hash table that has an initial size specified by size.

The third version creates a hash table that has an initial size specified by size and a fill ratio specified by fillRatio.

The fourth version creates a hash table that is initialized with the
elements is m.

Method:

void clear()
  Resets and empties the hash table

boolean contains(Object value)
Returns true if some value equal to value exists within the hash table. Returns false if the value isn’t found.

boolean containsKey(Object key)
Returns true if some key equal to key exists within the hash table. Returns false if the key isn’t found.

boolean containsValue(Object value)
Returns true if some value equal to value exists within the hash table. Returns false if the value isn’t found.

Enumeration elements( )
Returns an enumeration of the values contained in the hash table.

Object get(Object key)
Returns the object that contains the value associated with key. If key is not in the hash table, a null object is returned.

boolean isEmpty( )
Returns true if the hash table is empty;returns false if it contains at least one key.

Enumeration keys( )
Returns an enumeration of the keys contained in the hash table.

object get(object key)
Returns the object that contains the value associated with key. If key is not in the hash table, a null object is returned.

object Put(object key,object value)
Inserts a key and a value into the hash table. Returns null if key isn't allready in the hash table; returns the previous value associated with key. If key is allready in the hash table.


void rehash()
Increases the size of the hash table and rehashes all of its keys.

Object remove(object key)
            Removes key and its value. returns the value associated with key. If key is not in the hash table, a null object is returned.

Posted By : Ruchita Pandya

Class - Stack


Stack

Stack is a subclass of vector that implements  a standard last_in,first_out stack.
Stack only defines the default constructor, which creates an empty stack.

 

Method:


boolean empty()
Returns true if the stack is empty, and returns false if the stack contains elements.

Object peek()
Returns the element on the top of the stack, but does not remove it .

Object pop()
Returns the element on the top of the Stack removing it in the process.

Object push(Object element)
Pushes element on to the stack element is also returned

int search(object element)
Searches for element in the stack. If found its offset from the top of the stack is returned. Otherwise,-1 is returned.


Posted By : Ruchita Pnadya

Class - Vector


Vector

  Vector implements a dynamic array vector is synchronized, and it contains many legacy methods that are not part of the collection framework.
 constructors

     Vector()
     Vector(int size)
     Vector(int size,int incr)
     Vector(collection c)
 
The first form is the default vector constructors. It initial size of 10.

The second form creates a vector whose initial capacity is specified by size.

The third form creates a vector whose initial capacity is specified by size and increment is specified by incr.

The fourth form creates a vector that contains the elements of collection c.

Vector defines these protected data members:
           
            int capacityIncrement;
            int elementCount;
            Object elementData[];
 
The increment value is stored in capacity Increment. The number of elements currently in the vector is stored in elementCount. The array that holds the vector is stored in elementData.

Method

final void addElement(object element)
The object specified by element is added to the vector.

final Enumeration elements()
Returns an enumeration of the elements in the vector.
 
final object firstElement()
            Returns the first element in the vector.
 
final object lastElement()
            Returns the last element in the vector.
 
final void removeElementAt(int index)
Removes the element at the location specified by index.
 
final void setSize(int size)
Sets the number of elements in the vector to size. If the new size is less than the old size, elements are lost. If the new size is larger than the old size, null elements are added.

final int Size()
            Returns the number of elements currently in the vector.

Posted By : Ruchita Pandya

Interface - Enumeration


Enumeration


The enumeration interface defines the methods by which you can enumerate.The element in a collection of objects.Enumeration is considered absolute for new code.

Enumeration specifies the following two Methods:-
           
boolean has MoreElements()
The has more Elements() return true while there are still more elements to extract and false when all the  elements have been enumerated.

Object nextElement()
nextelement() returns the next object in the enumeration as a generic object reference.

Posted By  : Ruchita Pandya

Class - Calendar And Gregorian Calendar


Calendar

The abstract calendar class provides a set of methods that allows to convert a time in milliseconds to number of useful components. The type of information that can be provide are: Year,Month,Day,Hour,Minute and second.
 
Calendar provides no public constructors. Instead, getInstance() method is used to obtain a calendar initialized to the current date and time.

Calendar defines several protected instance variables are Fieldset is a boolean that indicates if the time components have been set. Fields is an array of that holds the components of the time isSet is a boolean array that indicates if a specific time component has been set. Time is a long that holds the current time for this object isTimeSet is a boolean that indicates if the current time has been set.

Calendar defines the following int constants, which are used when you get or set

Components of the calendar:

AM
NOVEMBER
PM
DECEMBER
AM_PM                 
DATE
SUNDAY
DAY_OF_MONTH
MONDAY
DAY_OF_WEEK
TUESDAY
DAY_OF_WEEK_IN_MONTH
WEDNESDAY
DAY_OF_YEAR
THURSDAY
MONTH
FRIDAY
WEEK_OF_MONTH
SATURDAY
WEEK_OF_YEAR
JANUARY
HOUR
FEBRUARY
MINUTE
MARCH
SECOND
APRIL
MILLISECOND
MAY
HOUR_OF_DAY
JUNE
YEAR
JULY
ZONE_OFFSET
AUGUST
FIELD_COUNT
SEPTMBER
DST_OFFSET        
OCTOBER
ERA
                                                                                                                                                                                                                                                                                                                                                                

Methods:

Static calendar getInstance()
Returns a calendar object for the default locale and time Zone.

abstract void add(int which,int val)
Adds val to the time or date components specified by which to subtract, add a negative value which must be one of the fields defined by calendar such as calendar. HOUR

boolean after(object calendar obj)
Returns true if the invoking calendar object contains a date that is later than the once specified by calendar obj. otherwise , it returns false.

boolean before(object calendar obj)
Returns true if the invoking calendar object contains a date that is before than the once specified by calendar obj. otherwise , it returns false.

final void clear()
            Zeros all time components in the invoking object.

boolean equals(object calenderObj)
Returns true if the invoking calendar object contains a date that is equal to the one specified by calendarObj. Otherwise it returns false.

final int get(int calendar Field)
Returns the value of one component of the invoking object. The component is indicated by calendarField. Examples of the components that can be requested are calendar. Year,calendar. Month,calendar. Minute and so fourth.

TimeZone getTimeZone()
            Returns the timeZone for the invoking object.

Final void set (int year, int month, int dayOfMonth, int hours, int minutes, int seconds)
Sets various date and time components of the invoking object.

void setTimeZone(TimeZone tz)
Sets the time zone for the invoking object to that specified by tz.

Gregorian Calendar

  Gregorian calendar is a concrete implementation of a calendar. The getInstance() method of calendar returns a GregorianCalendar. initialized with the current date and time in the default locale and time zone.
  Gregorian calendar defines two fields: AD and BC. These represent the two defined by the Gregorian calendar.
  There are also several constructors for GregorianCalendar objects.
GregorianCalendar()
The default, initializes the object with the current date and time in the default locale and time zone. Three constructors offer increasing levels of specificity.

GregorianCalendar(int Year, int month,int dayofMonth)
GregorianCalendar(int year,int month,int dayofMonth)     
GregorianCalendar(int year,int month,int dayofMonth,int hours,int minutes,int seconds)

All three versions set the day,month and year.
Here, year specifies the number of years that have elapsed since 1900.the month is specified  by month with zero indicating january.The day of month is specified by day of month.
The first version sets the time to midnight.The second version also sets the hours and the minutes.
The third version adds second.
  The following constructors create objects initialized with the current date and time using specified time zone and/or locale.
  GregorianCalendar (Locale locale)
  GregorianCalendar (Timezone timezone)
  GregorianCalendar (Timezone timezone,Locale locale)
GregorianCalendar provides an implementation of all the abstract methods in calendar.

Method 

Boolean isLeapyear(int year)
This method returns true if year is a leapyear and otherwise returns false.


Posted By : Ruchita APnday