Featured Post

Generics and Collections in Java 1.5

Generics And Collections In java 1.5
*************************************************************************************************

Comapred to Java 1.4 , Java 1.5 has come up with few more collection classes and interfaces

Before that We will discuss about Object class methods .

String toString() - To read Object properties , Need to override
int hashCode() - Useful for searching
boolean equals(Object obj) - to compare two objects semantically equal or not

wait() - running Thread will move to wait state
notify() - notify the waiting Thread in Threadpool
notifyAll - notifyAll thread on that Object which are waiting


finalize() - before garbage collection need to do somethings you can do that here


Difference between == and equlas()
**********************************

== compares whether two objects reference same Object . Means address should be same

equals() - will give true or false based on the semantic declaration



Relation between hash Code and equals()
**************************************

if objects are equal hash code must be equal
if objects are not equals no use of hash code
if hash code is equal does not mean objects are equal. means equals() method is not necessary to return true value
if objects are not equal return different hash Code
if hash code is not equal then equals() method should return false


Note : Dont involve transient in hash code generation , Since transient member will not be serializable . if serialize it and retrieve back that may return zero instead of real value



1.5 Java Collection Classes
***************************

Map descendants
***************

Maps
|
|_ HashMap
|
|_ Hashtable
|
|- TreeMap
|
|- LinkedHashMap
|

Set descendants
***************
Set
|
|- HashSet
|
|- LinkedHashSet
|
|- TreeSet






List classes
************
List
|
|-ArrayList
|-Vector
|-LinkedList

queues
*******
|-PriorityQueue

Utilities in Java collections
*****************************

|
|-Arrays
|-Collections


Extra Classes/Interfaces Added in 1.5 are mentioned below .
************************************************
NavigableMap
NavigableSet


List - List of things

Set - Unique Things (No duplicates)

Map - Unique Id's

Hashtable - No null key , no null value
HashMap - One Null key many Null Values

No collection will be Sorted , Unordered since sort is type of ordering

ordered sorted
********* *******
Hashtable - unordered unsorted
HashMap - unordered Unsorted
Treemap - Sorted NaturalOrder
LinkedHashMap - By Insertion Order No

HashSet - unordered , unsorted
Treeset - sorted , Natural Order /Custom Comparision rules
LinkedHashSet - insertion order No


ArrayList - By Index No
Vector - By Index No
LinkedList - By Index No


PriorityQueue - Sorted By to do order

Important Points
*********************

1) For Comparing Objects and sorting the Objects We use Comparable ,Comparator
2)Comparable - compareTo() method to that stuff , present object need to be modified
3)Comparator - equals(object,object) to do that stuff, we can use seperated class by implementing this interface

Important navigable methods
****************************
ceiling()- returns lowest element greater than equal
ceilingKey() - return lowestKey greater than equal
higher() _return lowest element greater than specified
higherKey() return lowest key greater than specified
floor() - returns lowest element less than equal
floorKey()- returns lowest key less than equal
lower() - return lowest element less than specified
lowerKey() - return lowest key lessathan specified
pollFirstEnrty() - returns and removes first key value pair
pollFirst() - return and removes first entry
poolLast() - returns and removes last entry
poolLastEntry() - returns and removes last key-value pair
descendinSet() - returns navigable set in reverse order
descendingMap()- returns navigable map in reverse order



Baked Collection classes
************************
headSet(e) - exclusive of e set will be returned
headMap(k,e) - exclusive of k returns Map
tailSet(e) - inclusive of e returns subSet
tailMap(k,e) - inclusive of K returns subMap
subSet(s,b,e,b) - returns set starting element s and just before b
submap(s,b,e,b) - returns map starting at key s and ending just before s



P.S: Next Topic will be Generics ..

























































Enter you DOB ,Time and Place

SEO Schemes

Comments

Popular posts from this blog

[Inside AdSense] Understanding your eCPM (effective cost per thousand impress...