Java Future S Ritter

Post on 10-May-2015

1.850 views 1 download

Tags:

description

The next release of the Java Standard Edition is scheduled for the beginning of 2010. In this session we'll review the latest feature list of what's in and what's out of the next version of the JDK. An update on the latest news around JavaFX including the 1.2 release and the general availability of JavaFX Mobile for Windows Mobile devices.

Transcript of Java Future S Ritter

What The Future Holds For Java: JDK7 and JavaFXSimon RitterTechnology Evangelist

2

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.

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

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

5

ModularityModularityProject JigsawProject Jigsaw

6

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

7

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.

8

Modularizing You Code

planetjdk/src/

org/planetjdk/aggregator/Main.java

module-info.java

planetjdk/src/

org/planetjdk/aggregator/Main.java

Modularize

9

module-info.java

module org.planetjdk.aggregator {

system jigsaw;requires module jdom;requires module tagsoup;requires module rome;requires module rome-fetcher;requires module joda-time;requires module java-xml;requires module java-base;class org.planetjdk.aggregator.Main;

}

Dependencies

Main class

Module name

Module system

10

Compiling Modules

> 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

javac -modulepath planetjdk/src:rssutils/romeorg.planetjdk.aggregator/module-info.javaorg.planetjdk.aggregator/org/...com.sun.syndication/module-info.javacom.sun.syndication/com/...

11

Running Modules

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

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

12

Module Versioningmodule 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;

}

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.javaorg.planetjdk.aggregator/org/...

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

sudo dpkg -i org.planetjdk.aggregator_1.0_all.deb/usr/bin/aggregator

14

SmallSmall(Language)(Language)

ChangesChangesProject CoinProject Coin

15

“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

16

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

17

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

18

Better Integer Literals> Binary literals

> With underscores

> Unsigned literals

int mask = 0b1010;

int bigMask = 0b1010_0101;long big = 9_223_783_036_967_937L;

byte b = 0xffu;

19

Better Type Inference

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

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

20

Strings in Switch> Strings are constants too

String s = ...;switch (s) {

case "foo":return 1;

case "bar":Return 2;

default:return 0;

}

21

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();

}}

22

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 }

23

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";

24

DynamicDynamicLanguagesLanguages

SupportSupportDa Vinci Machine ProejctDa Vinci Machine Proejct

25

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

26

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

27

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

28

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

29

Languages on the Java Virtual Machine

29

Clojure

Tcl

JavaScript

v-language

CAL

Sather

Funnel

MiniPLAN

Lisp

Scheme

Basic

Logo JHCR

TermWare

Drools

Prolog

LLP

JESS

Eiffel

Smalltalk

C#

G

GroovyNice

Anvil

Hojo

Correlate

Ada

Bex Script

Tea

PHP

Phobos Sleep

FScript

JudoScript

JRuby

ObjectScript

Jickle

Yoix

Simkin

BeanShell

DawnWebL

iScript

Jython

Pnuts

Yassl

Forth

PiccolaSALSA

Processing

Zigzag

Tiger

Tiger

IconPascal

Oberon

Modula-2

Luck

E

Rexx JavaFX ScriptScala

30

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!

31

Method Invocation TodayString 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 var5: 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

32

Bootstrapping Method Handle

33

invokedynamic Byte Code0: aload_11: aload_22: invokedynamic #3 //Name and type only lessThan:

//(Ljava/lang/Object;Ljava/lang/Object;)Z5: if_icmpeq

>

>

> >

pink thing = CallSite objectgreen thing = MethodHandle object

Call site reifies the call

34

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

35

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

36

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

37

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

38

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

39

39

Simon Ritter Technology Evangelist simon.ritter@sun.com

JDK7: What The Future Holds For Java