J2SE5 by Luqman

Embed Size (px)

Citation preview

  • 8/6/2019 J2SE5 by Luqman

    1/50

    J2SE 5.0Tiger

  • 8/6/2019 J2SE5 by Luqman

    2/50

    J2SE Road Map

    Version Code Name Release Date

    JDK 1.1.4

    JDK 1.1.5

    JDK 1.1.6

    JDK 1.1.7JDK 1.1.8

    J2SE 1.2

    J2SE 1.2.1

    J2SE 1.2.2

    J2SE 1.3

    J2SE 1.3.1

    J2SE 1.4.0

    J2SE 1.4.1

    J2SE 1.4.2

    Sparkler

    Pumpkin

    Abigail

    BrutusChelsea

    Playground

    (none)

    Cricket

    Kestrel

    Ladybird

    Merlin

    Hopper

    Mantis

    Sept 12, 1997

    Dec 3, 1997

    April 24, 1998

    Sept 28, 1998April 8, 1999

    Dec 4, 1998

    March 30, 1999

    July 8, 1999

    May 8, 2000

    May 17, 2001

    Feb 13, 2002

    Sept 16, 2002

    June 26, 2003

    J2SE 5.0 (1.5.0) Tiger Sept 29, 2004

  • 8/6/2019 J2SE5 by Luqman

    3/50

    J2SE Themes

    J2SE 1.4.0 - Quality(Merlin)

    J2SE 5.0 - Ease of Development

    (Tiger)

    J2SE 6.0 - Becoming more open

    (Mustang) (Java goes multilingual)

  • 8/6/2019 J2SE5 by Luqman

    4/50

    Theme forJ2SE 5.0

    Ease of development

    Quality

    Monitoring and Manageability

    Performance and Scalability

    Desktop Client

  • 8/6/2019 J2SE5 by Luqman

    5/50

    New Features in J2SE 5.0

    Language Features

    Virtual Machine Features

    Performance Enhancements

    Base Libraries

    Integration Libraries

  • 8/6/2019 J2SE5 by Luqman

    6/50

    New Features in J2SE 5.0

    Language Features

    Virtual Machine Features

    Performance Enhancements

    Base Libraries

    Integration Libraries

  • 8/6/2019 J2SE5 by Luqman

    7/50

    Language Features

    Generics

    Enhanced forLoop Variable Arguments

    Boxing / Unboxing

    Type-safe enumerations Static import

  • 8/6/2019 J2SE5 by Luqman

    8/50

    Generics

    A way to make class type-safe that are

    written on any arbitrary object type.

    Allows to narrow an instance of a Collection

    to hold a specific object type and eliminating

    the need to typecast it while retrieving the

    object.

  • 8/6/2019 J2SE5 by Luqman

    9/50

    J2SE 1.4.0

    ArrayList intList = new ArrayList();

    intList.add(new Integer(0));

    Integer intObj = (Integer) intList.get(0);

    J2SE 5.0

    ArrayList intList = new ArrayList();intList.add(new Integer(0)); // Only Integer Objects allowed

    Integer intObj = intList.get(0); // No need to Type Cast

  • 8/6/2019 J2SE5 by Luqman

    10/50

    Enhanced for Loop

    Iterating over collections is a pain.

    Often, iterator is unused except to get elements. Iterators are error-prone.

    Iterator variable occurs three times per loop.

    Gives you two opportunities to get it wrong.

    Common cut-and-paste error. Wouldnt it be nice if the compiler took care of the

    iterator for you?

  • 8/6/2019 J2SE5 by Luqman

    11/50

    J2SE 1.4.0

    for(Iterator iter = myArray.iterator(); iter.hasNext(); ){

    MyClass myObj = (MyClass)iter.next();

    myObj.someOperation();

    }

    J2SE 5.0

    for(MyClass myObj : myArray){

    myObj.someOperation();

    }

  • 8/6/2019 J2SE5 by Luqman

    12/50

    // Returns the sum of the elements of a

    int sum(int[] a)

    {

    int result = 0;

    for (int i : a)

    result += i;

    return result;

    }

    For Arrays

    Eliminates array index rather than iterator

    Similar advantages

  • 8/6/2019 J2SE5 by Luqman

    13/50

    Variable Arguments

    To write a method that takes an arbitrary

    number of parameters, you must use anarray.

    Creating and initializing arrays is a pain.

    Why not complier take care of it?

  • 8/6/2019 J2SE5 by Luqman

    14/50

    public int sum(int... intList){int i, sum;

    sum=0;

    for(i=0; i

  • 8/6/2019 J2SE5 by Luqman

    15/50

    Boxing / Unboxing

    Collections hold only objects, so to put

    primitive data types it needs to be wrappedinto a class, like int to Integer.

    It is a pain to wrap and unwrap.

    Wouldnt it be nice if the compiler took care

    of it for you?

  • 8/6/2019 J2SE5 by Luqman

    16/50

    J2SE 1.4.0

    ArrayList arrayList = new ArrayList();

    Integer intObject = new Integer(10);

    arrayList.add(intObject);// cannot add 10 directly

    J2SE 5.0

    ArrayList arrayList = new ArrayList();

    arrayList.add(10);// int 10 is automatically wrapped into Integer

  • 8/6/2019 J2SE5 by Luqman

    17/50

    Type-safe enumerations

    Compiler support for Typesafe Enum pattern.

    Looks like traditional enum (C, C++, Pascal). Far more powerful.

    Can be used in switch/case statements.

    Can be used in for loops.

  • 8/6/2019 J2SE5 by Luqman

    18/50

    An enumeration is an ordered list of items wrapped into a

    single entity.

    enum Season {winter, spring, summer, fall}

    UsageE

    xamplefor (Season s : Season.VALUES){

    //

    }

    An enumeration (abbreviated enum in Java) is a special type of class.

    All enumerations implicitly subclass a new class in Java,java.lang.Enum.

    This class cannot be subclassed manually.

  • 8/6/2019 J2SE5 by Luqman

    19/50

    Static import

    Ability to access static members from a class

    without need to qualify them with a classname.

  • 8/6/2019 J2SE5 by Luqman

    20/50

    interface ShapeNumbers {

    public static int CIRCLE = 0;public static int SQUARE = 1;

    public static int TRIANGLE = 2;

    }

    Implementing this interface creates an unnecessary dependence on

    the ShapeNumbers interface.

    It becomes awkward to maintain as the class evolves, especially if

    other classes need access to these constants also and implement this

    interface

  • 8/6/2019 J2SE5 by Luqman

    21/50

    To make this cleaner, the static members are placed into a class and

    then imported via a modified syntax of the import directive.

    package MyConstants;

    class ShapeNumbers {

    public static int CIRCLE = 0;

    public static int SQUARE = 1;

    public static int TRIANGLE = 2;}

    To import the static members in your class, specify the following in the import section

    of yourJava source file.

    import static MyConstants.ShapeNumbers.*;// imports all static data

    You can also import constants individually by using the following syntax:

    import static MyConstants.ShapeNumbers.CIRCLE;

    import static MyConstants.ShapeNumbers.SQUARE;

  • 8/6/2019 J2SE5 by Luqman

    22/50

    New Features in J2SE 5.0

    Language Features

    Virtual Machine Features

    Performance Enhancements

    Base Libraries

    Integration Libraries

  • 8/6/2019 J2SE5 by Luqman

    23/50

    Virtual Machine Features

    Class Data Sharing

    Server-Class Machine Detection Garbage Collector Ergonomics

    Thread Priority Changes

    High-Precision Timing Support

  • 8/6/2019 J2SE5 by Luqman

    24/50

    Class Data Sharing

    Reduces startup time of java applications.

    Better results for smaller applications. Automatically enabled when conditions allow it to

    be used.

    Not supported in Microsoft Windows 95/98/ME.

  • 8/6/2019 J2SE5 by Luqman

    25/50

    How CDS Works :

    When JRE is installed on 32-bit platforms using the Sun providedinstaller, it loads a set of classes from the system jar file into a

    private internal representation, and dumps that representation to a

    file, called a "shared archive".

    Unix : jre/lib/[arch]/client/classes.jsa

    Windows : jre/bin/client/classes.jsa

    During subsequent JVM invocations, the shared archive is

    memory-mapped in, saving the cost of loading those classes and

    allowing much of the JVM's metadata for these classes to be

    shared among multiple JVM processes.

    CDS produces better results for smaller applications because it

    eliminates a fixed cost of loading certain core classes.

  • 8/6/2019 J2SE5 by Luqman

    26/50

    The footprint cost of new JVM instances has been

    reduced in two ways.

    First, a portion of the shared archive, currently 5-6 MB, is

    mapped read-only and therefore shared among multiple

    JVM processes. Previously this data was replicated in

    each JVM instance.

    Second, since the shared archive contains class data in

    the form in which the Java VM uses it, the memory which

    would otherwise be required to access the original class

    information in rt.jar is not needed.

    These savings allow more applications to be run concurrently

    on the same machine.

  • 8/6/2019 J2SE5 by Luqman

    27/50

    Server-Class Machine Detection

    At startup Launcher automatically detects if

    application is running on server-class Machine.

    Uses ServerVM / Client VM accordingly.

    Server-class Machine : One with at least 2 CPUs and

    at least 2GB of physical memory.

    ServerVM start more slowly than client VM, but over time runs

    more quickly.

  • 8/6/2019 J2SE5 by Luqman

    28/50

    Garbage CollectorErgonomics

    On server-class machines running the server VM,

    the garbage collector (GC) has changed from the

    previous serial collector to a parallel collector.

    Can switch the GC collector mode using the

    command-line option.

    XX:+UseSerialGC - Serial collector

    XX:+UseParallelGC - Parallel collector

  • 8/6/2019 J2SE5 by Luqman

    29/50

    Thread Priority Changes

    Java threads and Native threads to compete on equalfooting.

    Java threads at NORM_PRIORITY can now competeas expected with native threads.

    Java priorities in the range [10...5] are all mapped to the

    highest possible TS (timeshare) or IA (interactive)priority.

    Priorities in the range [1..4] are mapped tocorrespondingly lower native TS or IA priorities

  • 8/6/2019 J2SE5 by Luqman

    30/50

    High-Precision Timing Support

    System.nanoTime() method added.

    Provides access to nanosecond granularity

    time source for relative time measurements.

    The actual precision of the time value

    returned is platform dependant.

  • 8/6/2019 J2SE5 by Luqman

    31/50

    New Features in J2SE 5.0

    Language Features

    Virtual Machine Features

    Performance Enhancements

    Base Libraries

    Integration Libraries

  • 8/6/2019 J2SE5 by Luqman

    32/50

    Performance Enhancements

    Garbage collection Ergonomics

    StringBuilder Class Java 2D Technology

    Image I/O

  • 8/6/2019 J2SE5 by Luqman

    33/50

    Garbage collection Ergonomics

    Automatic detection of Sever-Class Machine

    Using Client / ServerVM accordingly. Parallel Garbage Collection

    Default parallel garbage collection on ServerVM.

  • 8/6/2019 J2SE5 by Luqman

    34/50

    StringBuilder Class

    Introduced a new classjava.lang.StringBuilder.

    It is like unsunchronized StringBuffer. Faster than StringBuffer.

  • 8/6/2019 J2SE5 by Luqman

    35/50

    Java 2D Technology

    Improved acceleration for Buffered Image

    Objects Support for H/W accelerated rendering using

    OpenGL.

    Improved text-rendering performance.

  • 8/6/2019 J2SE5 by Luqman

    36/50

    Image I/O

    Improved Performance and memory usage

    while reading and writing JPEG Images.

    In mage I/O API (javax.imageio) added

    support for reading and writing BMP and

    WBMP images.

  • 8/6/2019 J2SE5 by Luqman

    37/50

    New Features in J2SE 5.0

    Language Features

    Virtual Machine Features

    Performance Enhancements

    Base Libraries

    Integration Libraries

  • 8/6/2019 J2SE5 by Luqman

    38/50

    Base Libraries

    Lang and Util Packages

    Networking JAXP

    Bit Manipulation Operations

  • 8/6/2019 J2SE5 by Luqman

    39/50

    Lang and Util Packages

    ProcesBuilder More convenient way to invoke sub processes than Runtime.exec

    Formatter printfstyle format strings.

    Support for layout justification and alignment, common formats for

    numeric, string and date/time data.

    Scanner Converts text into primitives or Strings.

    regular expression based searches on streams, file data,

    strings.

  • 8/6/2019 J2SE5 by Luqman

    40/50

    Lang and Util Packages contd

    Instrumentation

    New packagejava.land.instrument, allows javaprogramming agents to instrument programs running on the

    Java virtual machine by modifying methods' bytecodes at

    runtime

    Threads

    getState() for querying the execution state of a thread. getStackTrace to obtain stack trace of a thread.

    A new form of the sleep() method is provided which allows

    for sleep times smaller than one millisecond.

  • 8/6/2019 J2SE5 by Luqman

    41/50

    Networking

    Complete support for IPv6 on Windows XP

    (sp1) and 2003. ping like feature InetAddress class

    provides API to test the reachability of a host.

    Improved Cookie support.

    Proxy Sever Configuration ProxySelector

    API provides dynamic proxy configuration.

  • 8/6/2019 J2SE5 by Luqman

    42/50

    JAXP 1.3

    A built-in validation processor forXML Schema.

    XSLTC, the fast, compiling transformer, which is nowthe default engine for XSLT processing.

    Java-Centric XPathAPIs injavax.xml.xpath, which

    provide a more java-friendly way to use an XPath

    expression.

    Grammar pre-parsing and caching, which has a

    major impact on performance for high-volume XML

    processing.

  • 8/6/2019 J2SE5 by Luqman

    43/50

    Bit Manipulation Operations

    The wrapper classes (Integer, Long, Short, Byte, andChar) now support common bit manipulation

    operations like highestOneBit,

    lowestOneBit,

    numberOfLeadingZeros,

    numberOfTrailingZeros,

    bitCount, rotateLeft,

    rotateRight,

    reverse,

    signum, and

    reverseBytes.

  • 8/6/2019 J2SE5 by Luqman

    44/50

    New Features in J2SE 5.0

    Language Features

    Virtual Machine Features

    Performance Enhancements

    Base Libraries

    Integration Libraries

  • 8/6/2019 J2SE5 by Luqman

    45/50

    Integration Libraries

    Remote Method Invocation (RMI)

    Java Database Connectivity (JDBC) Java Naming and Directory Interface (JNDI)

  • 8/6/2019 J2SE5 by Luqman

    46/50

    Remote Method Invocation (RMI)

    Dynamic Generation of Stub Classes G

    eneration of stub at runtime eliminated the need of stubcompilerrmic.

    Standard SSL/TLS Socket Factory Classes Standard Java RMI socket factory classes,

    javax.rmi.ssl.SslRMIClientSocketFactory and

    javax.rmi.ssl.SslRMIServerSocketFactory added. Communicate over the Secure Sockets Layer (SSL) or

    Transport Layer Security (TLS) protocols using the Java

    Secure Socket Extension (JSSE).

  • 8/6/2019 J2SE5 by Luqman

    47/50

    Java Database Connectivity (JDBC)

    RowSetinterface has been implemented in five

    common ways a RowSet object can be used.

    JdbcRowSet- used to encapsulate a result set or a driver.

    CachedRowSet- disconnects from its data source and operatesindependently except when it is getting data from the data source

    or writing modified data back to the data source.

    FilteredRowSet- extends CachedRowSet and is used to get a

    subset of data.

    JoinRowSet- extends CachedRowSet and is used to get anSQL JOIN of data from multiple RowSet objects.

    WebRowSet- extends CachedRowSet and is used for XMLdata.

  • 8/6/2019 J2SE5 by Luqman

    48/50

  • 8/6/2019 J2SE5 by Luqman

    49/50

    Q & ATiger

  • 8/6/2019 J2SE5 by Luqman

    50/50

    Thank You