Wednesday, 5 December 2012
Thursday, 22 November 2012
Introductio with Collection Framework
Introductio with Collection Framework:
Collection is an Interface ... which provide us a well defined set of interfaces and classes to handle and manipulate a group or collection of objects.List and Set are Interfaces and both of them extends the Collection Interface.
List : --List is an ordered collection of objects which has the indexing property and allows duplicates...
The methods includedin it are given in the table bellow....
void |
add( int index, Object element) Inserts the specified element at the specified position in this list (optional operation). |
boolean |
add( Object o) Appends the specified element to the end of this list (optional operation). |
boolean |
addAll ( Collection c) Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation). |
boolean |
addAll ( int index, Collection c) Inserts all of the elements in the specified collection into this list at the specified position (optional operation). |
void |
clear () Removes all of the elements from this list (optional operation). |
boolean |
contains( Object o) Returns true if this list contains the specified element. |
boolean |
containsAll ( Collection c) Returns true if this list contains all of the elements of the specified collection. |
boolean |
equals( Object o) Compares the specified object with this list for equality. |
Object |
get( int index) Returns the element at the specified position in this list. |
int |
hashCode () Returns the hash code value for this list. |
int |
indexOf ( Object o) Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element. |
boolean |
isEmpty () Returns true if this list contains no elements. |
Iterator |
iterator () Returns an iterator over the elements in this list in proper sequence. |
int |
lastIndexOf ( Object o) Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element. |
ListIterator |
listIterator () Returns a list iterator of the elements in this list (in proper sequence). |
ListIterator |
listIterator ( int index) Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list. |
Object |
remove( int index) Removes the element at the specified position in this list (optional operation). |
boolean |
remove( Object o) Removes the first occurrence in this list of the specified element (optional operation). |
boolean |
removeAll ( Collection c) Removes from this list all the elements that are contained in the specified collection (optional operation). |
boolean |
retainAll ( Collection c) Retains only the elements in this list that are contained in the specified collection (optional operation). |
Object |
set( int index, Object element) Replaces the element at the specified position in this list with the specified element (optional operation). |
int |
size () Returns the number of elements in this list. |
List |
subList ( int fromIndex, int toIndex) Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. |
Object[] |
toArray () Returns an array containing all of the elements in this list in proper sequence. |
Object[] |
toArray ( Object[] a) Returns an array containing all of the elements in this list in proper sequence; the runtime type of the returned array is that of the specified array. |
Class which impelements List...are ArrayList and LinkedList
Set :-- Set is a collection of unique objects which forbids duplicate objects..
the methods included in Set are given in the table below...
boolean |
add (Object o) Ensures that this collection contains the specified element (optional operation). |
boolean |
addAll ( Collection c) Adds all of the elements in the specified collection to this collection (optional operation). |
void |
clear( ) Removes all of the elements from this collection (optional operation). |
boolean |
contains( Object o) Returns true if this collection contains the specified element. |
boolean |
containsAll ( Collection c) Returns true if this collection contains all of the elements in the specified collection. |
boolean |
equals( Object o) Compares the specified object with this collection for equality. |
int |
hashCode ( ) Returns the hash code value for this collection. |
boolean |
isEmpty ( ) Returns true if this collection contains no elements. |
Iterator |
iterator ( ) Returns an iterator over the elements in this collection. |
boolean |
remove( Object o) Removes a single instance of the specified element from this collection, if it is present (optional operation). |
boolean |
removeAll ( Collection c) Removes all this collection's elements that are also contained in the specified collection (optional operation). |
boolean |
retainAll ( Collection c) Retains only the elements in this collection that are contained in the specified collection (optional operation). |
int |
size( ) Returns the number of elements in this collection. |
Object[] |
toArray ( ) Returns an array containing all of the elements in this collection. |
Object[] |
toArray ( Object[] a) Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. |
Class which impelements set...Hashset and TreeSet.
Vector :-- A Vector is an historical collection class that acts like a growable array, but can store heterogeneous data elements.It is synchronized and thread safe.
Map :-- Map is also an interface but not extends the Collection Interface.It is a key-value association of objects with unique key .
Class Which Implements Map ... Hashmap and TreeMap....
Introduction with comperator and comperable
Introduction with comperator and comperable:
Comperator and comperable are interfaces used for compairing objects .Implementation of Comparator and Comperable Interfaces
class Student implements Comparator<Student>{ private String name; private int age; Student(){ } Student(String stdName, int stdAge){ name = stdName; age = stdAge; } public String getName(){ return name; } public int getAge(){ return age; } // Overriding the compare method to sort the age public int compare(Student s1, Student s2){ return s1.age - s2.age; } }
public class Member implements comperable<Member>{
private String name; private int age; Member(){ } Student(String memName, int mebAge){ name = mebName; age = mebAge; }
// Overriding the compareTo method public int compareTo(Member mem){ return (this.name).compareTo(mem.name); }
}
public class MainClass{ public static void main(String args[]){ List<Student> list = new ArrayList<Student>(); list.add(new Student("Roma",20)); list.add(new Student("Rama",12)); list.add(new Student("Froger",10)); list.add(new Student("Raghav",14)); list.add(new Student("Nammy",11)); Collections.sort(list);// Sorts the array list for(Student a: list)//printing the sorted list of names System.out.print(a.getName() + ", "); // Sorts the array list using comparator Collections.sort(list, new Student()); System.out.println(" "); for(Student a: list)//printing the sorted list of ages System.out.print(a.getName() +" : "+ a.getAge() + ", "); } }
Thursday, 8 November 2012
Vector Vs ArrayList which is preferable
Vector Vs ArrayList
We can compare this two based on some parameters....like Synchronization, DataSize
1)Vector is synchronized while Arraylist is not synchronized.Synchronization always pay for efficiency,so it is better to use ArrayList if we don't need thread safe data acces,Other wise go for Vector.
2)The size always matters,--Both vector and ArrayList are resizable(dynamic for their size),
but when size increase..Vector increase it's size by double and on the other hand ArrayList increases it's size by half of its previous size.So it is better to use ArrayList wrt size.
3)Arraylist are faster and speedup the execution while vector are less efficient than ArrayList.
4)Vector is threadsafe while ArrayList is not threadsafe.
We can compare this two based on some parameters....like Synchronization, DataSize
1)Vector is synchronized while Arraylist is not synchronized.Synchronization always pay for efficiency,so it is better to use ArrayList if we don't need thread safe data acces,Other wise go for Vector.
2)The size always matters,--Both vector and ArrayList are resizable(dynamic for their size),
but when size increase..Vector increase it's size by double and on the other hand ArrayList increases it's size by half of its previous size.So it is better to use ArrayList wrt size.
3)Arraylist are faster and speedup the execution while vector are less efficient than ArrayList.
4)Vector is threadsafe while ArrayList is not threadsafe.
Wednesday, 7 November 2012
JSF Core Tags
Tag | Description | |
---|---|---|
view | Creates the top-level view | |
subview | Creates a subview of a view | |
facet | Adds a facet to a component | |
attribute | Adds an attribute (key/value) to a component | |
param | Adds a parameter to a component | |
actionListener | Adds an action listener to a component | |
valueChangeListener | Adds a valuechange listener to a component/> | |
convertDateTime | Adds a datetime converter to a component |
Adds a number converter to a component
validator
Adds a validator to a component
validateDoubleRange
Validates a double range for a component’s value
validateLength
Validates the length of a component’s value
validateLongRange
Validates a long range for a component’s value
loadBundle
Loads a resource bundle, stores properties as a Map
selectitems
Specifies items for a select one or select many
selectitem
Specifies an item for a select one or select many component
verbatim
Adds markup to a JSF page
Subscribe to:
Posts (Atom)