7:42 PM
0







Java,Standard Edition 5 is a major feature release.
The following lists highlights many of important features and enhancements in Java SE 5. 

1) For-Each
2) Var-arg
3) Queue
4) Enum
5) Autoboxing and unboxing
6) Co-varient return types
7) Annotations
8) Generics
9) Static import
10) String builder


For-Each :

It is enhanced version of for loop
It is suitable for retrieve the elements of arrays and collections.By using this For-Each loop we can easily retrieve elements from array or collections.

Example:

public class Demo
{
public static void main(String args[]){
int[] a = {10,20,30};
for(int x : a)
{
System.out.println(x);
}}}

output:
10
20
30

var-arg:


Until 1.4 version we can’t declared a method with variable no. Of arguments. If there is a change in no of arguments compulsory we have to define a new method. This approach increases length of the code and reduces readability. But from 1.5 version onward s we can declare a method with variable no. Of arguments such type of methods are called var-arg methods.

We can declare a var-arg method as follows.
     
Syntax: mO(int... x)

We can call or invoke this method by passing any no. Of int values including zero number.

Example:

class VarArgDemo
{
public static void mO(int... x)
{
System.out.println("var-arg method");
}
public static void main(String[] args)
{
mO();
mO(100);
mO(100,250,330);
}
}

Output:

var-arg method
var-arg method
var-arg method

Queue:

Queue is the concept which is involved in java.util package.It is the child interface of Collection.It has one sub class PriorityQueue.If we want to represent a group of individual objects prior to processing then we should go for queue concept. LinkedList based implementation of Queue always follows first in first out order.

important methods present in Queue Interface are:

1. boolean after(Object o)

It is used to add an object into the Queue.

2. Object poll();

To remove and return head element of the Queue, if Queue  
is empty then we will get null.

3. Object remove();


To remove and return head element of the Queue. If Queue 
is empty then this method raises Runtime Exception saying 
NoSuchElementException.

4. Object peek();

To return head element of the Queue without removal, if 
Queue is empty this method returns null.

5.Object element();

It returns head element of the Queue and if Queue is empty 
then it will raise Runtime Exeption
saying NoSuchElementException

Enum:
    
We can use enum to define a group of named constants.
By using enum we can define our own data types which are also come enumerated data types.Internally enum’s are implemented by using class concept. Every enum constant is a reference variable to that enum type object.Every enum constant is implicitly public static final always.

Example :

enum Day
{
MON,TUE,WED;.
}
class EnumDemo
{
public static void main(String args[]){
Beer b1=Beer.MON;
System.out.println(b1);
}
}

Output:

java EnumDEmo
MON


The remaining topics will be posted individually in next posts

0 comments:

Post a Comment