HTML 5 / Java Script and Java: The Facts and the Myths

uglyveinInternet and Web Development

Jun 24, 2012 (4 years and 9 months ago)

382 views

1
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
Insert Information Protection Policy Classification from Slide
8
HTML5/JavaScript and Java: The Facts and the Myths

Bernard Traversat, Director Engineering
Java Platform Group
Oracle
2
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
Insert Information Protection Policy Classification from Slide
8
The following is intended to outline our general product
direction. It is intended for information purposes only, and may
not be incorporated into any contract. It is not a commitment to
deliver any material, code, or functionality, and should not be
relied upon in making purchasing decisions. The development,
release, and timing of any features or functionality described
for Oracle’s products remains at the sole discretion of Oracle.
3
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
Agenda

HTML5/JavaScript and Java background

Why delivering a JavaScript runtime on the JVM?

Project Nashorn (New Java JavaScript engine)

Demos


WebKit and Node.js on the JVM

Q&A
4
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
The Right Mindset

Look beyond technology religion and common
beliefs

Focus on the
complementary
values of Java and
HTML5/JavaScript
5
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
6
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
HTML5

Simplify and standardize HTML layout

Rendering (canvas) and embedding video & audio

Support for offline and local web app execution

Deeper integration in native platform (location,
camera)

Improve interoperability between browsers

Support existing HTML content
7
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
JavaScript
A language and runtime born in the browser

A prototype-based scripting language

Use for expressing computations that manipulate HTML pages

Libraries of build-in objects and methods to interact with the Document
Object Model (DOM) of a web page

Method of accessing / modifying HTML information on the page

Tree structure of all HTML elements, including attributes and the text
they contain.


New elements can be created and inserted into the DOM Tree (HTML5)

Events

to capture browser user's interactions - c
licking a button in a
window.
8
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
Java

Aim at large software development

Safety, readability, productivity, maintainability

Removed confusing features (pointers, operator overloading)

Automatic memory management (reference count/garbage collection)

Strongly typed - everything is a class

Architecture neutral & portability

Bytecode runs everywhere (JVM)

High-Performance

Mixed interpreted and compiled execution (JIT)
9
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
Java

Multi-threaded

Thread management

Concurrency primitives (synchronize)

Fork/Join

Security

Security sandbox

Memory accesses are virtual, mapped by JVM to physical
locations

Verification of classes
10
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
Why HTML5/JavaScript ?

The Web 2.0 Cloud effect or “the Browser is the Client”

The most interesting content is in the Cloud

Content is dynamic and can't be cached

Network ubiquity and good enough latency

The browser platform is closing the gap against native platforms

Rendering, process isolation, asynchronous communication,
persistency
,
event notification, widget, drag & drop, multi-media & video)

Good enough for many apps

Increase velocity to develop and deploy new apps

More assembly, mashup than development

Shorter release cycles (from years to weeks)
11
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
The Browser UI Uniformity

Everybody know how to use a browser

Users don't have to learn how to use and navigate a web app

The browser provides a simple and ubiquitous UI model

Quick startup (no installer)

Forward & back buttons

Hyperlinks

Bookmarks & tabs

Security & trust

Multiple-application management

Mobility – Access an app from any computers
12
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
HTML5/JavaScript & Java
JavaFX
JavaFX


(HTML5)
(HTML5)
13
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
Why Java & JavaScript

Access to a huge set of Java library and tools

Maintainability

Multi-threading

Limited security sandbox

Can't still truly verify what is downloaded and running within the browser

Limited access to native platform capabilities

More access to native platform features will further increase risk

Many developer toolkits (jQuery, Gears, Dojo, JIL, etc.)

Increase application download size
14
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
Java & Web Development

A verbose and bulky language

Strong and inflexible typed language

Inflexible object composition (no traits or delegation)

No class & method extension

Error handling and exception

Low-level concurrency model (immutable, actor)

Java plug-in

Consumer friendly deployment (security pop-up, webstart)

Good enough performance (startup, footprint)

Designer/authoring tool for rich media apps

Better bridge between JavaScript & Java
15
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
Java vs JavaScript Strengths

Big apps vs small scripts

Compile vs no-compile

Cached vs downloaded

Strong typing vs optional typing

Large development vs rapid prototyping

Readability vs conciseness

Maintainability vs productivity

Expresiveness vs simplicity

Safety vs speed of development
16
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
HTML5/JavaScript & Java
JavaFX
JavaFX


