Header Ads

  • Breaking Now

    Interview Questions on Java 5

    - What are the new features in Java 5 as compared to its earlier versions?

    Java 2 Platform Standard Edition 5.0 was a major feature release. The following features were introduced in 5.0 since previous major release and that was 1.4.0.

    Summary:
    - Performance Enhancements
    a.Garbage collection performance enhancements
    b.Introduction to StringBuilder
    c.Java 2D technology
    d.Image I/O - Performance and memory

    - Language Specific Features:
    a.Generics
    b.Enhanced for Loop
    c.Autoboxing/Unboxing
    d.Typesafe Enums
    e.Varargs
    f.Static Import
    g.Metadata (Annotations)

    The list is long which you can catch in detail at following URL:

    Java 5 New Features

    - What is Autoboxing/Unboxing and what are its advantages?

    The conversion from primitive types to wrapper types objects is automated. This facility eleminates pain of manual conversion from primitive to wrapper types.
    Boxing converts primitive values to objects of corresponding wrapper types.
    Unboxing converts objects of wrapper types to values of corresponding primitive types.

    Assignment Conversions on boolean and numeric types.
    boolean boolValue = true;
    byte b = 2;
    short s = 2;
    char c ='2';
    int i = 2;

    // Boxing
    Boolean boolReference = boolValue;
    Byte bReference = (byte) 4;
    Short sReference = (short) 4;
    // both byte and short type casting is to be done as int cannot be assigned to Byte and Short respectively
    Character cReference = '4';
    Integer iReference = 4;

    // Unboxing
    boolean boolValue1 = boolReference;
    byte b1 = bReference;
    short s1 = sReference;
    char c1 = cReference;
    int i1 = iReference;


    The usage of autoboxing/unboxing can be found:
    - In the if statement, condition can be Boolean.
    - In the switch statement, the switch expression can be Character, Byte, Short or Integer.
    - In the while, do-while and for statements, the condition can be Boolean.

    More questions in my next post on Java 5.

    No comments

    Post Top Ad

    Post Bottom Ad