Java 7: Quo vadis?


Published on

This presentations try to make a brief overview of features which can be expected in new version of Java.

Published in: Business, Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Java 7: Quo vadis?

    1. 1. <ul><ul><li>Michal Malohlava </li></ul></ul>Java 7 : Quo vadis? DISTRIBUTED SYSTEMS RESEARCH GROUP CHARLES UNIVERSITY IN PRAGUE Faculty of Mathematics and Physics
    2. 2. <ul><li>Java development process </li></ul><ul><li>Language extension </li></ul><ul><li>Related projects </li></ul><ul><ul><li>Java Module System </li></ul></ul><ul><li>Conclusion </li></ul>Outline
    3. 3. <ul><li>JDK </li></ul><ul><ul><li>Official Sun's Java </li></ul></ul><ul><ul><li>Source code released (GPL v.2) </li></ul></ul><ul><ul><li>18months release interval </li></ul></ul><ul><ul><ul><li>JDK6 fall 2006 => JDK7 spring 2008 (January 2009:) </li></ul></ul></ul><ul><ul><li>Still no official JSR ( Java Specification Request ) </li></ul></ul><ul><ul><ul><li>only many proposals of Java7 features/anti-features </li></ul></ul></ul><ul><li>OpenJDK </li></ul><ul><ul><li>Free implementation of JDK by Java community </li></ul></ul><ul><ul><ul><li>OpenJDK 6 will be based on OpenJDK 7 </li></ul></ul></ul><ul><ul><li>Now only Modules project - JSR 277, JSR 294 </li></ul></ul>Java development process
    4. 4. <ul><li>No official JSR </li></ul><ul><ul><li>Still in discussion </li></ul></ul><ul><li>JUG (Java User Group) </li></ul><ul><ul><li>Unofficial JSR for JDK7 </li></ul></ul><ul><ul><ul><li>Published on 7 th November </li></ul></ul></ul><ul><ul><li>Specify </li></ul></ul><ul><ul><ul><li>Closures </li></ul></ul></ul><ul><ul><ul><li>Generics, enum, switch enhancements </li></ul></ul></ul><ul><ul><ul><li>Chained invocations, extension methods </li></ul></ul></ul><ul><ul><ul><li>Exception catching </li></ul></ul></ul>Language extensions
    5. 5. <ul><li>Generics </li></ul><ul><ul><li>Constructors without duplicate declaration </li></ul></ul><ul><ul><ul><li>Map<String, List<String>> anagrams = new HashMap<>(); instead of Map<String, List<String>> anagrams = new HashMap<String, List<String>>(); </li></ul></ul></ul><ul><ul><ul><li>Generics are not still covariant! </li></ul></ul></ul><ul><ul><ul><ul><li>List<Integer> li = new ArrayList<Integer>(); List<Number> ln = li; // illegal ln.add(new Float(3.1415)); // legal </li></ul></ul></ul></ul><ul><ul><li>More type safe packages </li></ul></ul><ul><ul><ul><li>JDK 5: static Object newInstance(Class<?> componentType, int size) </li></ul></ul></ul><ul><ul><ul><ul><li>Because of backward compatibility </li></ul></ul></ul></ul><ul><ul><ul><li>JDK 5,7: static<T> T[] newInstance(Class<T> componentType, int size) </li></ul></ul></ul><ul><ul><ul><ul><li>More type-safe, can be called Array.<String>newInstance(String.class, 10) </li></ul></ul></ul></ul><ul><ul><li>Inference of method arguments </li></ul></ul><ul><ul><ul><ul><li>static<E> Set<E> emptySet(); </li></ul></ul></ul></ul><ul><ul><ul><ul><li>void print(Set<Man> men) {...} </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Call: print(Collection.emptySet()) // in JDK5,6 is necessary to explicitly specify which method should be called: Collection.<Man>emptySet(); </li></ul></ul></ul></ul><ul><ul><li>Template type information available at runtime </li></ul></ul>Lang. Ext. - JUG proposal
    6. 6. <ul><li>Enum </li></ul><ul><ul><li>JDK6: Enum implements Comparable, but cannot be used in expressions with <, >, >=, <= </li></ul></ul><ul><ul><li>JDK7: </li></ul></ul><ul><li>Strings in switch </li></ul><ul><ul><li>Use strings as constants in switch-statement instead of bundle of equals: </li></ul></ul>Lang. Ext. - JUG proposal enum Size {SMALL, MEDIUM, LARGE}; if (mySize < yourSize) { /* ... */ } switch (s) { “ yellow” : /* ... */ break ; “ red” : /* ... */ break ; defaul t: /* ... */ break ; } JDK7 JDK7
    7. 7. <ul><li>Chained invocations </li></ul><ul><ul><li>Reuse the receiver of previous call in case of a call of a method returning void </li></ul></ul><ul><li>Method extensions </li></ul><ul><ul><li>A way how to extend existing interface by utility methods </li></ul></ul><ul><ul><ul><li>Static imported method can be used as a member of its first argument </li></ul></ul></ul>Lang. Ext. - JUG proposal public class Beana { public void setName(String void) {} public void setDate(Date date) {} } Beana a = new Beana() .setName(“name”) .setDate(new Date()); import static java.util.Collections.sort; ... List<String> list = ...; list.sort(); JDK7
    8. 8. <ul><li>Catching multiple exception types </li></ul><ul><ul><li>To avoid repeating code </li></ul></ul>Lang. Ext. - JUG proposal <ul><li>More flexible checking of re-thrown exception </li></ul><ul><ul><ul><li>When we need to catch all exceptions, do something with them and re throw them </li></ul></ul></ul><ul><ul><ul><ul><li>Re-thrown exception is threated as if it can throw only checked exceptions occurring in the try block </li></ul></ul></ul></ul>public void test() throws IOException { try { doSomething(); } catch ( final Throwable ex) { throw ex; } } try { return clazz.newInstance(); } catch (InstantiationException | IllegalAccessException e) { /* .. */ } public void doSomething throws IOException {} public void test() throws Throwable { try { doSomething(); } catch (Throwable ex) } throw ex; } JDK7 JDK7 JDK5
    9. 9. <ul><li>Creation of XML fragments </li></ul><ul><ul><li>XML embedded in Java code </li></ul></ul><ul><ul><ul><li><tag> or #tag </li></ul></ul></ul><ul><ul><li>Data coders in according to XSD </li></ul></ul><ul><ul><ul><li>date/time </li></ul></ul></ul><ul><li>XPath language support </li></ul>Lang. Ext. - XML lang. support public void addMember(XML xml, String name, Integer age) { xml.addChild(<member> <name> { name } </name> <age> { 26 } </age> </member>); } public void makeYounger(XML fs, Integer newAge) { List<XML> l = fs.findAll(“member[age>25]”); for (XML a : l) { a.get(“age”).set(newAge); } } JDK7 JDK7
    10. 10. <ul><li>Closures </li></ul><ul><ul><li>Similar to delegates in C# </li></ul></ul><ul><ul><li>Anonymous functions </li></ul></ul><ul><ul><li>Function type </li></ul></ul><ul><ul><ul><li>Local functions </li></ul></ul></ul><ul><li>Main idea: translate closure to interface (similar to creating anonymous classes) </li></ul>Lang. Ext. - closures {String, String => String} simpleConcat = {String a, String b => a+b }; String s = “DS”; String g = “RG”; String dsrg = simpleConcat.invoke(s,t); interface Func<R extends String, A1 super String, A2 super String> { public R invoke(A1, A2); } ↔ Locks.withLock(lock, {=> doSomething()});, {Strings s => Integer.decode(s)}); JDK7
    11. 11. <ul><li>Additional information </li></ul><ul><ul><li>@Licence </li></ul></ul><ul><li>Annotations for static analysis of code </li></ul><ul><ul><li>@NonNull </li></ul></ul><ul><ul><li>@NonEmpty </li></ul></ul><ul><ul><li>@ReadOnly </li></ul></ul><ul><ul><li>@Existing </li></ul></ul><ul><ul><li>@Critical </li></ul></ul>Lang. Ext. - annotation extension
    12. 12. <ul><li>Operator overloading (BigDecimal) </li></ul><ul><ul><li>Arithmetic operators for BigDecimal </li></ul></ul><ul><li>Lightweight reflection </li></ul><ul><li>64bit index for arrays </li></ul><ul><li>XQuery support (JSR 225) </li></ul><ul><li>Resource Consumption Management API (JSR 284) </li></ul><ul><ul><li>Performance policies (CPU, heap consumption per application/thread, reservations) </li></ul></ul><ul><li>Null-safe types </li></ul><ul><ul><li>public void method(#K key) </li></ul></ul><ul><ul><ul><li># marks not-null parameter </li></ul></ul></ul><ul><ul><ul><ul><li>Checked at compile time (globally, per-method,...) </li></ul></ul></ul></ul><ul><ul><ul><li>(#) casting operator </li></ul></ul></ul><ul><ul><ul><li>Alternative to @NonNull annotation </li></ul></ul></ul>Lang. Ext. - proposed enhancements
    13. 13. <ul><li>Separated projects </li></ul><ul><ul><li>Almost work in the current version of Java </li></ul></ul><ul><ul><li>Proposed to be part of JDK7 </li></ul></ul><ul><ul><ul><li>Java Modules </li></ul></ul></ul><ul><ul><ul><li>Beans bindings, validation </li></ul></ul></ul><ul><ul><ul><li>Swing application API </li></ul></ul></ul><ul><ul><ul><li>... </li></ul></ul></ul>Related projects
    14. 14. <ul><li>Superpackages (JSR 294) </li></ul><ul><ul><li>Why? To hide unnecessary packages. </li></ul></ul><ul><ul><li>Superpackage is a named collection of packages or superpackages, classes </li></ul></ul><ul><ul><li>Accessibility defined by superpackages </li></ul></ul><ul><ul><ul><li>Compiled, loaded and checked by JVM at runtime </li></ul></ul></ul><ul><ul><li>Define development module for JSR 277 (Java Module System) </li></ul></ul><ul><ul><li>Separate compilation ? </li></ul></ul><ul><ul><ul><li>Not yet specified </li></ul></ul></ul>Rel. projects – modules superpackage jdk { member package java.util; member package; member package; // Impl detail export java.util.*; // Public API export*; } JDK7
    15. 15. <ul><li>Java Modules (JSR 277) </li></ul><ul><ul><li>Specifies: </li></ul></ul><ul><ul><ul><li>Modules, Versioning, Repository, Runtime support </li></ul></ul></ul><ul><li>Development module (=superpackage) => deployment module (JAM – Java Module) </li></ul><ul><ul><li>Meta-info (generated from devel. module) </li></ul></ul><ul><ul><li>Compiled code </li></ul></ul><ul><ul><li>Resources </li></ul></ul><ul><li>Versioning </li></ul><ul><ul><li>Simple major/minor versions </li></ul></ul><ul><ul><li>Intervals, expressions e.g 1.3* = <1.3, 1.4) </li></ul></ul>Rel. projects – modules
    16. 16. Rel. projects – modules <ul><li>Repository </li></ul><ul><ul><li>Can store more than one version of module </li></ul></ul><ul><ul><ul><li>Bootstrap repository </li></ul></ul></ul><ul><ul><ul><ul><li>Contains core modules (Java SE) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Always presented in system </li></ul></ul></ul></ul><ul><ul><ul><li>Application repository </li></ul></ul></ul><ul><ul><ul><ul><li>Modules specific for application </li></ul></ul></ul></ul><ul><ul><li>Delegation model of repositories </li></ul></ul><ul><ul><ul><li>Parent repository </li></ul></ul></ul><ul><ul><ul><ul><li>Search is delegated to the parent repository </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Insulating of modules </li></ul></ul></ul></ul><ul><ul><li>Other features </li></ul></ul><ul><ul><ul><li>Repository reload, sharing modules among repositories (repository interchange format) </li></ul></ul></ul><ul><ul><li>Changed classloading </li></ul></ul>
    17. 17. <ul><li>OSGi and JAM </li></ul><ul><ul><li>Comparison – special seminar </li></ul></ul>Rel. projects – modules and OSGi
    18. 18. <ul><li>JSR 296 </li></ul><ul><li>Framework for Swing applications </li></ul><ul><ul><li>library for typical operations: </li></ul></ul><ul><ul><li>ApplicationContext </li></ul></ul><ul><ul><ul><li>Provides resource, task management, session storage. </li></ul></ul></ul><ul><ul><ul><li>Each application has one ApplicationContext </li></ul></ul></ul><ul><ul><li>Application </li></ul></ul><ul><ul><ul><li>lifecycle </li></ul></ul></ul>Rel. projects – SWING API
    19. 19. <ul><li>Beans bindings (JSR 295) </li></ul><ul><ul><li>Keep properties of beans synced (bindings), listeners to properties... </li></ul></ul><ul><ul><ul><li>the project works with JDK5 </li></ul></ul></ul><ul><ul><ul><li>Mainly focused on SWING </li></ul></ul></ul><ul><li>Property keyword </li></ul><ul><ul><li>Spec. is really vague: </li></ul></ul><ul><ul><ul><li>No more getter/setters </li></ul></ul></ul><ul><ul><ul><li>In fact generates inner class with property getter/setters </li></ul></ul></ul><ul><ul><ul><ul><li>Property per-type </li></ul></ul></ul></ul><ul><ul><ul><li>Access attribute member#surname = “Sac” </li></ul></ul></ul><ul><ul><ul><li>Access property object member##surname </li></ul></ul></ul><ul><ul><ul><li>?Readonly properties? </li></ul></ul></ul>Rel. projects – beans class Person { private String surname; private Integer age; private Person mother; } // Bean property Property surnameP = BeanProperty.create(“surname”); // EL properties – JSP syntax Property motherSurnameP = BeanProperty.create(“${mother.surname}”); Property isTeenP = BeanProperty.create(“${age < 20}”); // m stores information about a person System.out.println(“Member surname = “ + surnameP.getValue(m)); System.out.println(“Member's mother surname = “ + surnameP.getValue(M)); Binding b = Bindings.createAutoBinding(READ_WRITE, m, surnameP,m , motherSurnameP); b.bind(); // the call affects attribute m.surname motherSurnameP.setValue(m, “NewSurname”);
    20. 20. <ul><li>Beans Validation (JSR 303) </li></ul><ul><ul><li>Bindings validation ( à la Hibernate Validator) </li></ul></ul><ul><ul><ul><li>constraints via annotations, e.g.: </li></ul></ul></ul><ul><ul><ul><ul><li>@NotNull, @NotEmpty </li></ul></ul></ul></ul><ul><ul><ul><ul><li>@Min(value=), @Max(value=) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>@Length(min=, max=), @Range(min=,max=) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>@Past/@Future, @Email </li></ul></ul></ul></ul><ul><ul><ul><ul><li>... </li></ul></ul></ul></ul><ul><ul><ul><li>New constraint = new annotation + new class </li></ul></ul></ul>Rel. projects – beans
    21. 21. <ul><li>Improvements of JSR 166 (Concurrency utilities) </li></ul><ul><ul><li>Fork-join concept </li></ul></ul><ul><ul><ul><li>Fine-grained parallel computation framework </li></ul></ul></ul><ul><ul><ul><li>Divide problems to subproblems, solve it, join the results </li></ul></ul></ul><ul><ul><ul><ul><li>Subproblems are executed in parallel, current thread waits until they complete </li></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>coInvoke(task1, task2) </li></ul></ul></ul></ul></ul><ul><ul><ul><li>Work-stealing </li></ul></ul></ul><ul><ul><ul><ul><li>Each thread has deque of tasks, instead of sleeping try to steal and execute a task from other busy threads </li></ul></ul></ul></ul><ul><ul><li>TransferQueue (type of BlockingQueue ) </li></ul></ul><ul><ul><ul><li>Producer side blocking until the consumers is ready </li></ul></ul></ul>Rel. projects – concurrent framework
    22. 22. <ul><li>Improvements of JSR 166 (Concurrency utilities) </li></ul><ul><ul><li>Fork-join concept </li></ul></ul><ul><ul><ul><li>Fine-grained parallel computation framework </li></ul></ul></ul><ul><ul><ul><li>Divide problems to subproblems, solve it, join the results </li></ul></ul></ul><ul><ul><ul><ul><li>Subproblems are executed in parallel, current thread waits until they complete </li></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>coInvoke(task1, task2) </li></ul></ul></ul></ul></ul><ul><ul><ul><li>Work-stealing </li></ul></ul></ul><ul><ul><ul><ul><li>Each thread has deque of tasks, instead of sleeping try to steal and execute a task from other threads </li></ul></ul></ul></ul><ul><ul><li>TransferQueue (type of BlockingQueue ) </li></ul></ul><ul><ul><ul><li>Producer side blocking until the consumers is ready </li></ul></ul></ul>Rel. projects – concurrent framework // PSEUDOCODE Result solve(Problem problem) { if (problem.size < SEQUENTIAL_THRESHOLD) return solveSequentially(problem); else { Result left, right; INVOKE-IN-PARALLEL { left = solve(extractLeftHalf(problem)); right = solve(extractRightHalf(problem)); } return combine(left, right); } } JDK7
    23. 23. <ul><li>JVM change </li></ul><ul><li>Invokedynamic (JSR 292) </li></ul><ul><ul><li>Improvement of scripting engine (JSR 223) </li></ul></ul><ul><ul><li>New byte code instruction (type free invokevirtual) </li></ul></ul><ul><ul><ul><li>Support for dynamically typed languages (Jython, Groovy) </li></ul></ul></ul><ul><ul><ul><ul><li>Jython – code written in Python, compiled into byte code at runtime, run in JVM </li></ul></ul></ul></ul><ul><ul><ul><li>Target of call/parameters need not to be statically known </li></ul></ul></ul>Rel. projects – invokedynamic
    24. 24. <ul><li>Units and Quantities (JSR 275) </li></ul><ul><ul><li>Conversions between many SI/Imperial units </li></ul></ul><ul><li>JMX 2.0 (JSR 255) </li></ul><ul><ul><ul><li>Annotations support for def. MBeans </li></ul></ul></ul><ul><li>JMX Web Service Connector (JSR 262) </li></ul><ul><li>Native IO - NIO 2.0 (JSR 203) </li></ul><ul><ul><ul><li>New filesystem API (access file attributes, ...) </li></ul></ul></ul><ul><ul><ul><li>Async IO </li></ul></ul></ul><ul><li>Javadoc update (JSR 260) </li></ul><ul><ul><li>New tags and documentation mechanism </li></ul></ul>Rel. projects – others
    25. 25. <ul><li>Java kernel </li></ul><ul><ul><li>Should be a part of JDK7, but will be released earlier in like “Consumer JRE” in 2008 </li></ul></ul><ul><ul><li>Small installation of Java </li></ul></ul><ul><li>Improved installation ? </li></ul><ul><li>Startup time of JVM ? </li></ul><ul><ul><li>Tiered compilation </li></ul></ul><ul><ul><ul><li>Mix of client and server hot spot compiler </li></ul></ul></ul><ul><li>HotSpot improvements ? </li></ul>Other proposed improvements
    26. 26. <ul><li>JDK7 </li></ul><ul><ul><li>Current build 23 (22 th November) </li></ul></ul><ul><ul><ul><li>Only bug fixes, no new features </li></ul></ul></ul><ul><li>OpenJDK </li></ul><ul><ul><li>Modules (JSR254, JSR257) </li></ul></ul><ul><li>Projects </li></ul><ul><ul><li>Beans binding, Fork framework, Swing API </li></ul></ul><ul><li>Missing! </li></ul><ul><ul><li>No proposals from EE (mainly app. servers)? </li></ul></ul><ul><ul><ul><li>Separation of application in JVM </li></ul></ul></ul>What is already implemented?
    27. 27. <ul><li>Java module system </li></ul><ul><ul><li>How will it cooperate with OSGi? </li></ul></ul><ul><li>Java kernel </li></ul><ul><li>Annotations </li></ul><ul><ul><li>Static analysis of code </li></ul></ul><ul><li>How will Google's Android affect Sun's Java? </li></ul>Important for us
    28. 28. <ul><li>Sun JDK7 Project </li></ul><ul><ul><li> </li></ul></ul><ul><li>OpenJDK </li></ul><ul><ul><li> </li></ul></ul><ul><li>Overview of Java 7 (updated) </li></ul><ul><ul><li> </li></ul></ul>Links