55 new things in Java 7 - Devoxx France

David Delabassee
David DelabasseeDevRel - Java Platform Group - Oracle
(+) 55 fonctionnalités de Java 7 dont
  vous n'avez (probablement) pas
       encore entendu parler
             par David Delabassée
                 @delabassee




                                        1
About me...

•    David Delabassée

    - ... Sun, Oracle

    - Devoxx (Belgium) Steering

•    @delabassee




                                       2
The preceding is intended to outline our general product direction.
It is intended for information purposes only, and may not be
incorporated into any contract. It is not a commitment to deliver
any material, code, or functionality, and should not be relied upon in
making purchasing decisions.
The development, release, and timing of any features or functionality
described for Oracle’s products remains at the sole discretion of
Oracle.



                                                                         3
Java 7
•   InvokeDynamic

•   Fork/Join

•   NIO.2

•   Project Coin

•   ...



                             4
Project Coin



               5
Binary Literals
 1: int mask = 0b101010101010;
 2: aShort = (short)0b1010000101000101;
 3: long aLong = 0b1010000101000101101000010100010110100001010001011010000101000101L;

 1: HAPPY_FACE = {
 2:    (short)0b0000011111100000;
 3:    (short)0b0000100000010000;
 4:    (short)0b0001000000001000;
 5:    (short)0b0010000000000100;
 6:    (short)0b0100000000000010;
 7:    (short)0b1000011001100001;
 8:    (short)0b1000011001100001;
 9:    (short)0b1000000000000001;
10:    (short)0b1000000000000001;
11:    (short)0b1001000000001001;
12:    (short)0b1000100000010001;
13:    (short)0b0100011111100010;
14:    (short)0b0010000000000100;
15:    (short)0b0001000000001000;
16:    (short)0b0000100000010000;
17:    (short)0b0000011111100000; }
                                                                                        6
Underscores in Numeric Literals
• Valid
    int mask = 0b1010_1010_1010;
    long big = 9_223_783_036_967_937L;
    long creditCardNumber = 1234_5678_9012_3456L;
    long socialSecurityNumber = 999_99_9999L;
    float pi = ! 3.14_15F;
    long hexBytes = 0xFF_EC_DE_5E;
    long hexWords = 0xCAFE_BFFE;

• Invalid
    float pi1 = 3_.1415F;          float pi2 = 3._1415F;
    long ssn = 999_99_9999_L;
    int x1 = _52;                  int x1 = 52_;
    int x2 = 0_x52;                int x2 = 0x_52;


                                                           7
Strings in Switch
 1: int NbrDay(String s, int year) {
 2:   switch(s) {
 3:     case "April": case "June":
 4:     case "September": case "November":
 5:       return 30;
 6:
 7:     case "January": case "March": case "May":
 8:     case "July": case "August": case "December":
 9:       return 31;
10:
11:     case "February”:
12:       ...
13:     default:
14:       ...
15: }



                                                       8
Automatic Resource Management
1: try (InputStream in = new FileInputStream(src);
2:      OutputStream out = new FileOutputStream(dest))
3: {
4:   byte[] buf = new byte[8192];
5:   int n;
6:   while (n = in.read(buf)) >= 0)
7:     out.write(buf, 0, n);
8: }



• New java.lang.AutoCloseable interface
• Anything with a void close() method is a candidate


                                                         9
10
Suppressed Exceptions
New Throwable.getSupressed() method
1: java.io.IOException
2:      at Suppress.write(Suppress.java:19)
3:      at Suppress.main(Suppress.java:8)
4:      Suppressed:  java.io.IOException
5:          at Suppress.close(Suppress.java:24)
6:          at Suppress.main(Suppress.java:9)
7:      Suppressed:  java.io.IOException
8:          at  Suppress.close(Suppress.java:24)
9:          at  Suppress.main(Suppress.java:9)




                                                   11
Multi Catch
1:   //...
2:   catch (IOException ex) {
3:         logger.log(ex);
4:         throw ex;
5:   } catch (SQLException ex) {
6:         logger.log(ex);
7:         throw ex;
8:   }


1: //...
2: catch (IOException|SQLException ex) {
3:     logger.log(ex);
4:     throw ex;
5: }

                                           12
Multi Catch
 1:   try {
 2:   !...
 3:   } catch (SpecificException ex) {
 4:     // Do something very specific!
 5:     throw ex;
 6:   } catch (AnException | MyException | ZeException ex) {
 9:   ! // Do something more generic...
10:   ! throw ex;
11:   }




                                                               13
More Precise Rethrow
 1:   // pre Java 7 "imprecise rethrow"
 2:   // must use "throws Exception"
 3:   public static void imprecise() throws Exception {
 4:      try {
 5:   !    ! // Code that may throw either
 6:   !!     // FirstException or SecondException
 7:   ! } catch (Exception e) {
 8:             throw e;
 9:      }
10:   }




                                                          14
More Precise Rethrow
 1:   // Java 7 precise rethrow.
 2:   // No longer "throws Exception"
 3:   public static void precise() throws FirstException, SecondException {
 4:       try {
 5:   !!    // Code that may throw either
 6:   !!    // FirstException or SecondException
 7:       } catch (Exception e) {
 8:           throw e;
 9:       }
10:   }




                                                                              15
Diamond <>
Map<Ville,List<Client>> map = new HashMap<Ville,List<Client>>();
Map<Ville,List<Client>> map = new HashMap<>();

Map<Dep,Map<Ville,List<Client>>> map = new
     HashMap<Dep,Map<Ville,List<Client>>>();
Map<Dep,Map<Ville,List<Client>>> map = new HashMap<>();

Map<Pays,Map<Dep,Map<Ville,List<Client>>>> map = new
     HashMap<Pays,Map<Dep,Map<Ville,List<Client>>>>();
Map<Pays,Map<Dep,Map<Ville,List<Client>>>> map = new HashMap<>();




                                                                    16
NIO.2
 IO



        17
File Navigation Helpers
Key navigation Helper Types:
 • Class java.nio.file.Files
  - Static methods to operate on files, directories and other types of files
 • Class java.nio.file.Paths
  - Static methods to return a Path by converting a string or URI
 • Interface java.nio.file.Path
  - Used for objects that represent the location of a file in a file system

Typical use case:
 •   Use Paths to get a Path
 •   Use Files to do stuff


                                                                             18
File Navigation Helpers
 1:   Path   p1   =   Paths.get("/tmp/foo");
 2:   Path   p2   =   Paths.get(URI.create("file:///Users/joe/FileTest.java"));
 3:   Path   p3   =   Paths.get(System.getProperty("user.home"),"logs", "foo.log");
 4:   Path   p4   =   Paths.get("/home/joe/foo");
 5:   Path   p5   =   ("c:datatest.dta");
 6:   Path   p6   =   Paths.get("Test.java").toAbsolutePath();
 7:
 8:   Path   fileName = listing.geFileName();
 9:   Path   parent = p2.getParent();
10:   Path   root = p2.getRoot();
11:   Path   subRep = p2.subPath(0,2);
12:
11:   File file = aPathPath.toFile(); // ‘legacy’ java.io.File



                                                                                      19
Files
java.nio.file.Files class
 • Static methods to operate on files, directories and other types of files
  - Read/Write, Copy, & Delete
  - Create Files, Directories & Links
  - Use of system “temp” directory
  - Attributes – Modified/Owner/Permissions/Size
  - Determining the file content type
  - Determining the file type (ex. isExecutable, isSymLink)
  - etc.
   1: Files.move(src, dst, StandardCopyOption.ATOMIC_MOVE);
   2: Files.copy(src, dst,
   3: !! StandardCopyOption.COPY_ATTRIBUTES,
   4: !! StandardCopyOption.REPLACE_EXISTING);
   5: String type = Files.probeContentType(path);
                                                                            20
Files Helper Class
DirectoryStream iterate over entries
  • Scales to large directories
  • Uses less resources
  • Smooth out response time for remote file systems
  • Implements Iterable and Closeable for productivity
