18 Aug 2011

JDK 7 features



Java Development Kit (JDK) 7 is most recent release of Java Standard Platform. I takes the birth at the OpenJDK project and has taken collaborative effort of Sun and Java developer community.


JVM
  • Extensions to the JVM  to support the implementation of dynamically-typed languages (InvokeDynamic) at performance levels near to that of the Java language itself. 

Programming Language
  • The integral types (byteshortint, and long) can also be expressed using the binary number system. To specify a binary literal, add the prefix 0b or 0B to the number.
  • The String class can be used in the expression of a switch statement.
  • A single catch block can handle more than one type of exception. In addition, the compiler performs more precise analysis of rethrown exceptions than earlier releases of Java SE.
  • The try-with-resources statement ensures that each resource is closed at the end of the statement. Any object that implements the new java.lang.AutoCloseable interface or the java.io.Closeable interface can be used as a resource. 
  • The type arguments required to invoke the constructor of a generic class can be replaced with an empty set of type parameters (<>) as long as the compiler can infer the type arguments from the context.
  • The Java SE 7 complier generates a warning at the declaration site of a varargs method or constructor with a non-reifiable varargs formal parameter.
  
Networking 
  • The URLClassLoader.close() method effectively eliminates the problem of how to support updated implementations of the classes and resources loaded from a particular codebase, and in particular from JAR files.
  • Sockets Direct Protocol support for reliable, high-performance network streams over Infiniband connections on Solaris and Linux.

Concurrency Utilities
  • The fork/join framework is designed to efficiently run a large number of tasks using a pool of worker threads.
  • The ThreadLocalRandom class eliminates contention among threads using pseudo-random numbers.
  • The Phaser class is a new synchronization barrier.

I/O
  • New APIs for filesystem access, scalable asynchronous I/O operations, socket-channel binding and configuration, and multicast datagrams.
  • A fully-functional and supported NIO.2 filesystem provider for zip and jar files.

JDBC
  • The ability to use a try-with-resources statement to automatically close resources of type ConnectionResultSetand Statement.
  • RowSet 1.1: The introduction of the RowSetFactory interface and the RowSetProvider class, which enable you to create all types of row sets supported by your JDBC driver.


    6 Aug 2011

    Under the Hood : Java Program Execution


    Starting JVM
    By invoking the main() of a class and passing argument to it. But at this stage main() still not invoked ,because JVM does not have binary representation of the class.


    Loading class or interface.
    JVM retrieve the binary representation of a class or interface from compiled source code and constructing the .class file format.

    Loading is implemented by the ClassLoader and its subclasses.
    If any error occurs during loading  , it throws instance of LinkageError or its subclasses.
    Array classes do not have an external binary representation; they are created by the Java virtual machine rather than by a class loader.


    Linking {Verification, Preparation, Resolution} class or interface
    Linking is a process of taking binary form of class or interface and combining it to run-time state of the Java virtual machine.
     Verification ensures that the binary representation of a class or interface is structurally correct.
    For example, it checks that every instruction has a valid operation code, every method is provided with a structurally correct signature etc.
    If an error occurs during verification, , it throws instance of LinkageError or its subclasses.
    Preparation involves creating the static fields for a class or interface and initializing such fields to the standard default values or explicit .
    Resolution is the process of checking symbolic references from class other classes and interfaces, by loading the other classes and interfaces that are mentioned and checking that the references are correct.
    If an error occurs during Resolution, it throws instance of IncompatibleClassChangeError or its subclasses


    Initialization class or interface
    Initializes the static initializer block and static fields but final  static field are not initialized at  this stage because they are complie-time constant..
    Initialization occur before any instance is created or any static method is invoked.
    Once a class is initialized  its main() is invoked by JVM.
    Before a class or interface is initialized, its direct superclass must be initialized, but interfaces implemented by the class need not be initialized.
    the superinterfaces of an interface need not be initialized before the interface is initialized.


    Instantiation of class
    When new() operator is encountered a instance is created.
    Memory is allocated for instance variable of class and that of its superclass as well.
    If there is not sufficient space available to allocate memory for the object, then creation of the class instance completes abruptly with an OutOfMemoryError.


    Unloading class and interface.
    A class or interface may be unloaded if and only if its class loader is unreachable.
    The bootstrap class loader is always reachable; as a result, system classes may never be unloaded.


    JVM Exists
    The Java virtual machine terminates all its activity and exits when one of two things happens: 
    All the threads that are not daemon threads terminate.
    Some thread invokes the exit method of class Runtime or class System, and the exit operation is permitted by the security manager.