Java Seminar
Java Seminar
2. Enumeration
- Enumeration and uses
- Methods in enum
3. Iteration
- Java iteration and uses
4. String tokenizer
- String tokenizer and its methods
5. Gregorian calendar
- Methods of Gregorian calendar
2. Vector
Syntax:
public class Vector<E> extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable,
Serializable
3. Stack
Syntax:
public class Stack<E> extends Vector<E>
4. LinkedList
LinkedList class is an implementation of the
LinkedList data structure. It can store the elements
that are not stored in contiguous locations and every
element is a separate object with a different data
part and different address part.
Syntax:
LinkedList name = new LinkedList();
5. HashSet
HashSet is implemented using the Hashtable data
structure. It offers constant time performance for the
performing operations like add, remove, contains,
and size.
Syntax:
public class HashSet<E> extends
AbstractSet<E> implements Set<E>,
Cloneable, Serializable
6.PriorityQueue
The PriorityQueue is based on the priority heap.
The elements of the priority queue are ordered
according to the natural ordering, or by a
Comparator provided at queue construction
time, depending on which constructor is used.
Syntax:
public class PriorityQueue<E> extends
AbstractQueue<E> implements Serializable
7.ArrayDeque
ENUMERATION:
A Java enumeration is a class type. Although we
don’t need to instantiate an enum using new, it has
the same capabilities as other classes.
Source code:-
enum Color {
RED,
GREEN,
BLUE;
}
Source code:-
JAVA ITERATOR:
An Iterator is an object that can be used to loop
through collections, like ArrayList and HashSet.
It is called an "iterator" because "iterating" is the
technical term for looping.
import java.util.ArrayList;
import java.util.Iterator;
// Make a collection
ArrayList<String> cars = new ArrayList<String>();
cars.add("Volvo");
cars.add("BMW");
cars.add("Ford");
cars.add("Mazda");
while(it.hasNext()) {
// Print the first item
System.out.println(it.next());
}
}
STRINGTOKENIZER:-
String tokenizer class in Java is used to break a string into
tokens. A StringTokenizer object internally maintains a current
position within the string to be tokenized.
The String Tokenizer class allows an application to break strings
into tokens. It implements the Enumeration interface. This class is
used for parsing data.
To use String Tokenizer class we have to specify an input string
and a string that contains delimiters. Delimiters are the characters
that separate tokens.
Each character in the delimiter string is considered a valid
delimiter. Default delimiters are whitespaces, new
line, space, and tab.
import java.util.*;
public class StrTkn
{
public static void main(String args[])
{
System.out.println("Using Constructor 1 - ");
StringTokenizer st1 = new StringTokenizer("How are
you", " ");
while (st1.hasMoreTokens())
System.out.println(st1.nextToken());
System.out.println("Using Constructor 2 - ");
StringTokenizer st2 = new StringTokenizer("JAVA :
Code : String", " :");
while (st2.hasMoreTokens())
System.out.println(st2.nextToken());
System.out.println("Using Constructor 3 - ");
StringTokenizer st3 = new StringTokenizer("JAVA :
Code : String", " :", true);
while (st3.hasMoreTokens())
System.out.println(st3.nextToken());
}
}
GREGORIAN CALENDAR :
Syntax
public String getSymbol()
Returns
The getSymbol() method is used to get the symbol
of invoking currency for the default locale.
Source code:-
import java.util.Currency;
public class CurrencyGetSymbolExample1 {
public static void main(String args[]) {
// Create a currency for USD
Currency cur = Currency.getInstance("USD");
// Get and print the symbol of the currency
String symbol = cur.getSymbol();
System.out.println("Currency symbol is: " +
symbol);
}
}
Source code:-
getAvailableIDs()
import java.util.*;
public class TimeZoneExample1 {
public static void main( String args[] ){
String[] id = TimeZone.getAvailableIDs();
System.out.println("In TimeZone class available
Ids are: ");
for (int i=0; i<id.length; i++){
System.out.println(id[i]);
}
}
}
Java TimeZone class Example:
Source code:-
getDisplayName()
FileName: TimeZoneExample4.java
import java.util.*;
public class TimeZoneExample4 {
public static void main( String args[] ){
TimeZone zone = TimeZone.getDefault();
String name = zone.getDisplayName();
System.out.println("Display name for default time
zone: "+ name);
}
}