Filtering support
  • Build-in support for glob, regex and custom filters Class

1:   Path srcPath = Paths.get(“/home/regis/src”);
2:
3:   try (DirectoryStream<Path> dir =
4:   ! ! srcPath.newDirectoryStream(“*.java”)) {
5:   ! for (Path file : dir)
6:   ! ! System.out.println(file.getName());
7:   }
                                                               21
Symbolic Links
Path and Files are “link aware”

 1:   Path newLink = Paths.get(...);
 2:   Path existingFile = Paths.get(...);
 3:   try {
 4:       Files.createLink(newLink, existingFile);
 5:   } catch (IOException x) {
 6:       System.err.println(x);
 7:   } catch (UnsupportedOperationException x) {
 8:       ! //Some file systems or some configurations
 9:   !! ! //may not support links
10:       System.err.println(x);
11:   }




                                                         22
Walking A File Tree
• FileVisitor interface makes walking a file tree for search, or performing
  actions, trivial.
• SimpleFileVisitor implements
     preVisitDirectory(T dir, BasicFileAttributes attrs);
     visitFile(T dir, BasicFileAttributes attrs);
     visitFileFailed(T dir, IOException exc);
     postVisitDirectory(T dir, IOException exc);




                                                                             23
Walking A File Tree
public static class PrintFiles extends SimpleFileVisitor<Path> {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attr) {
    if (attr.attr.isRegularFile()) {
         System.out.format("Regular file: %s ", file);
    } else if {
         System.out.format("Not a regular file: %s ", file);
    }
    return CONTINUE;
}
}

Path startingDir = ...;
PrintFiles pf = new PrintFiles();
Files.walkFileTree(startingDir, pf);
                                                                          24
Watching a Directory
• Create a WatchService “watcher” for the filesystem
• Register a directory with the watcher
• “Watcher” can be polled or waited on for events
 - Events raised in the form of Keys
 - Retrieve the Key from the Watcher
 - Key has filename and events within it for create/delete/modify
• Ability to detect event overflows




                                                                   25
Custom FileSystems
• FileSystems class is factory to FileSystem (interface)
• Java 7 allows for developing custom FileSystems:
 - Memory based based file systems
 - Fault tolerant distributed file systems
 - Replacing or supplementing the default file system provider
 - etc.
• Two steps:
 - Implement java.nio.file.spi.FileSystemProvider 
  - URI, Caching, File Handling, etc.
 - Implement java.nio.file.FileSystem
  - Roots, RW access, file store, etc.
                                                                26
zip FileSystem Provider
 Fully-functional and supported NIO.2 filesystem provider for zip and jar files

 1:   Map<String, String> env = new HashMap<>();
 2:   !env.put("create", "true");
 3:   !// locate file system by using the syntax
 4:   !// defined in java.net.JarURLConnection
 5:   !URI u= URI.create("jar:file:/foo/zipfs/zipfstest.zip");
 6:   !try (FileSystem z = FileSystems.newFileSystem(u, env)) {
 7:   !! Path externalFile = Paths.get("/foo/sample.txt");
 8:   !! Path pathInZipfile = z.getPath("/sample.txt");
 9:   !// copy a file into the zip file
10:   !externalTxtFile.copyTo(pathInZipfile);
11:   }
12:   ...


                                                                                27
URLClassLoader.close()
 1:   // create a class loader loading from "foo.jar"
 2:   URL url = new URL("file:foo.jar");
 3:   URLClassLoader loader = new URLClassLoader (new URL[] {url});
 4:   Class cl = Class.forName ("Foo", true, loader);
 5:   Runnable foo = (Runnable) cl.newInstance();
 6:   foo.run();
 7:   loader.close();
 8:
 9:   // foo.jar gets updated somehow
10:   loader = new URLClassLoader (new URL[] {url});
11:   cl = Class.forName ("Foo", true, loader);
12:   foo = (Runnable) cl.newInstance();
13:
14:   // run the new implementation of Foo
15:   foo.run();

                                                                      28
SDP & SCTP
• Infiniband
 - High throughput, low latency streamed connections
 - Remote Direct Memory Access
 - Solaris & Linux




                                                       29
Concurrency
  JSR166y



              30
Divide and Conquer


if (my portion of the work is small enough)
     do the work directly
else
     split my work into two pieces
     invoke the two pieces




                                              31
Fork Join Framework - Pools
ForkJoinPool - Service for running ForkJoinTasks
 • aFjp.execute(aTask); // async
 • aFjp.invoke(aTask); // wait
 • aFjp.submit(aTask); // async + future

 • ForkJoinPool(); // default to platform
 • ForkJoinPool(int n); // # concurrent threads
 • ForJoinPool(n,aThreadFactory,exHandler,FIFOtasks); //
   Create your own thread handler, exception handler, and
   boolean on task ordering (default LIFO)



                                                            32
Fork Join Framework - Tasks
ForkJoinTask - The abstract base class for:
 • RecursiveAction
  - A recursive resultless task
  - Implements compute() abstract method
 • RecursiveTask
  - Similar to RecursiveAction but returns a result
1: ForkJoinPool p = new ForkJoinPool();
2:     MyTask mt = new MyTask(n); // implements compute
3:     p.submit(mt);
4: while (!mt.isDone()) {/*THUMPER!*/ }
5: System.out.println(mt.get());



                                                          33
