Está en la página 1de 18

Java SE 7

- Kavyashree C M

Table Of Contents
Why Java 7? IO and New IO Package(JSR 203) Java programming language(JSR 334) JDBC

Why Java 7?
Provides comprehensive support for file I/O and accessing file system.

Ability to manipulate contents of zip/JAR file.


Try with resources and without catch/ finally.

Strings in switch case.


Ability to catch multiple Exceptions.

IO and New IO package(NIO2)


The java.nio.file package and its related package, java.nio.file.attribute, provide comprehensive support for file I/O and for accessing the file system. A zip file system provider is also available in JDK 7.
URI uri= URI.create("jar:file:/codeSamples/zipfs/zipfstest.zip");

FileSystem fs = FileSystems.newFileSystem(uri, env); Path zipfile = Paths.get("/codeSamples/zipfs/zipfstest.zip"); FileSystem fs = FileSystems.newFileSystem(zipfile, env, null);

File I/O
Commonly used methods for small files.
readAllBytes(Path) or readAllLines(Path,Charset) write(Path,byte[],OpenOption) or write(Path,Iterable<? extends CharSequence>, Charset,OpenOption)

Buffered IO methods for text files


Reading a file by using Buffered Stream I/O
newBufferedReader(Path,Charset)

Writing a file by using Buffered Stream I/O


newBufferedWriter(Path,Charset,OpenOption)

Methods for Unbuffered Streams And Interoperable with java APIs


Reading a file by using Stream I/O
newInputStream(Path,OpenOption)

Creating and Writing a file using Stream I/O


newOutputStream(Path,OpenOption)

Methods for channels and ByteBuffers


Reading and Writing Files By Channel I/O
newByteChannel(Path,OpenOption) newByteChannel(Path, Set<? extends OpenOption>, FileAttribute<?>)

Method for Creating regular and temporary Files


Creating Files
createFile(Path, FileAttribute<?>)

Creating Temporary Files


createTempFile(Path,String,String,FileAttribute<?>) createTempFile(String,String,FileAttribute<?>)

Java Programming Language/Project Coin


Binary Literals Underscores in Numeric Values String in Switch Statements Type interference for generic instance creation

Improved Compiler Warnings and Errors when Using Non-Reifiable Formal Parameters with Varargs.

Try with resources statement.


Catching Multiple Exception Type and Rethrowing Exceptions with Improved Type Checking.

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

Types of RowSet.
CachedRowSet
ResultSet rs = stmt.executeQuery("SELECT * FROM EMPLOYEES"); CachedRowSetImpl crs = new CachedRowSetImpl(); crs.populate(rs); while (crs.next()) { String name = crs.getString(1); }

FilteredRowSet
FilteredRowSet frs = new FilteredRowSetImpl(); frs.populate(rs); Range name = new Range("Alpha", "Bravo"); frs.setFilter(name); frs.next();

JdbcRowSet
JdbcRowSetImpl jrs = new JdbcRowSetImpl(); jrs.setCommand("SELECT * FROM TITLES"); jrs.setURL("jdbc:myDriver:myAttribute"); jrs.setUsername("cervantes"); jrs.setPassword("sancho"); jrs.execute();

WebRowSet

JoinRowSet
JoinRowSet jrs = new JoinRowSetImpl(); ResultSet rs1 = stmt.executeQuery("SELECT * FROM EMPLOYEES"); CachedRowSet empl = new CachedRowSetImpl(); empl.populate(rs1); empl.setMatchColumn(1); jrs.addRowSet(empl); ResultSet rs2 = stmt.executeQuery("SELECT * FROM OFFICE_BONUS_PLAN"); CachedRowSet bonus = new CachedRowSetImpl(); bonus.populate(rs2); bonus.setMatchColumn(1); jrs.addRowSet(bonus);

Comparison between Java 6 and Java 7


Features Accessing JAR files Java 6 Java 7 Allowed, using URI. Allowed, using Path.

Strings In switch case


Try with Resources Multiple catch exceptions Binary Literals Underscores in Numeric Literals

Not allowed
Not Allowed Not Allowed Not Allowed Not Allowed

Allowed
Allowed Allowed Allowed Allowed

JDBC version

4.0

4.1

References
http://www.oracle.com http://www.javagava.com

Questions?

Thank You

También podría gustarte