What The Future Holds For
Java: JDK7 and JavaFX
Simon Ritter
Technology Evangelist
Disclaimer



 The information in this presentation
 concerns forward-looking statements
 based on current expectations and beliefs
 about future events that are inherently
 susceptible to uncertainty and changes in
 circumstance etc. etc. etc.

                                             2
JDK 7 Features
> Language
 • Annotations on Java types
 • Small language changes (Project Coin)
 • Modularity (JSR-294)
> Core
 •   Modularisation (Project Jigsaw)
 •   Concurrency and collections updates
 •   More new IO APIs (NIO.2)
 •   Additional network protocol support
 •   Eliptic curve cryptography
 •   Unicode 5.1

                                           3
JDK 7 Features
> VM
 • Compressed 64-bit pointers
 • Garbage-First GC
 • Support for dynamic languages (Da Vinci Machine
   project)
> Client
 • Swing Application Framework (JSR-296)
 • Forward port Java SE6 u10 features
 • XRender pipeline for Java 2D




                                                     4
Modularity
 Project Jigsaw



                  5
Size Matters
> JDK is big, really big
  • JDK 1.x – 7 top level packages, 200 classes
  • JDK 7 – too many top level packages, over 4000 classes
  • About 12MB today
> Historical baggage
  • Build as a monolithic software system
> Problems
  • Download time, startup time, memory footprint, performance
  • Difficult to fit platform to newer mobile device
     -   CPU capable, but constrained by memory
> Current solution – use JDK 6u10
  • Kernel installer, quick startup feature
  • More like a painkiller, not the antidote

                                                                 6
New Module System for Java
> JSR-294 Improved Modularity Support in the Java
  Programming Language