Fork Join Framework - Compute()
• RecursiveAction - ex. increment an entire array
  1: protected void compute() {
  2:     if (hi - lo < THRESHOLD) {
  3:        for (int i = lo; i < hi; ++i) array[i]++; }
  4:     else {
  5:        int mid = (lo + hi) >>> 1;
  6:        invokeAll(new IncrementTask(array, lo, mid),
  7:                  new IncrementTask(array, mid, hi));}
• RecursiveTask - ex. Fibonacci numbers
  1: protected Integer compute() {
  2:      if (n <= 1) return n;
  3:      Fibonacci f1 = new Fibonacci(n - 1);
  4:      Fibonacci f2 = new Fibonacci(n - 2);
  5:      f1.fork(); f2.fork();
  6:      return f2.join() + f1.join();}
                                                             34
TransferQueue
• TransferQueue interface
• Extension to BlockingQueue
• Implemented by LinkedTransferQueue
• Additional Benefits:
 - Adds methods:
    transfer(E e), tryTransfer(E e),
    tryTransfer(E e, long timeout),
    hasWaitingConsumer(), getWaitingConsumerCount()
 - Allows for smarter queues to be built – sidestep the data structure if it’s
    known there are consumers waiting.


                                                                                 35
ConcurrentLinkedDeque
• Unbound concurrent deque based on linked nodes
 - Like a Queue, but allows front and rear removal of elements
• Concurrent insert, remove and access on multiple threads
• Iterators are weakly consistent




                                                                 36
Concurrent Random Numbers
• Existing RNG becomes unwitting source of contention between threads in
    concurrent apps
•   Expected more needs of concurrent RNG with advent of Fork Join Framework


Class java.util.ThreadLocalRandom
    ThreadLocalRandom.current().nextDouble(…)
    ThreadLocalRandom.current().nextInt (…)
    ThreadLocalRandom.current().nextLong(…)



                                                                               37
Phasers
• Barrier similar to CountDownLatch and CyclicBarrier
• Used for many threads to wait at common barrier point
• How is Phaser an improvement?
 - Dynamic add/remove “parties” to be sync’d
 - Better deadlock avoidance
 - Arrival “counting” and phase advance options, etc
 - Termination api’s
 - Tiering (tree structure)
  - Rather than sync 100 threads, sync 2x50 then 2x.


                                                          38
ClassLoader – Deadlock Avoidance
• Acyclic class loader delegation model
 • Custom classLoaders were prone to deadlock
• Java 7 new locking mechanism to avoid deadlock
• Java 7 “parallel capable” classloader




                                                   39
Client



         40
Standardize Nimbus Look and Feel
•   Better than Metal for cross platform look-and-feel
•   Introduced in Java SE 6u10, now part of Swing
•   Not the default L&F
•   Scalable Java 2D impl




                                                         41
JLayer



1:   // wrap your component with JLayer
2:   JLayer<JPanel> layer = new JLayer<JPanel>(panel);
3:   // custom ui provides all extra functionality
4:   layer.setUI(myLayerUI);
5:   // add the layer as usual component
6:   frame.add(layer);




                                                         42
Mixing of AWT and Swing                                   (*)




 (*) As   of 6u12 and 7u1, some caveats for scroll bars


                                                                43
Translucent Windows
     • Private API added in 6u10, made public in Java 7
     • Support (based on platform) for:
      - Uniform Translucency
      - Per Pixel Translucency
      - Per Pixel Transparency
1:   // simple uniform:
2:   aWindow.setOpacity(0.5f);
3:
4: // Per pixel g2d is the g2d of a Jpanel on paintComponent(g)
5: Paint p = new GradientPaint(0.0f, 0.0f, new Color(R, G, B,0), 0.0f,
          6: getHeight(), new Color(R, G, B, 255), true);
7: g2d.setPaint(p);
8: g2d.fillRect(0, 0, getWidth(), getHeight());


                                                                         44
Xrender-based Java 2D
• Improved Graphics Performance, modern X11
• Off by default (backward compatibility)
• Quiet:
 " -Dsun.java2d.xrender=true

• Verbose (log on stdout if successful or not)
 	

   -Dsun.java2d.xrender=true




                                                 45
OpenType/CFF Fonts
• Java Platform must support TrueType fonts, other font technologies is
    implementation dependent
•   Java 7 adds support for “Compact Font Format” - OpenType/CFF




                                                                          46
Better Support for Linux Fonts
• Five logical fonts since Java 1.0:
 - Serif, Sans-serif, Monospaced, Dialog, and DialogInput
 - Must map to physical font on your system
• No consistency in fonts in Linux
• Required editing fontconfig.properties
• Java 7 on Linux (and Solaris 11) uses system “libfontconfig”




                                                                47
HSV/HSL on JColorChooser




                           48
Other Client Stuff
• Shaped windows
• Handling multiple files selection in the FileDialog class
• Mouse
 - java.awt.Toolkit.areExtraMouseButtonsEnabled()
 - java.awt.event.MouseWheelEvent.getPreciseWheelRotation()
• java.awt.PrintJob dialogbox
• ...




                                                              49
Deployment



             50
Embedding JNLP File in Applet Tag
• Saves a network round trip first time applet is loaded
• Base64 Encode the JNLP contents into a Javascript call
<script src="http://www.java.com/js/deployJava.js"></script>
<script>
  var attributes = {} ;
       <!-- Base64 encoded string trunc’d below for readability -->
       var parameters =
          {jnlp_href: 'dynamictree-applet.jnlp',
          jnlp_embedded: 'PCEtLSAKLyoKICogQ29weX ... HA+Cg==' } ;
          deployJava.runApplet(attributes, parameters, '1.7');
</script>




                                                                      51
Ability to detect applet init status on load
 1:   <script>
 2:   function registerAppletStateHandler() {
 3:   !switch (drawApplet.status) {
 4:   !case 1: <!–- applet is loading -->        1:   function onLoadHandler(){
 5:   !! drawApplet.onLoad = onLoadHandler;      2:   ! document.getElementById("mydiv“)
 6:   !case 2: <!–- applet is loaded -->         3:   ! .innerHTML = "Applet loaded";
 7:   !case 3: <!–- error -->                    4:   ! draw();
 8:   !! document.getElementById("mydiv")        5:   }
 9:   !! ! .innerHTML =“No need to onload";
10:   !}
11:   }

           1:   <!–- assume java.com/js/deployJava.js is loaded ->
           2:   var parameters = {java_status_events: 'true'};
           3:   <!–- set other params like jnlp->
           4:   deployJava.runApplet(attributes, parameters, '1.7');
           5:   ...
           6:   </script>
                                                                                           52
Draggable Applet Decoration
• Applet decoration settings apply equally to in browser and out of browser
  launches – borderless, etc.




                                                                              53
Other JNLP New Stuff
• Partially signed JNLP
 - Simplifies build and deployment in some scenarios
 - External JNLP file may differ from one embedded in jar
• Targeting resources to particular version of OS
     <resources os="Windows Vista Windows 7">
     <jar href=“legacySound.jar"/> </resources>
• Better “install” preferences of an application
 - For example, attribute to determine if app appears on “Add or Remove
    Programs panel”




                                                                          54
VM



     55
Updates to Experimental GC – G1
• “Garbage First” intended to replace(*) Concurrent Mark-Sweep (CMS) in
  Hotspot at some future release
• G1 is included for experimentation in Java 7
• Key benefits:
 - More predictably “soft real-time” – temporal configuration
 - High throughput
• Basics:
 - Heap partitioned into equal-sized heap regions
 - Compacts as it proceeds – looks for regions with no live objects for
   immediate reclamation

 (*) not an official forward looking statement



                                                                          56
Tiered Compilation
• Hotspot has 2 JIT’s “client” and “server”
 - Client starts fast, but let optimizations – best for clients
 - Server starts slower, but provides better optimizations
• Java 7 adds Tiered Compiliation
 - JIT the code first with “client”, and if it’s really hot code, recompile with “server”
 - Has been around for a while, but not with a great implementation
 -server -XX:+TieredCompilation

• Image from Rémi Forax showing the DaCapo Jython benchmark.
 http://www.java.net/blogs/forax


                                                                                           57
Compressed OOPS by default

• From 32bit to 64bit system grow the heap by ~1.5x due to bigger
  ordinary object pointers
• Memory is cheap, bandwidth and cache is not!
• Compressed OOPS:
 - Managed 32 bit pointers (similar heap sizes for 32/64 bit apps)
 - Scaled (8 x 4GB chunks) added to a 64 bit base
• Useful for heaps up to 32GB
 - Turned off when –Xmx > 32g



                                                                     58
Support for Dynamically Typed Languages
 • JSR 292: Supporting Dynamically Typed Languages on the Java Platform
  - invokedynamic
 • Method Handle
  - Ability to call a method
  - Implement a subclass of java.lang.invoke.MethodHandle
  - Typesafe!




                                                                          59
I10N & L8N



             60
Unicode 4                         Unicode 6
• Unicode standard was originally 16 bit
• 16 bits not sufficient for Unicode 6, but backward compatibility needs to be
    maintained
•   Use String “U+hex” to express char in Unicode
•   Unicode 6.0 adds thousands of new characters
•   Support for properties and data files (mostly interesting to Japanese Telcos and
    Indic scripts)
•   Full Unicode 6.0 REGEX support!




                                                                                      61
Extensible Currency Codes
• ISO 4217 Defines Currency Codes
• Possible to supersede default currencies with <JAVA_HOME>/lib/
  currency.properties file
• Allows for supporting global changes without updating Java
• Format: ISO 3166 Country code = ISO 4217 Codes

 # Sample currency property if Canada adopts USD
 # CA=CAD,124,2 is default ISO 4217 code
 CA=USD,840,2




                                                                   62
Number Shaper Enhancements
• NumericShaper used to map numbers to non Latin char sets (since 1.4)
• NumericShaper traditionally used an int bitmask for defaults
 - Fine when there were only 19 defaults
 - In Java 7 there are 34 (> 32 bits!!)
• Java 7 now has an Enum NumericShaper.Range
• Backward compatibility maintained, new API’s added for Enum use where
  desired




                                                                          63
Locale – Categories
• Default Locale can be set independently for format resources (dates,
   numbers, currencies) and display resources (menus and dialogs)

• Ex. Application for Japanese audience who deal with US financial transactions:
   //Enum Locale.Category – DISPLAY and FORMAT
   //Default no arg get/set is DISPLAY
   Locale.setDefault(DISPLAY, Locale.JAPAN);
   Locale.setDefault(FORMAT, Locale.US);




                                                                                  64
Locale – BCP47 extensions
Java 7 confirms to IETF BCP 47 (refs UTS #35)
   • Specify extensions to a Locale (get/set)
   • i.e., de-DE-co-phonebk
   • No guarantee the underlying platform can honor extension
         Key          Description      Example          Example Description
          ca   calendar algorithm     ca-buddhist   Thai Buddhist calendar
          co   collation type         co-pinyin     Pinyin ordering for Latin
          k*   collation parameters   kf-upper      Donald before donald
          cu   currency type          cu-usd        U.S. dollars
          nu   number type            nu-jpanfin     Japanese financial numerals
          tz   timezone               tz-aldav      Europe/Andorra
          va   common variant type    va-posix      POSIX style locale variant


                                                                                 65
Miscellaneous



                66
JDBC 4.1
• Try-with-resources statement to automatically close resources of
  type Connection, ResultSet, and Statement
  try (Statement stmt = con.createStatement()) { //... }

• RowSet 1.1 introduces RowSetFactory and RowSetProvider
 //Factory options (impl) set on cmd line or metainf
 myRowSetFactory = RowSetProvider.newFactory();
 myRs = myRowSetFactory.createJdbcRowSet();
 myRs.setUrl("jdbc:myDriver:myAttribute"); //etc
 myRs.setCommand("select COF_NAME, SUP_ID, PRICE, SALES from COFFEES");
 myRs.execute();



                                                                          67
Java DB Enhancements
• JDK 7 includes Java DB 10.8.1.2
• New Since JDK 6
 - BOOLEAN data type
 - Table truncation
 - Query plan browsing
  - Automatic calc of index stats
 - Unicode database names
 - Improved interrupt handling
  - Can now interrupt connection threads
 - MAX optimization (faster!)
 - XML operator portability

                                           68
Security
• Native Elliptic Curve Cryptography provider (ECDSA/ECDH)
 - ECC offers equivalent security with smaller key sizes, faster computations
   and lower power consumption.
• Transport Layer Security Updates
 - TLS 1.1 (RFC 4346) & TLS 1.2 (RFC 5246 ) support
 - TLS Renegotiation
 - CertPath and TLS algorithm disabling
• etc.



                                                                                69
Java XML Technology Enhancements

• JAXP 1.4.5
 - Bug fixes and performance improvements
• JAX-WS 2.2.4
 - Bug fixes and performance improvements
• JAXB 2.2.3
 - Bug fixes and performance improvements



                                           70
JavaDoc Improvements
• Section 508 accessibility guidelines
 - Captions, headings, etc.
• Previously, JavaDoc wrote to an OutputStream on the fly meaning it built
  the document sequentially, imposing limitations
• Now uses internal “HTMLTree” classes
 - Generates compliant HTML
 - Allows for more advancements in the future
• Removes limitation of only being able to execute only once in any VM
 - Was fine when used as a command line tool
 - Continuous build, etc, made it necessary to address this!


                                                                            71
CSS for JavaDoc




                  72
73
1 of 73

Recommended

Dynamic Proxy by Java by
Dynamic Proxy by JavaDynamic Proxy by Java
Dynamic Proxy by JavaKan-Han (John) Lu
761 views14 slides
Understanding Java Dynamic Proxies by
Understanding Java Dynamic ProxiesUnderstanding Java Dynamic Proxies
Understanding Java Dynamic ProxiesRafael Luque Leiva
1.2K views29 slides
Introduction to the Java bytecode - So@t - 20130924 by
Introduction to the Java bytecode - So@t - 20130924Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924yohanbeschi
2.7K views130 slides
Java Deserialization Vulnerabilities - The Forgotten Bug Class by
Java Deserialization Vulnerabilities - The Forgotten Bug ClassJava Deserialization Vulnerabilities - The Forgotten Bug Class
Java Deserialization Vulnerabilities - The Forgotten Bug ClassCODE WHITE GmbH
18.2K views62 slides
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIs by
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIsCS6270 Virtual Machines - Java Virtual Machine Architecture and APIs
CS6270 Virtual Machines - Java Virtual Machine Architecture and APIsKwangshin Oh
2.7K views29 slides
Fixing the Java Serialization Mess by
Fixing the Java Serialization Mess Fixing the Java Serialization Mess
Fixing the Java Serialization Mess Salesforce Engineering
961 views46 slides

More Related Content

What's hot

Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition) by
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)CODE WHITE GmbH
10.4K views57 slides
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016 by
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016Christian Schneider
1.6K views41 slides
Understanding ClassLoaders by
Understanding ClassLoadersUnderstanding ClassLoaders
Understanding ClassLoadersMartin Skurla
344 views33 slides
Java class loader by
Java class loaderJava class loader
Java class loaderbenewu
1.9K views41 slides
Great cup of java by
Great  cup of javaGreat  cup of java
Great cup of javaCIB Egypt
999 views35 slides
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ... by
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...Christopher Frohoff
26.5K views100 slides

What's hot(20)

Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition) by CODE WHITE GmbH
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (DeepSec Edition)
CODE WHITE GmbH10.4K views
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016 by Christian Schneider
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Serial Killer - Silently Pwning your Java Endpoints // OWASP BeNeLux Day 2016
Christian Schneider1.6K views
Understanding ClassLoaders by Martin Skurla
Understanding ClassLoadersUnderstanding ClassLoaders
Understanding ClassLoaders
Martin Skurla344 views
Java class loader by benewu
Java class loaderJava class loader
Java class loader
benewu1.9K views
Great cup of java by CIB Egypt
Great  cup of javaGreat  cup of java
Great cup of java
CIB Egypt999 views
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ... by Christopher Frohoff
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
Christopher Frohoff26.5K views
Ahead-Of-Time Compilation of Java Applications by Nikita Lipsky
Ahead-Of-Time Compilation of Java ApplicationsAhead-Of-Time Compilation of Java Applications
Ahead-Of-Time Compilation of Java Applications
Nikita Lipsky3.6K views
testing ppt by techweb08
testing ppttesting ppt
testing ppt
techweb08263 views
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition) by CODE WHITE GmbH
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
CODE WHITE GmbH7.8K views
Let's talk about java class loader by Yongqiang Li
Let's talk about java class loaderLet's talk about java class loader
Let's talk about java class loader
Yongqiang Li1.4K views
Objective c runtime by Inferis
Objective c runtimeObjective c runtime
Objective c runtime
Inferis5.6K views
Resting on your laurels will get you powned by Dinis Cruz
Resting on your laurels will get you pownedResting on your laurels will get you powned
Resting on your laurels will get you powned
Dinis Cruz4.9K views
Java class loading tips and tricks - Java Colombo Meetup, January, 2014 by Sameera Jayasoma
Java class loading  tips and tricks - Java Colombo Meetup, January, 2014Java class loading  tips and tricks - Java Colombo Meetup, January, 2014
Java class loading tips and tricks - Java Colombo Meetup, January, 2014
Sameera Jayasoma6.1K views
No locked doors, no windows barred: hacking OpenAM infrastructure by Andrew Petukhov
No locked doors, no windows barred: hacking OpenAM infrastructureNo locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructure
Andrew Petukhov17.9K views
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J... by joaomatosf_
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
An Overview of Deserialization Vulnerabilities in the Java Virtual Machine (J...
joaomatosf_10.2K views
JIT vs. AOT: Unity And Conflict of Dynamic and Static Compilers by Nikita Lipsky
JIT vs. AOT: Unity And Conflict of Dynamic and Static Compilers JIT vs. AOT: Unity And Conflict of Dynamic and Static Compilers
JIT vs. AOT: Unity And Conflict of Dynamic and Static Compilers
Nikita Lipsky4.8K views
Java Classloaders by Prateek Jain
Java ClassloadersJava Classloaders
Java Classloaders
Prateek Jain1.3K views

Similar to 55 new things in Java 7 - Devoxx France

55 New Features in Java 7 by
55 New Features in Java 755 New Features in Java 7
55 New Features in Java 7Boulder Java User's Group
70.9K views63 slides
55j7 by
55j755j7
55j7swein2
2.7K views58 slides
Java by
JavaJava
Java박 경민
155 views44 slides
Back to the future with Java 7 (Geekout June/2011) by
Back to the future with Java 7 (Geekout June/2011)Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)Martijn Verburg
1.2K views47 slides
What`s new in Java 7 by
What`s new in Java 7What`s new in Java 7
What`s new in Java 7Georgian Micsa
1.4K views27 slides
Atlassian Groovy Plugins by
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy PluginsPaul King
2.3K views27 slides

