Translate the content to your language. Select your Language below.

Friday, May 30, 2014

Collections Framework in Java


Collection is like a container which can holds group of elements.

Iterator:- is an interface which will loop a collection list and executes each object inside the list. It allows us to access collection in only forward direction.

ListIterator:- is also an Interface just like Iterator. The only diff is, it allows us to access collection either forward or backward direction

Enumeration:- This is also similar to Iterator but for read-only purpose. It doesnt have Remove() method.


List Interface:-Provides support for Ordered collections of objects.
| This may contain Duplicate elements.
|
|-- ArrayList:- Resizable Array implementation of List Interface.
| It can grow dynamically and it provides powerful insertion and search mechanisms than Arrays.
| This is not synchronized by Default.
| It can use only Iterator to access the elements.
| ArrayList increases its array size by 50% or 1.5 times when it runs out of room.
| It doesn't have any default size.
| During the Deletion, all elements in the Array have to be moved one step back to fill the space  created by deletion.
|
|-- Vector:-Synchronized resizable array implementation of List Interface.
| It is synchronized by Default.
| It can use either Iterator or Enumeration to access its elements.
| Vector increases its size 100% or 2 times when it runs out of room.
| It has a default size of 10.
|
|-- LinkedList:-Doubly linked list of the interface. May provide better performance than Arraylist if elements are frrequently inserted or deleted.
Data is stored in nodes that have reference to the previous node and the enxt node. So adding element is simple as creating the node and updating the next pointer on the previous node and previous pointer on the New node.
Deletion in LinkedList is fast because it invloves only updating the next pointer on the node before of the deleted node and previous pointer on the node after the deleted node.



Set Interface:- provides methods for accessing elements of a Set.
| Do not allow duplicate elements.
| Contains no methods otherthan the Inherited methods from Collection.
| It adds restriction that duplicate elements are prohibited.
| 2 SET objects are equal if they contain same elements.
|
|-- HashSet:- A HashSet is Unsorted and Unordered set.
| It uses hashcode of the object being inserted (So the more efficient your hasCode() implementation the better access performace you get).
| Use this class when user dont want Duplicates and not caring about order when it is iterated.
| It doesn't guarantee for either sorted order or sequence order.
| We can add any type of elements to HashSet.
|
|-- TreeSet:- Provides elements in the Sorted order [ascending].
| Elements are sorted according to the natural order of elements or by the comparataor provided at the time of creation.
| We can add only similar types of elements.
|
|-- L.HashSet:-
|
|-- EnumSet:- Specified set for use of eNum types.
All of the elements in this type that is specified explicitly or implicitly at the time created.



Map Interface:- A Map is an Object which stores associations between Keys and Values.
| Both Keys and Values are objects.
| Keys must be unique and values can be duplicated.
| Some Maps can accept Null keys and Null Values, other maps not allow.
|
|-- HashMap:- For inserting, deleting and locating elements in a Map, this is the best alternative.
| Depending upon the size of your collection, it may be faster to add elements in the HashMap and later convert it to TreeMap for better Sorted Order key travesal.
| Allows us to have all NULL values and one NULL key.
| Iterator in the HashMap is fail-safe [if you cahnge the map, while iterating we can see].
| It is UnSynchronized.
|
|-- HashTable:- Doesn't allow NULL values as KEY or Value.
| Enumerator for the HashTable is NOT a fail-safe.
| It is Synchronized.
|
|-- TreeMap:- Implements SortedMap interface which extends internally Map interface.
| Data will be sorted in the ascending order of the keys according to natural order of key's class or by the comparator provided at runtime.
| When we need to traverse the keys in a sorted order then TreeMap is the better choice.
| Depending on the size of your collection, it may be faster to add elements in the HashMap and later convert it to TreeMap for better Sorted Order key traversal.
| TreeMap is based on the Red-Black tree data structure.
|
|-- EnumMap:-  

Maps provide 3 different collection views.

1.) Key Set View :- is a Set returned by keySet() method of Map Interface. It contains all the keys in the map.

2.) Values Collection View:- is a collection returned by values() method of Map Interface. It contains all objects as Values in Map.

3.) Entry Set View:- is a set returned by entryset() method of Map Interface and contains Objects of type map. Entry each of which has both Keys and Values.


Wednesday, May 14, 2014

Java Features By Version Wise

Java SE 8

Java 8 was released on 18 March 2014. The code name culture is dropped with Java 8 and so no official code name going forward from Java 8...

New features in Java SE 8

  • Lambda Expressions
  • Pipelines and Streams
  • Date and Time API
  • Default Methods
  • Type Annotations
  • Nashhorn JavaScript Engine
  • Concurrent Accumulators
  • Parallel operations
  • PermGen Error Removed
  • TLS SNI

Java Version SE 7

Code named Dolphin and released on July 28, 2011.

New features in Java SE 7

  • Strings in switch Statement
  • Type Inference for Generic Instance Creation
  • Multiple Exception Handling
  • Support for Dynamic Languages
  • Try with Resources
  • Java nio Package
  • Binary Literals, underscore in literals
  • Diamond Syntax
  • Automatic null Handling

Java Version SE 6

Code named Mustang and released on December 11, 2006.

New features in Java SE 6

  • Scripting Language Support
  • JDBC 4.0 API
  • Java Compiler API
  • Pluggable Annotations
  • Native PKI, Java GSS, Kerberos and LDAP support.
  • Integrated Web Services.
  • Lot more enhancements.

J2SE Version 5.0

Code named Tiger and released on September 30, 2004.

New features in J2SE 5.0

  • Generics
  • Enhanced for Loop
  • Autoboxing/Unboxing
  • Typesafe Enums
  • Varargs
  • Static Import
  • Metadata (Annotations)
  • Instrumentation

J2SE Version 1.4

Code named Merlin and released on February 6, 2002 (first release under JCP).

New features in J2SE 1.4

  • XML Processing
  • Java Print Service
  • Logging API
  • Java Web Start
  • JDBC 3.0 API
  • Assertions
  • Preferences API
  • Chained Exception
  • IPv6 Support
  • Regular Expressions
  • Image I/O API

J2SE Version 1.3

Code named Kestrel and released on May 8, 2000.

New features in J2SE 1.3

  • Java Sound
  • Jar Indexing
  • A huge list of enhancements in almost all the java area.

J2SE Version 1.2

Code named Playground and released on December 8, 1998.

New features in J2SE 1.2

  • Collections framework.
  • Java String memory map for constants.
  • Just In Time (JIT) compiler.
  • Jar Signer for signing Java ARchive (JAR) files.
  • Policy Tool for granting access to system resources.
  • Java Foundation Classes (JFC) which consists of Swing 1.0, Drag and Drop, and Java 2D class libraries.
  • Java Plug-in
  • Scrollable result sets, BLOB, CLOB, batch update, user-defined types in JDBC.
  • Audio support in Applets.

JDK Version 1.1

Released on February 19, 1997

New features in JDK 1.1

  • JDBC (Java Database Connectivity)
  • Inner Classes
  • Java Beans
  • RMI (Remote Method Invocation)
  • Reflection (introspection only)

JDK Version 1.0

Codenamed Oak and released on January 23, 1996.