(HTML5)
(HTML5)
JVM
JavaScript
JavaScript
Client
Client
Java Code
Java Code
Project Nashorn
JVM
JavaScript
JavaScript
Server
Server
Java Code
Java Code
17
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
Project Nashorn

Pronounced Nahz-horn

German for nose-horn, reference to Rhino and O'Reilly's Rhinoceros

Implement a modern
ECMAScript-262-5
engine to run on the
Oracle JVM

Seamless interoperability between JavaScript and Java

Nashorn is written from a clean code base, in Java

Will be an OpenJDK open-source project

Will replace Rhino in JDK 8
18
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
Rhino

Rhino 1.7R3 bundled with JDK 7

But, Rhino is showing its age and limitations

Developed thirteen years ago at Netscape (pre-Hotspot)

Mozilla focusing resource on its native engine

Performance significantly fallen behind

High memory usage due to interpreted model

Will require significant rewrite to take advantage of JSR-
292 (InvokeDynanmic)
19
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
JavaScript on the Java Virtual Machine

Scripting for Java (Client, Server, Embedded)

Scripting language for J2EE

Runtime for client Web HTML5 programming

Enabling deep HTML5 and Java content interoperability

Access to a huge set of tools and libraries

Dynamic programming style

Developer familiarity

Assert the JVM as a multi-language runtime

Bytecode as the intermediary target for language developers (Jruby, Python, Groovy,
Closure)

Reference use case for JDK 7 InvokeDynamics
20
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
Project Nashorn (Suite)

Have JavaScript performance match that of Java

As thin a layer as possible

Work with familiar paradigms (Java Beans, Collections)

Secure JavaScript execution sandbox

Provide seamless debugging experience for JavaScript/Java apps

Leverage JVM serviceability and profiling capabilities

Customized to Enterprise need
21
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
The HotSpot Java Virtual Machine

Tier and Just-in Time (JIT) Compilation – 15 Years of R&D

Seamless multi-tier transition from interpreted to fast compiled
excecution


Race towards JavaScript performance

Major investments from browser vendors into building their own JIT
technology (V8, SquirrelFish, SpiderMonkey, JaegerMonkey)


Limit of “tracing” vs “method” compilation


JIT complexity is exponentially proportional to performance!


Latency vs app complexity
22
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
The Java Virtual Machine
The Computer Language Benchmark Games http://shootout.alioth.debian.org/
~5x Slower
23
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
JavaScript Vulnerability
http://secunia.com/gfx/pdf/Secunia_Half_Year_Report_2010.pdf
24
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
Java Sandbox

Safety features built into the Java language

Type-safe reference casting

Structured memory access (no pointer arithmetic)

Automatic garbage collection (can't explicitly free allocated memory)

Array bounds checking

Checking references for null

The class loader architecture

Bytecode verifier

The security manager and the fine grain Java security API
25
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
Demos
26
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
HTML5 Powered by Nashorn

WebKit modified to use Nashorn as its JavaScript
engine

Proof of concept – only some DOM, Window and
Canvas2D methods implemented

Java Bindings currently hand-written using JNI, to be
generated from IDL later

Advantage: can call any Java API from JavaScript
27
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
Node Powered by Nashorn

Server-side JavaScript Framework

Presents Node.js JavaScript APIs using Nashorn as
the JavaScript Engine

Not limited to single thread – use all your cores

Can call into Java – reuse all your Java middleware
28
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
Project Nashorn Status

A functioning JavaScript with some bugs and
incomplete areas

Out of the box performance (3x faster and 5x
smaller than Rhino 1.7R3)

Working with JVM team on JSR-292 optimizations

Open source as a OpenJDK project (Date TBD)

Nashorn will ship in JDK 8
29
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
Summary

Java and HTML5/JavaScript are complementary technologies

Significant values to enable HTML5 apps to easily access Java

Project Nashorn

A new & modern JavaScript engine for the JVM

Seamless and lightweight integration between Java and JavaScript

Leverage the latest JDK7 HotSpot technology

Open-source as part of OpenJDK

Will be released as part of JDK 8
30
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
Q&A
We are
Hiring!
Repeat: Today!
12:30pm-1:30pm
Parc 55 Powell I / II
31
Copyright © 2011, Oracle and/or its affiliates. All rights
reserved.
Latin America 2011
December 6–8, 2011

Tokyo 2012
April 4–6, 2012