Similar to 55 new things in Java 7 - Devoxx France(20)

55j7 by swein2
55j755j7
55j7
swein22.7K views
Back to the future with Java 7 (Geekout June/2011) by Martijn Verburg
Back to the future with Java 7 (Geekout June/2011)Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)
Martijn Verburg1.2K views
Atlassian Groovy Plugins by Paul King
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy Plugins
Paul King2.3K views
Practical JavaScript Programming - Session 8/8 by Wilson Su
Practical JavaScript Programming - Session 8/8Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8
Wilson Su409 views
Introduction to clojure by Abbas Raza
Introduction to clojureIntroduction to clojure
Introduction to clojure
Abbas Raza1.4K views
DevNexus 2020: Discover Modern Java by Henri Tremblay
DevNexus 2020: Discover Modern JavaDevNexus 2020: Discover Modern Java
DevNexus 2020: Discover Modern Java
Henri Tremblay95 views
Spock: Test Well and Prosper by Ken Kousen
Spock: Test Well and ProsperSpock: Test Well and Prosper
Spock: Test Well and Prosper
Ken Kousen4.3K views
Java 7 Whats New(), Whats Next() from Oredev by Mattias Karlsson
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
Mattias Karlsson2.2K views
Don't Be Afraid of Abstract Syntax Trees by Jamund Ferguson
Don't Be Afraid of Abstract Syntax TreesDon't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax Trees
Jamund Ferguson3.3K views
Getting started with Clojure by John Stevenson
Getting started with ClojureGetting started with Clojure
Getting started with Clojure
John Stevenson1.7K views
React Native Evening by Troy Miles
React Native EveningReact Native Evening
React Native Evening
Troy Miles542 views
5. Ввод-вывод, доступ к файловой системе by DEVTYPE
5. Ввод-вывод, доступ к файловой системе5. Ввод-вывод, доступ к файловой системе
5. Ввод-вывод, доступ к файловой системе
DEVTYPE967 views

