[strukelj] why will java 7.0 be so cool

29
WHAT’S COMING IN JAVA SE 7 MARKO ŠTRUKELJ PARSEK

Upload: javablend

Post on 06-May-2015

1.554 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: [Strukelj] Why will Java 7.0 be so cool

WHAT’S COMING IN JAVA SE 7

MARKO ŠTRUKELJ

PARSEK

Page 2: [Strukelj] Why will Java 7.0 be so cool

JAVA SE 7

• Feature set not specified yet

• JSR not created yet

• Many different API, library, and framework efforts

aiming for inclusion

• Early Access downloads available:

– Java SE 7 EA

– Open JDK

• Release expected summer 2009 at the earliest

Page 3: [Strukelj] Why will Java 7.0 be so cool

FOCUS

• Focus on (as claimed by Sun):

– Multiple languages support

– Modularity

– Rich clients

• Plus the usual:

– API updates and language enhancements

– Performance

Page 4: [Strukelj] Why will Java 7.0 be so cool

SOME LANGUAGE ENHANCEMENTS

– Modules

– Annotations extensions

– Strings in switch statements

– Closures

– Try catch syntax improvement

– Enum comparisons

Page 5: [Strukelj] Why will Java 7.0 be so cool

SOME API UPDATES

• New I/O version 2

• JMX 2.0

Page 6: [Strukelj] Why will Java 7.0 be so cool

MODULE SYSTEM (JSR-277)

• Introduce mandatory and consistent versioning

and dependency meta info

• Integrate versioned dependencies with

classloading

• Introduce new packaging system – JAM archives,

and module repositories to store and serve the

content of these archives.

• Introduce a scope that’s less than public but more

than package-private to improve hiding of non-api

classes

Page 7: [Strukelj] Why will Java 7.0 be so cool

MODULE SCOPE - LESS THAN PUBLIC, MORE THAN PACKAGE PRIVATE

:: com/company/util/ImageUtils.java

package com.company.util;

public class ImageUtils {

... OSHacks.callConvert();

}

::com/company/util/impl/OSHacks.java

package com.company.util.impl;

public class OSHacks {

public callConvert() {...}

}

Page 8: [Strukelj] Why will Java 7.0 be so cool

MODULE SCOPE - LESS THAN PUBLIC, MORE THAN PACKAGE PRIVATE

:: com/company/util/ImageUtils.java

module com.company.util;

package com.company.util;

public class ImageUtils {

... OSHacks.callConvert();

}

::com/company/util/impl/OSHacks.java

module com.company.util;

package com.company.util.impl;

module class OSHacks {

module callConvert() {...}

}

:: com/company/util/module-info.java

@Version(“1.0”)

@ImportModule(name=“java.se.core”, version=“1.7+”)