> Requirements for JSR-294
  •   Integrate with the VM
  •   Integrate with the language
  •   Integrate with (platform's) native packaging
  •   Support multi-module packages
  •   Support “friend” modules
> Open JDK's Project Jigsaw
  • Reference implementation for JSR-294
  • openjdk.java.net/projects/jigsaw
  • Can have other type of module systems based on OSGi,
      IPS, Debian, etc.

                                                           7
Modularizing You Code
planetjdk/src/
            org/planetjdk/aggregator/Main.java




                       Modularize


planetjdk/src/
            org/planetjdk/aggregator/Main.java
            module-info.java


                                                 8
module-info.java                       Module name

 module org.planetjdk.aggregator {
                                       Module system
     system jigsaw;
     requires module jdom;
     requires module tagsoup;
     requires module rome;
     requires module rome-fetcher;       Dependencies
     requires module joda-time;
     requires module java-xml;
     requires module java-base;
     class org.planetjdk.aggregator.Main;
 }
                                            Main class
                                                         9
Compiling Modules
javac -modulepath planetjdk/src:rssutils/rome
     org.planetjdk.aggregator/module-info.java
     org.planetjdk.aggregator/org/...
     com.sun.syndication/module-info.java
     com.sun.syndication/com/...


 > Infers classes in org.planetjdk.aggregator/* belongs to
   module org.planetjdk.aggregator
   • From module-info.java
 > Handles mutual dependency
   • Module A dependent on Module B which is dependent on
     Module A
                                                             10
Running Modules

java -modulepath planetjdk/cls:rssutils/rome
  -m org.planetjdk.aggregator




> Launcher will look for org.planetjdk.aggregator from
  modulepath and executes it
  • Assuming that module is a root module




                                                         11
Module Versioning
 module org.planetjdk.aggregator @ 1.0 {
   system jigsaw;
   requires module jdom @ 1.*;
   requires module tagsoup @ 1.2.*;
   requires module rome @ =1.0;
   requires module rome-fetcher @ =1.0;
   requires module joda-time @ [1.6,2.0);
   requires module java-xml @ 7.*;
   requires module java-base @ 7.*;
   class org.planetjdk.aggregator.Main;
 }

                                            12
Native Packaging
  > Java does not integrate well with native OS
    • JAR files have no well defined relationship to native OS
      packaging
  > Build native packaging from module information
  > New tool – jpkg
javac -modulepath planetjdk/src:rssutils/rome
  -d build/modules org.planetjdk.aggregator/module-info.java
  org.planetjdk.aggregator/org/...


jpkg -L planetjdk/cls:rssutils/rome -m build/modules
   deb -c aggregator


sudo dpkg -i org.planetjdk.aggregator_1.0_all.deb
/usr/bin/aggregator
                                                                 13
Small
(Language)
 Changes
  Project Coin

                 14
“Why don't you add X to Java?”
>Assumption is that adding features is always good
>Application
  •   Application competes on the basis of completeness
  •   User cannot do X until application supports it
  •   Features rarely interacts “intimately” with each other
  •   Conclusion: more features are better
>Language
  •   Languages (most) are Turing complete
  •   Can always do X; question is how elegantly
  •   Features often interact with each other
  •   Conclusion: fewer, more regular features are better



                                                               15
Adding X To Java
> Must be compatible with existing code
  • assert and enum keywords breaks old code
> Must respect Java's abstract model
   • Should we allowing padding/aligning object sizes?
> Must leave room for future expansion
   • Syntax/semantics of new feature should not conflict with
     syntax/semantics of existing and/or potential features
   • Allow consistent evolution




                                                                16
Changing Java Is Really Hard Work
> Update the JSL
> Implement it in the compiler
> Add essential library support
> Write test
> Update the VM specs
> Update the VM and class file tools
> Update JNI
> Update reflection APIs
> Update serialization support
> Update javadoc output

                                       17
Better Integer Literals
> Binary literals
 int mask = 0b1010;

> With underscores
 int bigMask = 0b1010_0101;
 long big = 9_223_783_036_967_937L;


> Unsigned literals
 byte b = 0xffu;



                                      18
Better Type Inference


 Map<String, Integer> foo =
     new HashMap<String, Integer>();

 Map<String, Integer> foo =
     new HashMap<>();




                                       19
Strings in Switch
> Strings are constants too
       String s = ...;
       switch (s) {
         case "foo":
            return 1;

           case "bar":
             Return 2;

           default:
             return 0;
       }
                              20
Resource Management
> Manually closing resources is tricky and tedious
   public void copy(String src, String dest) throws IOException {
      InputStream in = new FileInputStream(src);
      try {
          OutputStream out = new FileOutputStream(dest);
          try {
             byte[] buf = new byte[8 * 1024];
             int n;
             while ((n = in.read(buf)) >= 0)
                 out.write(buf, 0, n);
          } finally {
             out.close();
          }
      } finally {
          in.close();
   }}

                                                                    21
Automatic Resource Management

static void copy(String src, String dest) throws IOException {
    try (InputStream in = new FileInputStream(src);
         OutputStream out = new FileOutputStream(dest)) {
        byte[] buf = new byte[8192];
        int n;
        while ((n = in.read(buf)) >= 0)
            out.write(buf, 0, n);
    }
   //in and out closes
}




                                                             22
Index Syntax for Lists and Maps


 List<String> list =
   Arrays.asList(new String[] {"a", "b", "c"});
 String firstElement = list[0];

 Map<Integer, String> map = new HashMap<>();
 map[Integer.valueOf(1)] = "One";




                                                  23
Dynamic
 Languages
  Support
Da Vinci Machine Proejct

                           24
Virtual Machines
> A software implementation of a specific computer
  architecture
  • Could be a real hardware (NES) or fictitious (z-machine)
> Popular in current deployments
  • VirtualBox, VMWare, VirtualPC, Parallels, etc
> “Every problem in computer science can be solved by
  adding a layer of indirection” – Butler Lampson
  • VM is the indirection layer
  • Abstraction from hardware
  • Provides portability




                                                               25
VM Have Mostly Won the Day
> Lots of languages today are targeting VM
  • Writing native compiler is a lot of work
> Why? Language need runtime support
  • Memory management, reflection, security, concurrency
    controls, tools, libraries, etc
> VM based systems provides these
  • Some features are part of the VM
> Lots of VM for lots of different languages
  • JVM, CLR, Dalvik, Smalltalk, Perl, Python, YARV, Rubinius,
    Tamarin, Valgrind (C++!), Lua, Postscript, Flash, p-code,
    Zend, etc



                                                                 26
JVM Specification



“The Java virtual machine knows nothing about
the Java programming language, only of a
particular binary format, the class file format.”
                             1.2 The Java Virtual Machine




                                                            27
JVM Architecture
> Stack based
  • Push operand on to the stack
  • Instructions operates by popping data off the stack
  • Pushes result back on the stack
> Data types
  • Eight primitive types, objects and arrays
> Object model – single inheritance with interfaces
> Method resolution
  • Receiver and method name
  • Statically typed for parameters and return types
  • Dynamic linking + static type checking
     -   Verified at runtime


                                                          28
Languages on the Java Virtual Machine
                                                                                     Tea               iScript
 Zigzag                                              JESS                              Jickle
                      Modula-2                                             Lisp
                                        Nice
                                                              CAL                                 JavaScript
          Correlate                                                                  JudoScript
                              Simkin                     Drools
                                                                      Basic
 Icon        Groovy                       Eiffel                                                         Luck
                                                              v-language                     Pascal
                              Prolog              Mini
                      Tcl                                               PLAN               Hojo          Scala
Rexx                        JavaFX Script                                         Funnel
                                                                                                      FScript
             Tiger          Anvil                                     Yassl                       Oberon
    E                                 Smalltalk
             Logo
                              Tiger
                                                                      JHCR                 JRuby
  Ada                            G                                  Scheme                               Sather
                                                  Clojure
 Processing                             Dawn                                      Phobos              Sleep
                            WebL                                  TermWare
                                               LLP                                     Pnuts          Bex Script
             BeanShell                           Forth            PHP
                                        C#                           SALSA
                                                  Yoix                             ObjectScript
                        Jython                                    Piccola                                          29


                                                                                                                        29
Pain Points for Dynamic Languages
> Method invocation
  • Including linking and selection
> New view points on Java types
  • List versus LIST
> Boxed values
  • Integer versus fixnum
> Special control structures
  • Tailcall, generators, continuations, etc
> What is the one change in the JVM that would make
  life better for dynamic languages?
  • Flexible method calls!



                                                      30
Method Invocation Today
String s = “Hello World”;
System.out.println(s);
   1: ldc #2        // Push String, s, onto stack
   2: astore_1      // Pop string and store in local
   3: getstatic #3 // Get static field
               java/lang/System.out:Ljava/io/PrintStream
   4: aload_1       // Load string ref from local var
   5: invokevirtual #4; //Method java/io/PrintStream.println:
                         //(Ljava/lang/String;)V
> Receiver type must conform to the resolved type of
  the call site
> Call methods must always exist
> Symbolic name is the name of an actual method
> Four 'invoke' bytecode
   • invokevirtual, invokeinterface, invokestatic, invokespecial
                                                                   31
Bootstrapping Method Handle




                              32
invokedynamic Byte Code
0: aload_1
1: aload_2
2: invokedynamic #3 //Name and type only lessThan:
              //(Ljava/lang/Object;Ljava/lang/Object;)Z
5: if_icmpeq

                                        Call site reifies the call




>



    pink thing = CallSite object
    green thing = MethodHandle object
                                                                     33
What Will Not Be in JDK7
> Closures
> Small Language changes that were proposed
  • Improved exception handling (safe rethrow, multi-catch)
  • Elvis and other null-safe operators
  • Large arrays
> Other language features
  • Reified generic types
  • First class properties
  • Operator overloading
> JSR-295 Beans binding
> JSR-277 Java Module System


                                                              34
JavaFX
> Develop Rich Internet Applications using Java
> JavaFX scripting language
  • Leverages Java platform: JVM, Class libraries
  • Simple integration of existing Java code
> Powerful language features
  • Binding
  • Effects
  • Animations




                                                    35
Added in JavaFX 1.1
> Official support for JavaFX Mobile
  • Mobile Emulator
> Language Improvements
  • Addition of Java primitive types (float, double, long, int, short, byte, char)
  • Improved Language Reference Guide
> Performance and Stability Improvements
  • Desktop Runtime updated to improve performance and stability
> Additional Improvements
  • Better support for mobile/desktop apps using the same code-base
  • Improved “cross domain” access
  • Standard navigation method for cross-device content



                                                                                     36
JavaFX 1.2: Released at JavaOne 2009
> UI Control components
  • Button, CheckBox, etc
> UI Chart components
  • LineChart, BubbleChart, BarChart, etc
> Solaris and Linux supported!!!!
  • GStreamer media support
> RealTime Streaming Protocol (RTSP) support
> Production suite now supports Adobe CS4




                                               37
Summary
> Lots of new things coming
  • Some not covered here
  • Includes annotations for Java type, Swing application
    framework, JXLayer, date picker, etc.
> Java on the client is alive and well
> JavaFX becoming mature
> Platform will be more robust and scalable
> Coming soon in 2010




                                                            38
JDK7: What The Future
        Holds For Java

     Simon Ritter
     Technology Evangelist
      simon.ritter@sun.com




39
                             39

Java Future S Ritter

  • 1.
    What The FutureHolds For Java: JDK7 and JavaFX Simon Ritter Technology Evangelist
  • 2.
    Disclaimer The informationin this presentation concerns forward-looking statements based on current expectations and beliefs about future events that are inherently susceptible to uncertainty and changes in circumstance etc. etc. etc. 2
  • 3.
    JDK 7 Features >Language • Annotations on Java types • Small language changes (Project Coin) • Modularity (JSR-294) > Core • Modularisation (Project Jigsaw) • Concurrency and collections updates • More new IO APIs (NIO.2) • Additional network protocol support • Eliptic curve cryptography • Unicode 5.1 3
  • 4.
    JDK 7 Features >VM • Compressed 64-bit pointers • Garbage-First GC • Support for dynamic languages (Da Vinci Machine project) > Client • Swing Application Framework (JSR-296) • Forward port Java SE6 u10 features • XRender pipeline for Java 2D 4
  • 5.
  • 6.
    Size Matters > JDKis big, really big • JDK 1.x – 7 top level packages, 200 classes • JDK 7 – too many top level packages, over 4000 classes • About 12MB today > Historical baggage • Build as a monolithic software system > Problems • Download time, startup time, memory footprint, performance • Difficult to fit platform to newer mobile device - CPU capable, but constrained by memory > Current solution – use JDK 6u10 • Kernel installer, quick startup feature • More like a painkiller, not the antidote 6
  • 7.
    New Module Systemfor Java > JSR-294 Improved Modularity Support in the Java Programming Language > Requirements for JSR-294 • Integrate with the VM • Integrate with the language • Integrate with (platform's) native packaging • Support multi-module packages • Support “friend” modules > Open JDK's Project Jigsaw • Reference implementation for JSR-294 • openjdk.java.net/projects/jigsaw • Can have other type of module systems based on OSGi, IPS, Debian, etc. 7
  • 8.
    Modularizing You Code planetjdk/src/ org/planetjdk/aggregator/Main.java Modularize planetjdk/src/ org/planetjdk/aggregator/Main.java module-info.java 8
  • 9.
    module-info.java Module name module org.planetjdk.aggregator { Module system system jigsaw; requires module jdom; requires module tagsoup; requires module rome; requires module rome-fetcher; Dependencies requires module joda-time; requires module java-xml; requires module java-base; class org.planetjdk.aggregator.Main; } Main class 9
  • 10.
    Compiling Modules javac -modulepathplanetjdk/src:rssutils/rome org.planetjdk.aggregator/module-info.java org.planetjdk.aggregator/org/... com.sun.syndication/module-info.java com.sun.syndication/com/... > Infers classes in org.planetjdk.aggregator/* belongs to module org.planetjdk.aggregator • From module-info.java > Handles mutual dependency • Module A dependent on Module B which is dependent on Module A 10
  • 11.
    Running Modules java -modulepathplanetjdk/cls:rssutils/rome -m org.planetjdk.aggregator > Launcher will look for org.planetjdk.aggregator from modulepath and executes it • Assuming that module is a root module 11
  • 12.
    Module Versioning moduleorg.planetjdk.aggregator @ 1.0 { system jigsaw; requires module jdom @ 1.*; requires module tagsoup @ 1.2.*; requires module rome @ =1.0; requires module rome-fetcher @ =1.0; requires module joda-time @ [1.6,2.0); requires module java-xml @ 7.*; requires module java-base @ 7.*; class org.planetjdk.aggregator.Main; } 12
  • 13.
    Native Packaging > Java does not integrate well with native OS • JAR files have no well defined relationship to native OS packaging > Build native packaging from module information > New tool – jpkg javac -modulepath planetjdk/src:rssutils/rome -d build/modules org.planetjdk.aggregator/module-info.java org.planetjdk.aggregator/org/... jpkg -L planetjdk/cls:rssutils/rome -m build/modules deb -c aggregator sudo dpkg -i org.planetjdk.aggregator_1.0_all.deb /usr/bin/aggregator 13
  • 14.
  • 15.
    “Why don't youadd X to Java?” >Assumption is that adding features is always good >Application • Application competes on the basis of completeness • User cannot do X until application supports it • Features rarely interacts “intimately” with each other • Conclusion: more features are better >Language • Languages (most) are Turing complete • Can always do X; question is how elegantly • Features often interact with each other • Conclusion: fewer, more regular features are better 15
  • 16.
    Adding X ToJava > Must be compatible with existing code • assert and enum keywords breaks old code > Must respect Java's abstract model • Should we allowing padding/aligning object sizes? > Must leave room for future expansion • Syntax/semantics of new feature should not conflict with syntax/semantics of existing and/or potential features • Allow consistent evolution 16
  • 17.
    Changing Java IsReally Hard Work > Update the JSL > Implement it in the compiler > Add essential library support > Write test > Update the VM specs > Update the VM and class file tools > Update JNI > Update reflection APIs > Update serialization support > Update javadoc output 17
  • 18.
    Better Integer Literals >Binary literals int mask = 0b1010; > With underscores int bigMask = 0b1010_0101; long big = 9_223_783_036_967_937L; > Unsigned literals byte b = 0xffu; 18
  • 19.
    Better Type Inference Map<String, Integer> foo = new HashMap<String, Integer>(); Map<String, Integer> foo = new HashMap<>(); 19
  • 20.
    Strings in Switch >Strings are constants too String s = ...; switch (s) { case "foo": return 1; case "bar": Return 2; default: return 0; } 20
  • 21.
    Resource Management > Manuallyclosing resources is tricky and tedious public void copy(String src, String dest) throws IOException { InputStream in = new FileInputStream(src); try { OutputStream out = new FileOutputStream(dest); try { byte[] buf = new byte[8 * 1024]; int n; while ((n = in.read(buf)) >= 0) out.write(buf, 0, n); } finally { out.close(); } } finally { in.close(); }} 21
  • 22.
    Automatic Resource Management staticvoid copy(String src, String dest) throws IOException { try (InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dest)) { byte[] buf = new byte[8192]; int n; while ((n = in.read(buf)) >= 0) out.write(buf, 0, n); } //in and out closes } 22
  • 23.
    Index Syntax forLists and Maps List<String> list = Arrays.asList(new String[] {"a", "b", "c"}); String firstElement = list[0]; Map<Integer, String> map = new HashMap<>(); map[Integer.valueOf(1)] = "One"; 23
  • 24.
    Dynamic Languages Support Da Vinci Machine Proejct 24
  • 25.
    Virtual Machines > Asoftware implementation of a specific computer architecture • Could be a real hardware (NES) or fictitious (z-machine) > Popular in current deployments • VirtualBox, VMWare, VirtualPC, Parallels, etc > “Every problem in computer science can be solved by adding a layer of indirection” – Butler Lampson • VM is the indirection layer • Abstraction from hardware • Provides portability 25
  • 26.
    VM Have MostlyWon the Day > Lots of languages today are targeting VM • Writing native compiler is a lot of work > Why? Language need runtime support • Memory management, reflection, security, concurrency controls, tools, libraries, etc > VM based systems provides these • Some features are part of the VM > Lots of VM for lots of different languages • JVM, CLR, Dalvik, Smalltalk, Perl, Python, YARV, Rubinius, Tamarin, Valgrind (C++!), Lua, Postscript, Flash, p-code, Zend, etc 26
  • 27.
    JVM Specification “The Javavirtual machine knows nothing about the Java programming language, only of a particular binary format, the class file format.” 1.2 The Java Virtual Machine 27
  • 28.
    JVM Architecture > Stackbased • Push operand on to the stack • Instructions operates by popping data off the stack • Pushes result back on the stack > Data types • Eight primitive types, objects and arrays > Object model – single inheritance with interfaces > Method resolution • Receiver and method name • Statically typed for parameters and return types • Dynamic linking + static type checking - Verified at runtime 28
  • 29.
    Languages on theJava Virtual Machine Tea iScript Zigzag JESS Jickle Modula-2 Lisp Nice CAL JavaScript Correlate JudoScript Simkin Drools Basic Icon Groovy Eiffel Luck v-language Pascal Prolog Mini Tcl PLAN Hojo Scala Rexx JavaFX Script Funnel FScript Tiger Anvil Yassl Oberon E Smalltalk Logo Tiger JHCR JRuby Ada G Scheme Sather Clojure Processing Dawn Phobos Sleep WebL TermWare LLP Pnuts Bex Script BeanShell Forth PHP C# SALSA Yoix ObjectScript Jython Piccola 29 29
  • 30.
    Pain Points forDynamic Languages > Method invocation • Including linking and selection > New view points on Java types • List versus LIST > Boxed values • Integer versus fixnum > Special control structures • Tailcall, generators, continuations, etc > What is the one change in the JVM that would make life better for dynamic languages? • Flexible method calls! 30
  • 31.
    Method Invocation Today Strings = “Hello World”; System.out.println(s); 1: ldc #2 // Push String, s, onto stack 2: astore_1 // Pop string and store in local 3: getstatic #3 // Get static field java/lang/System.out:Ljava/io/PrintStream 4: aload_1 // Load string ref from local var 5: invokevirtual #4; //Method java/io/PrintStream.println: //(Ljava/lang/String;)V > Receiver type must conform to the resolved type of the call site > Call methods must always exist > Symbolic name is the name of an actual method > Four 'invoke' bytecode • invokevirtual, invokeinterface, invokestatic, invokespecial 31
  • 32.
  • 33.
    invokedynamic Byte Code 0:aload_1 1: aload_2 2: invokedynamic #3 //Name and type only lessThan: //(Ljava/lang/Object;Ljava/lang/Object;)Z 5: if_icmpeq Call site reifies the call > pink thing = CallSite object green thing = MethodHandle object 33
  • 34.
    What Will NotBe in JDK7 > Closures > Small Language changes that were proposed • Improved exception handling (safe rethrow, multi-catch) • Elvis and other null-safe operators • Large arrays > Other language features • Reified generic types • First class properties • Operator overloading > JSR-295 Beans binding > JSR-277 Java Module System 34
  • 35.
    JavaFX > Develop RichInternet Applications using Java > JavaFX scripting language • Leverages Java platform: JVM, Class libraries • Simple integration of existing Java code > Powerful language features • Binding • Effects • Animations 35
  • 36.
    Added in JavaFX1.1 > Official support for JavaFX Mobile • Mobile Emulator > Language Improvements • Addition of Java primitive types (float, double, long, int, short, byte, char) • Improved Language Reference Guide > Performance and Stability Improvements • Desktop Runtime updated to improve performance and stability > Additional Improvements • Better support for mobile/desktop apps using the same code-base • Improved “cross domain” access • Standard navigation method for cross-device content 36
  • 37.
    JavaFX 1.2: Releasedat JavaOne 2009 > UI Control components • Button, CheckBox, etc > UI Chart components • LineChart, BubbleChart, BarChart, etc > Solaris and Linux supported!!!! • GStreamer media support > RealTime Streaming Protocol (RTSP) support > Production suite now supports Adobe CS4 37
  • 38.
    Summary > Lots ofnew things coming • Some not covered here • Includes annotations for Java type, Swing application framework, JXLayer, date picker, etc. > Java on the client is alive and well > JavaFX becoming mature > Platform will be more robust and scalable > Coming soon in 2010 38
  • 39.
    JDK7: What TheFuture Holds For Java Simon Ritter Technology Evangelist simon.ritter@sun.com 39 39