More from David Delabassee

JVMs in Containers - Best Practices by
JVMs in Containers - Best PracticesJVMs in Containers - Best Practices
JVMs in Containers - Best PracticesDavid Delabassee
726 views37 slides
JVMs in Containers by
JVMs in ContainersJVMs in Containers
JVMs in ContainersDavid Delabassee
1.3K views38 slides
Serverless Java Challenges & Triumphs by
Serverless Java Challenges & TriumphsServerless Java Challenges & Triumphs
Serverless Java Challenges & TriumphsDavid Delabassee
1.2K views46 slides
Serverless Java - Challenges and Triumphs by
Serverless Java - Challenges and TriumphsServerless Java - Challenges and Triumphs
Serverless Java - Challenges and TriumphsDavid Delabassee
282 views41 slides
Randstad Docker meetup - Serverless by
Randstad Docker meetup - ServerlessRandstad Docker meetup - Serverless
Randstad Docker meetup - ServerlessDavid Delabassee
322 views37 slides
Java Serverless in Action - Voxxed Banff by
Java Serverless in Action - Voxxed BanffJava Serverless in Action - Voxxed Banff
Java Serverless in Action - Voxxed BanffDavid Delabassee
232 views22 slides

More from David Delabassee(20)

Serverless Java Challenges & Triumphs by David Delabassee
Serverless Java Challenges & TriumphsServerless Java Challenges & Triumphs
Serverless Java Challenges & Triumphs
David Delabassee1.2K views
Serverless Java - Challenges and Triumphs by David Delabassee
Serverless Java - Challenges and TriumphsServerless Java - Challenges and Triumphs
Serverless Java - Challenges and Triumphs
David Delabassee282 views
Java Serverless in Action - Voxxed Banff by David Delabassee
Java Serverless in Action - Voxxed BanffJava Serverless in Action - Voxxed Banff
Java Serverless in Action - Voxxed Banff
David Delabassee232 views
Java EE Next - BeJUG JavaOne Afterglow 2016 by David Delabassee
Java EE Next - BeJUG JavaOne Afterglow 2016Java EE Next - BeJUG JavaOne Afterglow 2016
Java EE Next - BeJUG JavaOne Afterglow 2016
David Delabassee433 views
HTTP/2 comes to Java (Dec. 2015 version) by David Delabassee
HTTP/2 comes to Java (Dec. 2015 version)HTTP/2 comes to Java (Dec. 2015 version)
HTTP/2 comes to Java (Dec. 2015 version)
David Delabassee690 views
EJB and CDI - Alignment and Strategy by David Delabassee
EJB and CDI - Alignment and StrategyEJB and CDI - Alignment and Strategy
EJB and CDI - Alignment and Strategy
David Delabassee31.9K views
Java EE 8 - What’s new on the Web front by David Delabassee
Java EE 8 - What’s new on the Web frontJava EE 8 - What’s new on the Web front
Java EE 8 - What’s new on the Web front
David Delabassee960 views

Recently uploaded

Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveNetwork Automation Forum
46 views35 slides
Why and How CloudStack at weSystems - Stephan Bienek - weSystems by
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsWhy and How CloudStack at weSystems - Stephan Bienek - weSystems
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsShapeBlue
111 views13 slides
Five Things You SHOULD Know About Postman by
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About PostmanPostman
40 views43 slides
The Research Portal of Catalonia: Growing more (information) & more (services) by
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)CSUC - Consorci de Serveis Universitaris de Catalunya
136 views25 slides
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue by
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueShapeBlue
96 views7 slides
Business Analyst Series 2023 - Week 4 Session 7 by
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7DianaGray10
80 views31 slides

Recently uploaded(20)

Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Why and How CloudStack at weSystems - Stephan Bienek - weSystems by ShapeBlue
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsWhy and How CloudStack at weSystems - Stephan Bienek - weSystems
Why and How CloudStack at weSystems - Stephan Bienek - weSystems
ShapeBlue111 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman40 views
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue by ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
ShapeBlue96 views
Business Analyst Series 2023 - Week 4 Session 7 by DianaGray10
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7
DianaGray1080 views
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT by ShapeBlue
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITUpdates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
ShapeBlue91 views
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
State of the Union - Rohit Yadav - Apache CloudStack by ShapeBlue
State of the Union - Rohit Yadav - Apache CloudStackState of the Union - Rohit Yadav - Apache CloudStack
State of the Union - Rohit Yadav - Apache CloudStack
ShapeBlue145 views
HTTP headers that make your website go faster - devs.gent November 2023 by Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn28 views
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue50 views
DRBD Deep Dive - Philipp Reisner - LINBIT by ShapeBlue
DRBD Deep Dive - Philipp Reisner - LINBITDRBD Deep Dive - Philipp Reisner - LINBIT
DRBD Deep Dive - Philipp Reisner - LINBIT
ShapeBlue62 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson133 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker50 views
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ... by ShapeBlue
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
ShapeBlue65 views
Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates by ShapeBlue
Keynote Talk: Open Source is Not Dead - Charles Schulz - VatesKeynote Talk: Open Source is Not Dead - Charles Schulz - Vates
Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates
ShapeBlue119 views
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ... by ShapeBlue
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
ShapeBlue77 views

