Java Features JDK 5





Features added in Java5.0 :

The codename of this version is Tiger. This version was release in 2004 was originally numbered 1.5, which is still used as the internal version number. The number was changed to "better reflect the level of maturity, stability, scalability and security of the J2SE. This version bring the major upgrades in the language, these are:


  • Java Generics : provides compile-time (static) type safety for collections and eliminates the need for most typecasts (type conversion).

  • Example:
    import java.util.*;
    class Test 
    {
     public static void main(String[] ar)
     {
      //Typesafe ArrayList
      ArrayList< Float> il; //Generics
      il = new ArrayList< Float >();
      il.add(10.0f);
      il.add(100.9f);
      il.add(1000.3f);
      System.out.print(il);
     }
    }
    

  • Annotation : also called metadata that allows language constructs such as classes and methods to be tagged with additional structural information.

  • Example:
    class A{
     void show(){
      System.out.print("SHOW");
     }
     void put(){
      System.out.print("PUT");
     }
    }
    class b extends A{
     @Override   //Annotation
     void show(){
      System.out.print("NEW SHOW");
     }
    }
    

  • Autoboxing/Autounboxing : automatic conversions between primitive types (such as int) and primitive wrapper classes (such as Integer) .

  • Example:
    class Test 
    {
     public static void main(String[] ar)
     {
      int i1 = 20;
      Integer i2 = i1;  //AutoBoxing
      int i3 = i2;      //AutoUnBoxing
      System.out.print(i1);
      System.out.print(i2);
      System.out.print(i3); 
     }
    }
    

  • Enumerations : the enum keyword creates a typesafe, ordered list of values (such as Day.MONDAY, Day.TUESDAY, etc.).

  • Example
    class Test 
    {
     enum Day{MON,TUE,WED,THU,FRI,SAT};
     public static void main(String[] ar)
     {
      Day today = Day.FRI;
      System.out.print(today);
     }
    }
    

  • Varargs : the last parameter of a method can now be declared using a type name followed by three dots.

  • Example
    class Test 
    {
     void print(int ... x)   //VarArg
     {
      for(int i=0; i< x.length; i++)
      {
       System.out.print(x[i]); 
      }
     }
     public static void main(String[] ar)
     {
       Test ob = new Test();
       ob.print();
       ob.print(1,2,3);
       ob.print(1,2,3,4);
       ob.print(1,2,3,4,5,6);
     }
    }
    

  • Enhanced for each loop : the for loop syntax is extended with special syntax for iterating over each member of either an array.

  • Example
    class Test 
    {
     public static void main(String[] ar)
     {
      String names [] = {
    	"Amit","Ayaan","Priya",
    	"Alok","Hasan","Varun"
      };
      //For-Each Loop
      for(String name : names)
      {
       System.out.println(name);
      }
     }
    }
    
Example
//Static Import		
import static java.lang.System.*;
import static java.lang.Math.*;
class Test 
{
 public static void main(String[] ar)
 {
  double d = 2.0;
  double v1 = sqrt(d);
  double v2 = random();
  out.print(v1);
  out.print(v2);
 }
}

Next topic is java-features-jdk-6




 






Training For College Campus

We offers college campus training for all streams like CS, IT, ECE, Mechanical, Civil etc. on different technologies like
C, C++, Data Structure, Core Java, Advance Java, Struts Framework, Hibernate, Python, Android, Big-Data, Ebedded & Robotics etc.

Please mail your requirement at info@prowessapps.in


Projects For Students

Students can contact us for their projects on different technologies Core Java, Advance Java, Android etc.

Students can mail requirement at info@prowessapps.in



CONTACT DETAILS

info@prowessapps.in
(8AM to 10PM):

+91-9026070669 , +91-9451396824

© 2016, prowessapps.in, All rights reserved