@ExportResources({“schemas/**”})

module com.company.util;

Page 9: [Strukelj] Why will Java 7.0 be so cool

MODULE SYSTEM (JSR-277)

• JAM file - like JAR but more stringent meta

data requirements

– Can contain jars, native libraries, resources ...

– Module definition info and dependencies

specified through annotations

• Repositories implemented at API level

– You can implement custom repositories and

plug them into the module system.

Page 10: [Strukelj] Why will Java 7.0 be so cool

MODULE SYSTEM (JSR-277)

– bootstrap repository (java.* classes)

contains "java.se" module - implicitly imported

– system-wide runtime repository (versioned

global libraries)

– user repository

– application repository - on the fly at app

startup - when application not installed in

system repository

Page 11: [Strukelj] Why will Java 7.0 be so cool
Page 12: [Strukelj] Why will Java 7.0 be so cool

ANNOTATIONS ON JAVA TYPES (JSR-308)

• Catch more errors at compile time

– You’ll be able to put annotation in more places

– Type use:

• List<@NonNull String> keys;

– @NonNull, @Interned, @Readonly,

@Immutable

Page 13: [Strukelj] Why will Java 7.0 be so cool

LANGUAGE ENHANCEMENTS - IMPROVED TRY-CATCH

Motivation: prevent code repetition

try {

... someCall();

} catch(IllegalArgumentException, IOException e) {

log.warn(“We expected that, moving on ...: ”, e);

} catch(Exception e) {

log.error();

throw e;

}

Page 14: [Strukelj] Why will Java 7.0 be so cool

LANGUAGE ENHANCEMENTS – SAFE RETHROW

Motivation: prevent code repetition

public void test() throws E1, E2 {

try {

... someCall();

} catch(final Throwable ex) {

log.error(“error: “, ex);

throw ex;

}

}

Page 15: [Strukelj] Why will Java 7.0 be so cool

LANGUAGE ENHANCEMENTS – ENUM COMPARISON

Motivation: improve usability and readability

enum Size {SMALL, MEDIUM, LARGE};

Size mySize, yourSize;

...

if (mySize < yourSize) {

...

}

Page 16: [Strukelj] Why will Java 7.0 be so cool

LANGUAGE ENHANCEMENTS – STRINGS IN SWITCH STATEMENTS

Motivation: improve usability and readability

switch(val) {

case “true”:

case “yes”:

return true;

case “false”:

return false;

default:

throw new IllegalArgumentException(“Wrong value: ” + val);

}

Page 17: [Strukelj] Why will Java 7.0 be so cool

LANGUAGE ENHANCEMENTS - JBBA CLOSURES PROPOSAL

• What are closures?

Thread t = new Thread(new Runnable() {

public void run() {

doSomething();

}

});

Page 18: [Strukelj] Why will Java 7.0 be so cool

LANGUAGE ENHANCEMENTS - CLOSURES

• Couldn’t we have something like

Thread t = new Thread({ =>

doSomething();

});

• Motivation: reduce boilerplate

Page 19: [Strukelj] Why will Java 7.0 be so cool

LANGUAGE ENHANCEMENTS - CLOSURES

Connection con = ds.getConnection();

con.use({ =>

ps = con.prepareStatement(...);

...

}); // connection will automatically be closed

• Motivation: automatic resource cleanup, remove a whole

class of errors – i.e. make connection leak impossible

Page 20: [Strukelj] Why will Java 7.0 be so cool

LANGUAGE ENHANCEMENTS - CLOSURES

Double highestGpa = students

.withFilter( { Student s => (s.graduation ==

THIS_YEAR)} )

.withMapping( { Student s => s.gpa } )

.max();

• Motivation: express a data processing algorithm

in clean and short form that is parallelism-

agnostic

Page 21: [Strukelj] Why will Java 7.0 be so cool

API UPDATES – NEW I/O 2 (JSR-203)

– copying, moving files

– symbolic links support

– file change notification (watch service)

– file attributes

– efficient file tree walking

– path name manipulation

– pluggable FileSystem providers

Page 22: [Strukelj] Why will Java 7.0 be so cool

API UPDATES – NEW I/O 2 (JSR-203)

Path home = Path.get("/home/user1");

Path profile = home.resolve(".profile");

profile.copyTo(home.resolve(".profile.bak"),

REPLACE_EXISTING, COPY_ATTRIBUTES);

Page 23: [Strukelj] Why will Java 7.0 be so cool

API UPDATES – NEW I/O 2 (JSR-203)

– java.nio.file

– java.nio.file.attribute

– interoperability with java.io

File srcFile = new File(“/home/user1/file.txt”);

File destFile = new File(“/home/user1/file2.txt”);

srcFile.getFileRef().copyTo(destFile.getFileRef());

Page 24: [Strukelj] Why will Java 7.0 be so cool

API UPDATES – JMX 2.0

• Use annotations to turn POJOs into MBeans.

(JSR-255)

• There is also a new standard to access

management services remotely through web

services - interoperable with .NET (JSR-262)

Page 25: [Strukelj] Why will Java 7.0 be so cool

NEW APIS

• New Date and Time API (JSR-310)

(implemented in Joda-Time library)

Page 26: [Strukelj] Why will Java 7.0 be so cool

FORK-JOIN CONCURRENCY API (JSR-166)

Fine-grained parallel computation framework

based on divide-and-conquer and work-stealing

Double highestGpa = students

.withFilter( { Student s => (s.graduation ==

THIS_YEAR)} )

.withMapping( { Student s => s.gpa } )

.max();

Page 27: [Strukelj] Why will Java 7.0 be so cool

BEANS VALIDATION FRAMEWORK (JSR-303)

Constraints via annotations (like in Hibernate

Validator)

– @NotNull, @NotEmpty

– @Min(value=), @Max(value=)

– @Length(min=, max=), @Range(min=,max=)

– @Past/@Future, @Email

Page 28: [Strukelj] Why will Java 7.0 be so cool

SOME OTHER STUFF – NEW GARBAGE COLLECTOR

• Garbage first (G1) garbage collector

– Parallel, concurrent – makes good use of

multiple native threads (fast)

– Generational – segments the heap and gives

different attention to different segments (fast)

– High throughput (fast)

– Compacting – efficient memory use – but

takes most of GC processing time (slow)

Page 29: [Strukelj] Why will Java 7.0 be so cool

SOME OTHER STUFF – JAVA FX

• A new scripting language and a whole set

of APIs for building rich GUIs

– Motivation: finally make UI development easy

for GUI, multimedia applications, vector

graphics, animation, rich internet applications

... Compete with AIR and Silverlight

– JavaFX Script

– Swing enhancements (JWebPane ... )

– Java Media Components