What is new and cool j2se & java

1,618 views

Published on

Published in: Technology, News & Politics
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,618
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

What is new and cool j2se & java

  1. 1. What is new in Java SE 7 and – Java Enterprise Edition 6 Eugene Bogaart Solution Architect Sun Microsystems 1
  2. 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 2
  3. 3. JDK 7 Features > VM • Compressed 64-bit pointers • Garbage-First GC • Support for dynamic languages (Da Vinci Machine project) > Client • Forward port Java SE6 u10 features • XRender pipeline for Java 2D 3
  4. 4. Modularity Project Jigsaw 4
  5. 5. 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. 5
  6. 6. Modularizing You Code planetjdk/src/ org/planetjdk/aggregator/Main.java Modularize planetjdk/src/ org/planetjdk/aggregator/Main.java module-info.java 6
  7. 7. module-info.java Module name module org.planetjdk.aggregator { Module system system jigsaw; requires module jdom; requires module tagsoup; requires module rome; Dependencies requires module rome-fetcher; requires module joda-time; requires module java-xml; requires module java-base; class org.planetjdk.aggregator.Main; } Main class 7
  8. 8. 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; } 8
  9. 9. Small (Language) Changes Project Coin 9
  10. 10. 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; 10
  11. 11. Better Type Inference Map<String, Integer> foo = new HashMap<String, Integer>(); Map<String, Integer> foo = new HashMap<>(); 11
  12. 12. Strings in Switch • Strings are constants too String s = ...; switch (s) { case "foo": return 1; case "bar": Return 2; default: return 0; } 12
  13. 13. 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(); }} 13
  14. 14. 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 } 14
  15. 15. 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"; 15
  16. 16. Dynamic Languages Support Da Vinci Machine Project 16
  17. 17. 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 17
  18. 18. Languages Running on the JVM Tea iScript Zigzag JESS Jickle Modula-2 Lisp Correlate Nice CAL JudoScript JavaScript Simkin Drools Basic Icon Groovy Eiffel Luck v-language Pascal Prolog Mini Tcl PLAN Hojo Scala Rexx JavaFX Script Funnel Tiger Anvil Yassl FScript Oberon E Smalltalk Logo Tiger JHCR JRuby Ada G Scheme Sather Clojure Phobos Processing WebL Dawn TermWare Sleep LLP Pnuts Bex Script BeanShell Forth PHP C# Yoix SALSA ObjectScript Jython Piccola 18 18
  19. 19. InvokeDynamic Bytecode • JVM currently has four ways to invoke method > Invokevirtual, invokeinterface, invokestatic, invokespecial • All require full method signature data • InvokeDynamic will use method handle > Effectively an indirect pointer to the method • When dynamic method is first called bootstrap code determines method and creates handle • Subsequent calls simply reference defined handle • Type changes force a re-compute of the method location and an update to the handle > Method call changes are invisible to calling code 19
  20. 20. Bootstrapping Method Handle 20
  21. 21. invokedynamic Byte Code Call site reifies the call pink = CallSite object green = MethodHandle object 21
  22. 22. JDK 7 Milestone Timeline • M5 29 Oct 2009 > Concurrency and collections updates (jsr166y) > Elliptic-curve cryptography (ECC) > JSR TBD: Small language enhancements (Project Coin) > Swing updates > Update the XML stack • M6 18 Feb 2010 • M7 15 Apr 2010 • M8 3 Jun 2010 Feature complete • M9 22 Jul 2010 • M10 9 Sep 2010 22
  23. 23. More information • On OpenJDK7 • http://www.javapassion.com/javaee6/ 23
  24. 24. Java EE: Past & Present Rightsizing Ease of Development Java EE 6 Web Services Pruning Java EE 5 Extensibility Robustness Profiles Enterprise Java Ease of Platform J2EE 1.4 Development Ease of Development Annotations J2EE 1.3 Web EJB Lite J2EE 1.2 Services EJB 3.0 RESTful Management CMP Persistence Services Servlet Deployment JPE Connector New and Dependency Project JSP Architecture Async. Updated Ejection EJB Connector Web Services JMS Web Profile RMI/IIOP 24
  25. 25. Java EE 6 Final release December 10, 2009 25
  26. 26. Java EE 5 J2EE 1.4 Java EE 5 • Deployment • Java language descriptors annotations @ • Required container • Plain Old Java Objects interfaces (POJOs) • JNDI Lookups • Dependency Injection • Deployment • More and better defaults descriptor, interfaces • No Supported UI • Java Server Faces(JSF) Framework 26
  27. 27. Java EE 6 GOALS 27
  28. 28. Java EE 6 Platform Goals • Rightsizing > Flexible > Lighter weight • Extensible > Embrace Open Source Frameworks • Productive > Improve on Java EE 5 28
  29. 29. Rightsizing the Platform Platform Flexibility • Decouple specifications to allow more combinations • Expand potiential licensee ecosystem • Profiles > Targeted technology bundles > Web Profile 29
  30. 30. About Profiles • Profiles are targeted bundles of technologies • (Simple) rules set by platform spec • Profiles can be subsets, supersets or overlapping • First profile: the Web Profile • Decoupling of specs to allow more combinations • Future profiles defined in the Java Community Process 30
  31. 31. Rightsizing the Platform Web Profile • Fully functional mid-sized profile • Actively discussed > Expert Group > Industry • Technologies > Servlet 3.0, EJB Lite 3.1, JPA 2.0, JSP 2.2, EL 1.2, JSTL 1.2, JSF 2.0, JTA 1.1, JSR 45, Common Annotations 31
  32. 32. Rightsizing the Platform Pruning (Deprecation) • Some technologies optional > Optional in next release > Deleted in subsequent release > Marked in Javadocs • Pruning list > JAX-RPC > EJB 2.x Entity Beans > JAXR > JSR-85 (Rules based Auth & Audit) 32
  33. 33. About Pruning • Make some technologies optional • Reduce the real and conceptual footprint • Same rules as proposed by the Java SE > “pruned now, optional in the next release” • Pruned technologies will be marked in the javadocs • Current pruning list: > JAX-RPC, EJB Entity Beans, JAXR, JSR-88 33
  34. 34. Rightsizing the Platform Extensibility • Embrace open source libraries and frameworks • Zero-configuration, drag-n- drop web frameworks > Servlets, servlet filters > Framework context listeners are discovered & registered • Plugin library jars using Web Fragments 34
  35. 35. Ease of Development Extensibility • Continue Java EE 5 advancements • Primary focus: Web Tier • Multiple areas easier to use: EJB 3.1 • General Principles > Annotation-based programming model > Reduce or eliminate need for deployment descriptors > Traditional API for advanced users 35
  36. 36. About Extensibility • Embrace open source libraries and frameworks • Zero-configuration, drag-and-drop for web frameworks > Monolithic web.xml can become complex to maintain as the dependencies of the application increases > Servlets, servlet filters, context listeners for a framework get discovered and registered automatically • Completely general solution using web fragments • Scripting languages can use the same mechanism 36
  37. 37. Ease of Development • Ongoing effort • This time focus is the web tier • Lots of opportunities in other areas, e.g. EJB • General principles: > Use of annotations across all web APIs > Reduce or eliminate need for deployment descriptors – No editing of web.xml required > Self-registration of third-party libraries > Simplified packaging > JAX-RS for RESTful web services > Get technologies to work together well 37
  38. 38. Java EE 6 Platform Summary 38
  39. 39. Java EE 6 Platform What's New? • Several new APIs • Web Profile • Pluggability/extensibility • Dependency injection • Many improvements to APIs 39
  40. 40. Java EE 6 Platform New Technologies • JAX-RS 1.1 • Bean Validation 1.0 • Dependency injection 1.0 • CDI 1.0 • Managed Beans 1.0 40
  41. 41. Java EE 6 Platform Updated Technolgies • EJB 3.1 • JAX-WS 2.2 • JPA 2.0 • JSR-109 1.3 • Servlet 3.0 • JSP 2.2 • JSF 2.0 • EL 2.2 • Connectors 1.6 • JSR-250 1.1 • Interceptors 1.1 • JACC 1.4 • JASPIC 1.0 41
  42. 42. Java EE 6 Samples 42
  43. 43. Ease of Development Adding an EJB to a Web Application ShoppingCart BuyBooks.war EJB Class BuyBooks.war ShoppingCart.jar ShoppingCart EJB Class BuyBooks.ear 43
  44. 44. Java EE Platform 5 Packaging 44
  45. 45. Java EE Platform 6 Packaging 45
  46. 46. Session Bean with No - Interface 46
  47. 47. Ease of Development - Annotations Servlet in Java EE 5: Create two source files /* Code in Java Class */ <!--Deployment descriptor web.xml --> package com.foo; <web-app> public class MyServlet extends <servlet> HttpServlet { <servlet-name>MyServlet public void </servlet-name> doGet(HttpServletRequest <servlet-class> req,HttpServletResponse res) com.foo.MyServlet </servlet-class> { </servlet> <servlet-mapping> ... <servlet-name>MyServlet </servlet-name> } <url-pattern>/myApp/* </url-pattern> ... </servlet-mapping> ... } </web-app> 47
  48. 48. Ease of Development - Annotations Servlet in Java EE 5: Java Class /* Code in Java Class */ package com.foo; public class MyServlet extends HttpServlet { public void doGet(HttpServletRequest req,HttpServletResponse res) { /* doGet body */ } } 48
  49. 49. Ease of Development - Annotations Servlet in Java EE 5: Descriptor <!--Deployment descriptor web.xml --> <web-app> <servlet> <servlet-name>MyServlet </servlet-name> <servlet-class> com.foo.MyServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>MyServlet </servlet-name> <url-pattern>/myApp/* </url-pattern> </servlet-mapping> ... </web-app> 49
  50. 50. Ease of Development - Annotations Java EE 6 Servlet: Single Source file (many cases) package com.foo; @WebServlet(name=”MyServlet”, urlPattern=”/myApp/*”) public class MyServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) { ... } 50
  51. 51. Demos Java EE 6 51
  52. 52. Demo Setup Enterprise Java JavaServer Java Beans Persistence JavaDB Faces (Business API (Database) (presentation) Logic) (Data Access) 52
  53. 53. Summary • Java continues to evolve • JDK7 driving changes in the platform • JavaFX providing a RIA platform built on Java • More to come... 53
  54. 54. More information • Tutorial On Java EE 6 • Webinar on Java EE 6 • http://www.javapassion.com/javaee6/ 54
  55. 55. Thanks Eugene Bogaart Eugene.Bogaart@sun.com 55

×