Loading
New in Java 7

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  What is new in Java 7


Ans)

Here are some of the important features that are introduced in Java 7. 


Small Language Enhancements :

i) Strings in switch:
 

"String" is being newly added to the list of types which can be switched on "The switch Statement" is augmented.

Now the type of the Expression must be char, byte, short, int, Character, Byte, Short,  Integer, String, or an enum type,

or a compile-time error occurs."

2) Multi-catch and more precise rethrow :
Two changes are made to exception handling. First, multiple exception types can be named
as being handled by a single catch block. Second, if an exception parameter is not modified
and if it is rethrown inside the catch block, the compiler applies a more precise analysis
to determine the type of what can be thrown.

Please see below example, we are catching both
"ClassNotFoundError as well as IllegalAccessException ex" in single catch block.

try {
//throws some ReflectiveOperationException }
catch (ClassNotFoundError | IllegalAccessException ex) { //body }

 
Method to close a URLClassLoader :

URLClassLoader.close() is being added, this method effectively invalidates the loader,
so that no new classes can be loaded from it. It also closes any JAR files that were
opened by the loader. This allows the application to delete or replace these files and,
if necessary, create new loaders using new implementations.

       //
       // create a class loader loading from "foo.jar"
       //
       URL url = new URL("file:foo.jar");
       URLClassLoader loader = new URLClassLoader (new URL[] {url});
       Class cl = Class.forName ("Foo", true, loader);
       Runnable foo = (Runnable) cl.newInstance();
       foo.run();
       loader.close ();

       // foo.jar gets updated somehow

       loader = new URLClassLoader (new URL[] {url});
       cl = Class.forName ("Foo", true, loader);
       foo = (Runnable) cl.newInstance();
       // run the new implementation of Foo
       foo.run();
   

Parallelize your arrays with JSR 166y (this meets Groovy) :
In brief, they allow you to perform operations like filtering or calculations on elements
stored in a collection in parallel
. And what is important, very little knowledge of
concurrent programming is required to use Parallel Arrays.

//create a thread pool and store the collection in a Parallel Array
        final ForkJoinPool pool = new ForkJoinPool(2);
        final ParallelArray people = ParallelArray.createFromCopy(friends, pool);

        //Create a predicate for filtering
        final Ops.Predicate aMale = new Ops.Predicate() {
            public boolean op(final Person friend) {
                return friend.isMale();
            }
        };

        //Create an operation to retrieve the name from an element
        final Ops.Op retrieveName = new Ops.Op() {
            public Object op(final Person friend) {
                return friend.getName();
            }
        };

        //Perform filtering and mapping concurrently on all elements of the collection
        final ParallelArraynamesOfMen = people.withFilter(aMale).withMapping(retrieveName).all();
System.out.println("namesOfMen = " + namesOfMen);


I/O and Networking :
JSR 203: More new I/O APIs for the Java platform (NIO.2)
New APIs for filesystem access, scalable asynchronous I/O operations, socket-channel binding
and configuration, and multicast datagrams

The More New I/O APIs for the Java™ Platform (NIO.2) is one of the major new functional areas
in Java 7, adding asynchronous channel functionality and a new file system API to the language.


Database Connectivity :
JDBC 4.1
Upgrade to JDBC 4.1 and Rowset 1.1, introduced new classes like "RowSetProvider","RowSetFactory".

Please take a look at the Example below.

        public void jDBC_4.1_Method(
                String sampleUserName, String samplePassword) throws SQLException

                {      
                      RowSetFactory sampleRowSetFactory = null;  
                     JdbcRowSet sampleRowSet = null; 
                         try       
                         {  
                         sampleRowSetFactory = RowSetProvider.newFactory(); 
                         sampleRowSet = sampleRowSetFactory.createJdbcRowSet();      
                         sampleRowSet.setUrl("jdbc:sampleDriver:sampleAttribute");       
                         sampleRowSet.setUsername(sampleUserName);         
                         sampleRowSet.setPassword(samplePassword); 
                         sampleRowSet.setCommand("select EMPNO, NAME, ADDRESS from EMPLOYEE");
                                sampleRowSet.execute();        
                                          // …       
                         }             
                         catch(Exception e)          
                         {           
                         }
                         }
     



Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

New in Java 7


New in Java 7

-------------------------------------------------------------------------------------------------------



Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free