55 new things in Java 7 - Devoxx France

  • 1. (+) 55 fonctionnalités de Java 7 dont vous n'avez (probablement) pas encore entendu parler par David Delabassée @delabassee 1
  • 2. About me... • David Delabassée - ... Sun, Oracle - Devoxx (Belgium) Steering • @delabassee 2
  • 3. The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 3
  • 4. Java 7 • InvokeDynamic • Fork/Join • NIO.2 • Project Coin • ... 4
  • 6. Binary Literals 1: int mask = 0b101010101010; 2: aShort = (short)0b1010000101000101; 3: long aLong = 0b1010000101000101101000010100010110100001010001011010000101000101L; 1: HAPPY_FACE = { 2: (short)0b0000011111100000; 3: (short)0b0000100000010000; 4: (short)0b0001000000001000; 5: (short)0b0010000000000100; 6: (short)0b0100000000000010; 7: (short)0b1000011001100001; 8: (short)0b1000011001100001; 9: (short)0b1000000000000001; 10: (short)0b1000000000000001; 11: (short)0b1001000000001001; 12: (short)0b1000100000010001; 13: (short)0b0100011111100010; 14: (short)0b0010000000000100; 15: (short)0b0001000000001000; 16: (short)0b0000100000010000; 17: (short)0b0000011111100000; } 6
  • 7. Underscores in Numeric Literals • Valid int mask = 0b1010_1010_1010; long big = 9_223_783_036_967_937L; long creditCardNumber = 1234_5678_9012_3456L; long socialSecurityNumber = 999_99_9999L; float pi = ! 3.14_15F; long hexBytes = 0xFF_EC_DE_5E; long hexWords = 0xCAFE_BFFE; • Invalid float pi1 = 3_.1415F; float pi2 = 3._1415F; long ssn = 999_99_9999_L; int x1 = _52; int x1 = 52_; int x2 = 0_x52; int x2 = 0x_52; 7
  • 8. Strings in Switch 1: int NbrDay(String s, int year) { 2: switch(s) { 3: case "April": case "June": 4: case "September": case "November": 5: return 30; 6: 7: case "January": case "March": case "May": 8: case "July": case "August": case "December": 9: return 31; 10: 11: case "February”: 12: ... 13: default: 14: ... 15: } 8
  • 9. Automatic Resource Management 1: try (InputStream in = new FileInputStream(src); 2: OutputStream out = new FileOutputStream(dest)) 3: { 4: byte[] buf = new byte[8192]; 5: int n; 6: while (n = in.read(buf)) >= 0) 7: out.write(buf, 0, n); 8: } • New java.lang.AutoCloseable interface • Anything with a void close() method is a candidate 9
  • 10. 10
  • 11. Suppressed Exceptions New Throwable.getSupressed() method 1: java.io.IOException 2: at Suppress.write(Suppress.java:19) 3: at Suppress.main(Suppress.java:8) 4: Suppressed:  java.io.IOException 5: at Suppress.close(Suppress.java:24) 6: at Suppress.main(Suppress.java:9) 7: Suppressed:  java.io.IOException 8: at  Suppress.close(Suppress.java:24) 9: at  Suppress.main(Suppress.java:9) 11
  • 12. Multi Catch 1: //... 2: catch (IOException ex) { 3: logger.log(ex); 4: throw ex; 5: } catch (SQLException ex) { 6: logger.log(ex); 7: throw ex; 8: } 1: //... 2: catch (IOException|SQLException ex) { 3: logger.log(ex); 4: throw ex; 5: } 12
  • 13. Multi Catch 1: try { 2: !... 3: } catch (SpecificException ex) { 4: // Do something very specific! 5: throw ex; 6: } catch (AnException | MyException | ZeException ex) { 9: ! // Do something more generic... 10: ! throw ex; 11: } 13
  • 14. More Precise Rethrow 1: // pre Java 7 "imprecise rethrow" 2: // must use "throws Exception" 3: public static void imprecise() throws Exception { 4: try { 5: ! ! // Code that may throw either 6: !! // FirstException or SecondException 7: ! } catch (Exception e) { 8: throw e; 9: } 10: } 14
  • 15. More Precise Rethrow 1: // Java 7 precise rethrow. 2: // No longer "throws Exception" 3: public static void precise() throws FirstException, SecondException { 4: try { 5: !! // Code that may throw either 6: !! // FirstException or SecondException 7: } catch (Exception e) { 8: throw e; 9: } 10: } 15
  • 16. Diamond <> Map<Ville,List<Client>> map = new HashMap<Ville,List<Client>>(); Map<Ville,List<Client>> map = new HashMap<>(); Map<Dep,Map<Ville,List<Client>>> map = new HashMap<Dep,Map<Ville,List<Client>>>(); Map<Dep,Map<Ville,List<Client>>> map = new HashMap<>(); Map<Pays,Map<Dep,Map<Ville,List<Client>>>> map = new HashMap<Pays,Map<Dep,Map<Ville,List<Client>>>>(); Map<Pays,Map<Dep,Map<Ville,List<Client>>>> map = new HashMap<>(); 16
  • 17. NIO.2 IO 17
  • 18. File Navigation Helpers Key navigation Helper Types: • Class java.nio.file.Files - Static methods to operate on files, directories and other types of files • Class java.nio.file.Paths - Static methods to return a Path by converting a string or URI • Interface java.nio.file.Path - Used for objects that represent the location of a file in a file system Typical use case: • Use Paths to get a Path • Use Files to do stuff 18
  • 19. File Navigation Helpers 1: Path p1 = Paths.get("/tmp/foo"); 2: Path p2 = Paths.get(URI.create("file:///Users/joe/FileTest.java")); 3: Path p3 = Paths.get(System.getProperty("user.home"),"logs", "foo.log"); 4: Path p4 = Paths.get("/home/joe/foo"); 5: Path p5 = ("c:datatest.dta"); 6: Path p6 = Paths.get("Test.java").toAbsolutePath(); 7: 8: Path fileName = listing.geFileName(); 9: Path parent = p2.getParent(); 10: Path root = p2.getRoot(); 11: Path subRep = p2.subPath(0,2); 12: 11: File file = aPathPath.toFile(); // ‘legacy’ java.io.File 19
  • 20. Files java.nio.file.Files class • Static methods to operate on files, directories and other types of files - Read/Write, Copy, & Delete - Create Files, Directories & Links - Use of system “temp” directory - Attributes – Modified/Owner/Permissions/Size - Determining the file content type - Determining the file type (ex. isExecutable, isSymLink) - etc. 1: Files.move(src, dst, StandardCopyOption.ATOMIC_MOVE); 2: Files.copy(src, dst, 3: !! StandardCopyOption.COPY_ATTRIBUTES, 4: !! StandardCopyOption.REPLACE_EXISTING); 5: String type = Files.probeContentType(path); 20
  • 21. Files Helper Class DirectoryStream iterate over entries • Scales to large directories • Uses less resources • Smooth out response time for remote file systems • Implements Iterable and Closeable for productivity Filtering support • Build-in support for glob, regex and custom filters Class 1: Path srcPath = Paths.get(“/home/regis/src”); 2: 3: try (DirectoryStream<Path> dir = 4: ! ! srcPath.newDirectoryStream(“*.java”)) { 5: ! for (Path file : dir) 6: ! ! System.out.println(file.getName()); 7: } 21
  • 22. Symbolic Links Path and Files are “link aware” 1: Path newLink = Paths.get(...); 2: Path existingFile = Paths.get(...); 3: try { 4: Files.createLink(newLink, existingFile); 5: } catch (IOException x) { 6: System.err.println(x); 7: } catch (UnsupportedOperationException x) { 8: ! //Some file systems or some configurations 9: !! ! //may not support links 10: System.err.println(x); 11: } 22
  • 23. Walking A File Tree • FileVisitor interface makes walking a file tree for search, or performing actions, trivial. • SimpleFileVisitor implements preVisitDirectory(T dir, BasicFileAttributes attrs); visitFile(T dir, BasicFileAttributes attrs); visitFileFailed(T dir, IOException exc); postVisitDirectory(T dir, IOException exc); 23
  • 24. Walking A File Tree public static class PrintFiles extends SimpleFileVisitor<Path> { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attr) { if (attr.attr.isRegularFile()) { System.out.format("Regular file: %s ", file); } else if { System.out.format("Not a regular file: %s ", file); } return CONTINUE; } } Path startingDir = ...; PrintFiles pf = new PrintFiles(); Files.walkFileTree(startingDir, pf); 24
  • 25. Watching a Directory • Create a WatchService “watcher” for the filesystem • Register a directory with the watcher • “Watcher” can be polled or waited on for events - Events raised in the form of Keys - Retrieve the Key from the Watcher - Key has filename and events within it for create/delete/modify • Ability to detect event overflows 25
  • 26. Custom FileSystems • FileSystems class is factory to FileSystem (interface) • Java 7 allows for developing custom FileSystems: - Memory based based file systems - Fault tolerant distributed file systems - Replacing or supplementing the default file system provider - etc. • Two steps: - Implement java.nio.file.spi.FileSystemProvider  - URI, Caching, File Handling, etc. - Implement java.nio.file.FileSystem - Roots, RW access, file store, etc. 26
  • 27. zip FileSystem Provider Fully-functional and supported NIO.2 filesystem provider for zip and jar files 1: Map<String, String> env = new HashMap<>(); 2: !env.put("create", "true"); 3: !// locate file system by using the syntax 4: !// defined in java.net.JarURLConnection 5: !URI u= URI.create("jar:file:/foo/zipfs/zipfstest.zip"); 6: !try (FileSystem z = FileSystems.newFileSystem(u, env)) { 7: !! Path externalFile = Paths.get("/foo/sample.txt"); 8: !! Path pathInZipfile = z.getPath("/sample.txt"); 9: !// copy a file into the zip file 10: !externalTxtFile.copyTo(pathInZipfile); 11: } 12: ... 27
  • 28. URLClassLoader.close() 1: // create a class loader loading from "foo.jar" 2: URL url = new URL("file:foo.jar"); 3: URLClassLoader loader = new URLClassLoader (new URL[] {url}); 4: Class cl = Class.forName ("Foo", true, loader); 5: Runnable foo = (Runnable) cl.newInstance(); 6: foo.run(); 7: loader.close(); 8: 9: // foo.jar gets updated somehow 10: loader = new URLClassLoader (new URL[] {url}); 11: cl = Class.forName ("Foo", true, loader); 12: foo = (Runnable) cl.newInstance(); 13: 14: // run the new implementation of Foo 15: foo.run(); 28
  • 29. SDP & SCTP • Infiniband - High throughput, low latency streamed connections - Remote Direct Memory Access - Solaris & Linux 29
  • 31. Divide and Conquer if (my portion of the work is small enough) do the work directly else split my work into two pieces invoke the two pieces 31
  • 32. Fork Join Framework - Pools ForkJoinPool - Service for running ForkJoinTasks • aFjp.execute(aTask); // async • aFjp.invoke(aTask); // wait • aFjp.submit(aTask); // async + future • ForkJoinPool(); // default to platform • ForkJoinPool(int n); // # concurrent threads • ForJoinPool(n,aThreadFactory,exHandler,FIFOtasks); // Create your own thread handler, exception handler, and boolean on task ordering (default LIFO) 32
  • 33. Fork Join Framework - Tasks ForkJoinTask - The abstract base class for: • RecursiveAction - A recursive resultless task - Implements compute() abstract method • RecursiveTask - Similar to RecursiveAction but returns a result 1: ForkJoinPool p = new ForkJoinPool(); 2: MyTask mt = new MyTask(n); // implements compute 3: p.submit(mt); 4: while (!mt.isDone()) {/*THUMPER!*/ } 5: System.out.println(mt.get()); 33
  • 34. Fork Join Framework - Compute() • RecursiveAction - ex. increment an entire array 1: protected void compute() { 2: if (hi - lo < THRESHOLD) { 3: for (int i = lo; i < hi; ++i) array[i]++; } 4: else { 5: int mid = (lo + hi) >>> 1; 6: invokeAll(new IncrementTask(array, lo, mid), 7: new IncrementTask(array, mid, hi));} • RecursiveTask - ex. Fibonacci numbers 1: protected Integer compute() { 2: if (n <= 1) return n; 3: Fibonacci f1 = new Fibonacci(n - 1); 4: Fibonacci f2 = new Fibonacci(n - 2); 5: f1.fork(); f2.fork(); 6: return f2.join() + f1.join();} 34
  • 35. TransferQueue • TransferQueue interface • Extension to BlockingQueue • Implemented by LinkedTransferQueue • Additional Benefits: - Adds methods: transfer(E e), tryTransfer(E e), tryTransfer(E e, long timeout), hasWaitingConsumer(), getWaitingConsumerCount() - Allows for smarter queues to be built – sidestep the data structure if it’s known there are consumers waiting. 35
  • 36. ConcurrentLinkedDeque • Unbound concurrent deque based on linked nodes - Like a Queue, but allows front and rear removal of elements • Concurrent insert, remove and access on multiple threads • Iterators are weakly consistent 36
  • 37. Concurrent Random Numbers • Existing RNG becomes unwitting source of contention between threads in concurrent apps • Expected more needs of concurrent RNG with advent of Fork Join Framework Class java.util.ThreadLocalRandom ThreadLocalRandom.current().nextDouble(…) ThreadLocalRandom.current().nextInt (…) ThreadLocalRandom.current().nextLong(…) 37
  • 38. Phasers • Barrier similar to CountDownLatch and CyclicBarrier • Used for many threads to wait at common barrier point • How is Phaser an improvement? - Dynamic add/remove “parties” to be sync’d - Better deadlock avoidance - Arrival “counting” and phase advance options, etc - Termination api’s - Tiering (tree structure) - Rather than sync 100 threads, sync 2x50 then 2x. 38
  • 39. ClassLoader – Deadlock Avoidance • Acyclic class loader delegation model • Custom classLoaders were prone to deadlock • Java 7 new locking mechanism to avoid deadlock • Java 7 “parallel capable” classloader 39
  • 40. Client 40
  • 41. Standardize Nimbus Look and Feel • Better than Metal for cross platform look-and-feel • Introduced in Java SE 6u10, now part of Swing • Not the default L&F • Scalable Java 2D impl 41
  • 42. JLayer 1: // wrap your component with JLayer 2: JLayer<JPanel> layer = new JLayer<JPanel>(panel); 3: // custom ui provides all extra functionality 4: layer.setUI(myLayerUI); 5: // add the layer as usual component 6: frame.add(layer); 42
  • 43. Mixing of AWT and Swing (*) (*) As of 6u12 and 7u1, some caveats for scroll bars 43
  • 44. Translucent Windows • Private API added in 6u10, made public in Java 7 • Support (based on platform) for: - Uniform Translucency - Per Pixel Translucency - Per Pixel Transparency 1: // simple uniform: 2: aWindow.setOpacity(0.5f); 3: 4: // Per pixel g2d is the g2d of a Jpanel on paintComponent(g) 5: Paint p = new GradientPaint(0.0f, 0.0f, new Color(R, G, B,0), 0.0f, 6: getHeight(), new Color(R, G, B, 255), true); 7: g2d.setPaint(p); 8: g2d.fillRect(0, 0, getWidth(), getHeight()); 44
  • 45. Xrender-based Java 2D • Improved Graphics Performance, modern X11 • Off by default (backward compatibility) • Quiet: " -Dsun.java2d.xrender=true • Verbose (log on stdout if successful or not) -Dsun.java2d.xrender=true 45
  • 46. OpenType/CFF Fonts • Java Platform must support TrueType fonts, other font technologies is implementation dependent • Java 7 adds support for “Compact Font Format” - OpenType/CFF 46
  • 47. Better Support for Linux Fonts • Five logical fonts since Java 1.0: - Serif, Sans-serif, Monospaced, Dialog, and DialogInput - Must map to physical font on your system • No consistency in fonts in Linux • Required editing fontconfig.properties • Java 7 on Linux (and Solaris 11) uses system “libfontconfig” 47
  • 49. Other Client Stuff • Shaped windows • Handling multiple files selection in the FileDialog class • Mouse - java.awt.Toolkit.areExtraMouseButtonsEnabled() - java.awt.event.MouseWheelEvent.getPreciseWheelRotation() • java.awt.PrintJob dialogbox • ... 49
  • 51. Embedding JNLP File in Applet Tag • Saves a network round trip first time applet is loaded • Base64 Encode the JNLP contents into a Javascript call <script src="http://www.java.com/js/deployJava.js"></script> <script> var attributes = {} ; <!-- Base64 encoded string trunc’d below for readability --> var parameters = {jnlp_href: 'dynamictree-applet.jnlp', jnlp_embedded: 'PCEtLSAKLyoKICogQ29weX ... HA+Cg==' } ; deployJava.runApplet(attributes, parameters, '1.7'); </script> 51
  • 52. Ability to detect applet init status on load 1: <script> 2: function registerAppletStateHandler() { 3: !switch (drawApplet.status) { 4: !case 1: <!–- applet is loading --> 1: function onLoadHandler(){ 5: !! drawApplet.onLoad = onLoadHandler; 2: ! document.getElementById("mydiv“) 6: !case 2: <!–- applet is loaded --> 3: ! .innerHTML = "Applet loaded"; 7: !case 3: <!–- error --> 4: ! draw(); 8: !! document.getElementById("mydiv") 5: } 9: !! ! .innerHTML =“No need to onload"; 10: !} 11: } 1: <!–- assume java.com/js/deployJava.js is loaded -> 2: var parameters = {java_status_events: 'true'}; 3: <!–- set other params like jnlp-> 4: deployJava.runApplet(attributes, parameters, '1.7'); 5: ... 6: </script> 52
  • 53. Draggable Applet Decoration • Applet decoration settings apply equally to in browser and out of browser launches – borderless, etc. 53
  • 54. Other JNLP New Stuff • Partially signed JNLP - Simplifies build and deployment in some scenarios - External JNLP file may differ from one embedded in jar • Targeting resources to particular version of OS <resources os="Windows Vista Windows 7"> <jar href=“legacySound.jar"/> </resources> • Better “install” preferences of an application - For example, attribute to determine if app appears on “Add or Remove Programs panel” 54
  • 55. VM 55
  • 56. Updates to Experimental GC – G1 • “Garbage First” intended to replace(*) Concurrent Mark-Sweep (CMS) in Hotspot at some future release • G1 is included for experimentation in Java 7 • Key benefits: - More predictably “soft real-time” – temporal configuration - High throughput • Basics: - Heap partitioned into equal-sized heap regions - Compacts as it proceeds – looks for regions with no live objects for immediate reclamation (*) not an official forward looking statement 56
  • 57. Tiered Compilation • Hotspot has 2 JIT’s “client” and “server” - Client starts fast, but let optimizations – best for clients - Server starts slower, but provides better optimizations • Java 7 adds Tiered Compiliation - JIT the code first with “client”, and if it’s really hot code, recompile with “server” - Has been around for a while, but not with a great implementation -server -XX:+TieredCompilation • Image from Rémi Forax showing the DaCapo Jython benchmark. http://www.java.net/blogs/forax 57
  • 58. Compressed OOPS by default • From 32bit to 64bit system grow the heap by ~1.5x due to bigger ordinary object pointers • Memory is cheap, bandwidth and cache is not! • Compressed OOPS: - Managed 32 bit pointers (similar heap sizes for 32/64 bit apps) - Scaled (8 x 4GB chunks) added to a 64 bit base • Useful for heaps up to 32GB - Turned off when –Xmx > 32g 58
  • 59. Support for Dynamically Typed Languages • JSR 292: Supporting Dynamically Typed Languages on the Java Platform - invokedynamic • Method Handle - Ability to call a method - Implement a subclass of java.lang.invoke.MethodHandle - Typesafe! 59
  • 61. Unicode 4 Unicode 6 • Unicode standard was originally 16 bit • 16 bits not sufficient for Unicode 6, but backward compatibility needs to be maintained • Use String “U+hex” to express char in Unicode • Unicode 6.0 adds thousands of new characters • Support for properties and data files (mostly interesting to Japanese Telcos and Indic scripts) • Full Unicode 6.0 REGEX support! 61
  • 62. Extensible Currency Codes • ISO 4217 Defines Currency Codes • Possible to supersede default currencies with <JAVA_HOME>/lib/ currency.properties file • Allows for supporting global changes without updating Java • Format: ISO 3166 Country code = ISO 4217 Codes # Sample currency property if Canada adopts USD # CA=CAD,124,2 is default ISO 4217 code CA=USD,840,2 62
  • 63. Number Shaper Enhancements • NumericShaper used to map numbers to non Latin char sets (since 1.4) • NumericShaper traditionally used an int bitmask for defaults - Fine when there were only 19 defaults - In Java 7 there are 34 (> 32 bits!!) • Java 7 now has an Enum NumericShaper.Range • Backward compatibility maintained, new API’s added for Enum use where desired 63
  • 64. Locale – Categories • Default Locale can be set independently for format resources (dates, numbers, currencies) and display resources (menus and dialogs) • Ex. Application for Japanese audience who deal with US financial transactions: //Enum Locale.Category – DISPLAY and FORMAT //Default no arg get/set is DISPLAY Locale.setDefault(DISPLAY, Locale.JAPAN); Locale.setDefault(FORMAT, Locale.US); 64
  • 65. Locale – BCP47 extensions Java 7 confirms to IETF BCP 47 (refs UTS #35) • Specify extensions to a Locale (get/set) • i.e., de-DE-co-phonebk • No guarantee the underlying platform can honor extension Key Description Example Example Description ca calendar algorithm ca-buddhist Thai Buddhist calendar co collation type co-pinyin Pinyin ordering for Latin k* collation parameters kf-upper Donald before donald cu currency type cu-usd U.S. dollars nu number type nu-jpanfin Japanese financial numerals tz timezone tz-aldav Europe/Andorra va common variant type va-posix POSIX style locale variant 65
  • 67. JDBC 4.1 • Try-with-resources statement to automatically close resources of type Connection, ResultSet, and Statement try (Statement stmt = con.createStatement()) { //... } • RowSet 1.1 introduces RowSetFactory and RowSetProvider //Factory options (impl) set on cmd line or metainf myRowSetFactory = RowSetProvider.newFactory(); myRs = myRowSetFactory.createJdbcRowSet(); myRs.setUrl("jdbc:myDriver:myAttribute"); //etc myRs.setCommand("select COF_NAME, SUP_ID, PRICE, SALES from COFFEES"); myRs.execute(); 67
  • 68. Java DB Enhancements • JDK 7 includes Java DB 10.8.1.2 • New Since JDK 6 - BOOLEAN data type - Table truncation - Query plan browsing - Automatic calc of index stats - Unicode database names - Improved interrupt handling - Can now interrupt connection threads - MAX optimization (faster!) - XML operator portability 68
  • 69. Security • Native Elliptic Curve Cryptography provider (ECDSA/ECDH) - ECC offers equivalent security with smaller key sizes, faster computations and lower power consumption. • Transport Layer Security Updates - TLS 1.1 (RFC 4346) & TLS 1.2 (RFC 5246 ) support - TLS Renegotiation - CertPath and TLS algorithm disabling • etc. 69
  • 70. Java XML Technology Enhancements • JAXP 1.4.5 - Bug fixes and performance improvements • JAX-WS 2.2.4 - Bug fixes and performance improvements • JAXB 2.2.3 - Bug fixes and performance improvements 70
  • 71. JavaDoc Improvements • Section 508 accessibility guidelines - Captions, headings, etc. • Previously, JavaDoc wrote to an OutputStream on the fly meaning it built the document sequentially, imposing limitations • Now uses internal “HTMLTree” classes - Generates compliant HTML - Allows for more advancements in the future • Removes limitation of only being able to execute only once in any VM - Was fine when used as a command line tool - Continuous build, etc, made it necessary to address this! 71
  • 73. 73