Boldly go where the Java programming language has never gone before
1. Boldly go
where the Java programming language
has never gone before
Geert Bevin, Senior Developer, Terracotta Inc.
TS-6213
2. Learn that you don't have to master new
languages, tools and libraries to deliver
applications that go much further than what
the standard Java™ Platform provides
2008 JavaOneSM Conference | java.sun.com/javaone | 2
3. Who is Geert Bevin?
senior developer at Terracotta (http://terracotta.org)
founder of Uwyn (http://uwyn.com)
founder of RIFE (http://rifers.org)
contributor to many open-source projects:
Terracotta, RIFE, OpenLaszlo, Gentoo Linux,
Bla-bla List, Drone, ...
Sun Java Champion
creator of native Java language continuations
biker and gamer
2008 JavaOneSM Conference | java.sun.com/javaone | 3
4. Agenda
Java programming language != Java Virtual Machine (JVM™) !=
Java platform
Terracotta
RIFE Continuations
Google Web Toolkit
Google Android
2008 JavaOneSM Conference | java.sun.com/javaone | 4
5. Key differences
The Java programming language provides a syntax that
allows the expression of application logic
The JVM provides a runtime environment that abstracts away
the operating system and hardware differences
The Java platform bundles the Java programming language
and the JVM with tools and libraries to provide a complete
development and runtime solution
2008 JavaOneSM Conference | java.sun.com/javaone | 5
6. Different purposes
The Java programming language is for development
The JVM is for the execution of byte code
The Java platform provides javac which compiles Java code to
byte code
2008 JavaOneSM Conference | java.sun.com/javaone | 6
7. This is what you use
every day …
2008 JavaOneSM Conference | java.sun.com/javaone | 7
8. … but it doesn’t have to
be this way
2008 JavaOneSM Conference | java.sun.com/javaone | 8
9. You can change the language
Another language can be used for development
For example:
• Groovy
• JavaFX™ script
• Scala
• JRuby
• Jython
• ...
2008 JavaOneSM Conference | java.sun.com/javaone | 9
10. You can change the tooling
Another tool can be used to create byte code
For example:
• ASM
• AspectJ
• BCEL
• groovyc
• ...
2008 JavaOneSM Conference | java.sun.com/javaone | 10
11. You can change the runtime
Another runtime can be used to execute your logic
For example:
• GCJ
• Web browser
• Dalvik virtual machine
•…
2008 JavaOneSM Conference | java.sun.com/javaone | 11
12. Today’s focus
Any variation on this theme is possible
Any of the layers can be replaced, extended or modified
Today we'll focus on the Java programming language as the
constant
2008 JavaOneSM Conference | java.sun.com/javaone | 12
13. Disclaimer
The technologies in this presentation are being covered
from a 'boldness' perspective. No judgment is made on
whether they're a good solution nor how they compare to
alternatives. This presentation is also not intended to be a
comprehensive overview of their capabilities
2008 JavaOneSM Conference | java.sun.com/javaone | 13
14. Agenda
Java programming language != JVM != Java platform
Terracotta
RIFE Continuations
Google Web Toolkit
Google Android
2008 JavaOneSM Conference | java.sun.com/javaone | 14
15. Agenda
Java programming language != JVM != Java platform
Terracotta
RIFE Continuations
Google Web Toolkit
Google Android
2008 JavaOneSM Conference | java.sun.com/javaone | 15
16. What is Terracotta?
Open Source Clustering for the Java Platform
Scalability and Availability for the JVM
2008 JavaOneSM Conference | java.sun.com/javaone | 16
18. Terracotta’s approach
'Regular' Clustering Different approach
• Scale out is complex • Cluster the JVM software
• Requires custom Java code • Eliminate need for custom
code
2008 JavaOneSM Conference | java.sun.com/javaone | 18
19. Main features
Heap level replication JVM coordination
• Declarative • Distributed synchronized
• No serialization • Distributed wait()/notify()
• Fine grained / field Level • Fine grained locking
• Only where resident Management
Large virtual heaps • Runtime visibility
• As large as available disk • Data introspection
• Dynamic paging • Cluster monitoring
2008 JavaOneSM Conference | java.sun.com/javaone | 19
25. Demo Terracotta Shared State
Hello World
2008 JavaOneSM Conference | java.sun.com/javaone | 25
26. Hello World - trying it out
Start the server:
$ start-tc-server.sh
Start a client:
$ dso-java.sh -Dtc.config=tc-config.xml
tutorial.HelloWorld
Output:
Hello Thu Dec 13 17:46:58 CET 2007
After starting the 2nd client:
Hello Thu Dec 13 17:46:58 CET 2007
Hello Thu Dec 13 17:47:06 CET 2007
The state is preserved in the server between executions
2008 JavaOneSM Conference | java.sun.com/javaone | 26
27. Example of coordination
Enhanced Hello World
using java.util.concurrent
2008 JavaOneSM Conference | java.sun.com/javaone | 27
31. Coordination - trying it out
Start the server:
$ start-tc-server.sh
Start a client:
$ dso-java.sh -Dtc.config=tc-config-concurrent.xml
-Dnodes=2 tutorial.HelloWorldConcurrent
It just hangs there
After starting the 2nd client:
Hello Thu Dec 13 19:12:38 CET 2007
Hello Thu Dec 13 19:13:56 CET 2007
The cyclic barrier is clustered across JVMs
2008 JavaOneSM Conference | java.sun.com/javaone | 31
33. Terracotta's Boldness
Plug into the JVM with a bootjar
Translate threads to cluster nodes
Modify getfield, putfield, monitorenter,
monitorexit byte code instructions to work across the
cluster
Java Memory Model as a contract for accessing shared state
and coordination across the cluster
2008 JavaOneSM Conference | java.sun.com/javaone | 33
34. Agenda
Java programming language != JVM != Java platform
Terracotta
RIFE Continuations
Google Web Toolkit
Google Android
2008 JavaOneSM Conference | java.sun.com/javaone | 34
35. Agenda
Java programming language != JVM != Java platform
Terracotta
RIFE Continuations
Google Web Toolkit
Google Android
2008 JavaOneSM Conference | java.sun.com/javaone | 35
36. What is RIFE?
Full-stack component framework to
quickly and consistently develop and
maintain Java web applications
2008 JavaOneSM Conference | java.sun.com/javaone | 36
38. … continuations are like
Save Game
2008 JavaOneSM Conference | java.sun.com/javaone | 38
39. … Save Game
can be performed at certain locations in the game
(or anywhere, depending on the type of game)
captures the progress and your possessions
several saved games can exist at once
2008 JavaOneSM Conference | java.sun.com/javaone | 39
40. … but they are also like
Load Game
2008 JavaOneSM Conference | java.sun.com/javaone | 40
41. … Load Game
retrieve any saved game
load the saved game
restore the progress and your possessions
resume exactly where you left off
2008 JavaOneSM Conference | java.sun.com/javaone | 41
42. … all we have to do is replace
Game Application
Saved Game Continuation
Progress Location
Possession State
2008 JavaOneSM Conference | java.sun.com/javaone | 42
43. … Pause
can be performed at certain locations in the game
captures the progress and your possessions
the progress your possessions
several saved games can exist at once
saved games
… Resume
retrieve any saved games
saved games
load the saved game
saved game
restore the progress and your possessions
resume the progress you leftpossessions
exactly where your off
2008 JavaOneSM Conference | java.sun.com/javaone | 43
44. … Pause
can be performed at certain locations in the game
captures the progress and your possessions
several saved games can exist at once
… Resume
retrieve any saved games
load the saved game
restore the progress and your possessions
resume exactly where you left off
2008 JavaOneSM Conference | java.sun.com/javaone | 44
45. … Pause
can be performed at certain locations in the application
game
captures the progress and the state
the location your possessions
several saved games can exist at once
continuations
… Resume
retrieve any saved games
continuation
load the saved game
continuation
restore the progress and your possessions
resume the location you left off
exactly where the state
2008 JavaOneSM Conference | java.sun.com/javaone | 45
48. Concretely : pseudo code
Program output is
Let's call this backwards
Context and location are stored in a variable
Multiple continuations can be active at once
2008 JavaOneSM Conference | java.sun.com/javaone | 48
49. Continuations Example
Number guessing game
(as a web application)
2008 JavaOneSM Conference | java.sun.com/javaone | 49
53. RIFE’s Boldness
Java method calls are trapped at runtime when classes are
loaded to rewrite the code sections they're executing in
(pause(), call(), answer())
Intuitive state handling, requiring no serialization
Regular Java language statements direct application control
flow
Regular Java development tools like debuggers and IDEs can
be used to develop, document and debug application control
flow
Continuation trees for backward and forward stepping
2008 JavaOneSM Conference | java.sun.com/javaone | 53
54. Agenda
Java programming language != JVM != Java platform
Terracotta
RIFE Continuations
Google Web Toolkit
Google Android
2008 JavaOneSM Conference | java.sun.com/javaone | 54
55. Agenda
Java programming language != JVM != Java platform
Terracotta
RIFE Continuations
Google Web Toolkit
Google Android
2008 JavaOneSM Conference | java.sun.com/javaone | 55
56. What is Google Web Toolkit?
Create AJAX applications in the Java programming language
using regular Java tools and deploy them to browser-
compliant HTML and Javascript™ technology
2008 JavaOneSM Conference | java.sun.com/javaone | 56
57. Google Web Toolkit Overview
2008 JavaOneSM Conference | java.sun.com/javaone | 57
58. Google Web Toolkit approach
'Regular' Ajax Dev Different approach
• Write Javascript code and • Write Ajax applications in the
DHTML Java platform
• Learn all the intricacies • Compile Java code to Javascript
code
Difficult to test Client-side debuggers
Javascript versions Toolkit (GWT)
Google Web Browser differences
use Java platform, standard APIs and your packaging
Smart text editors Resource regular tools
Ajax Libraries Design RPC API and format
2008 JavaOneSM Conference | java.sun.com/javaone | 58
59. GWT’s main features
Two main execution modes
• Hosted mode
• Executed with the JVM, no generated Javascript source code
• Embedded browser hooks into Java libraries
• Code-test-debug as regular Java applications
• Web mode
• Compiles Java source code to Javascript source code
• Runs inside browser without plugins
Standardized RPC
• Implement RemoteService interface
• Relies on serialization for arguments and return values
• Supports asynchronous method calls
2008 JavaOneSM Conference | java.sun.com/javaone | 59
61. Hello World
2008 JavaOneSM Conference | java.sun.com/javaone | 61
62. GWT Hello World
Create a new project and generate the required files
Import project into Eclipse
2008 JavaOneSM Conference | java.sun.com/javaone | 62
73. GWT’s Boldness
Two execution modes simplify both development and
deployment
Browser is hooked into Java libraries to provide real
debugging during hosted mode
The Java source code is compiled to the Javascript source code
during web mode to hide the difficulties of Ajax/DHTML
development
2008 JavaOneSM Conference | java.sun.com/javaone | 73
74. Agenda
Java programming language != JVM != Java platform
Terracotta
RIFE Continuations
Google Web Toolkit
Google Android
2008 JavaOneSM Conference | java.sun.com/javaone | 74
75. Agenda
Java programming language != JVM != Java platform
Terracotta
RIFE Continuations
Google Web Toolkit
Google Android
2008 JavaOneSM Conference | java.sun.com/javaone | 75
76. What is Google Android?
A platform for mobile devices where
software is written in the Java
language and run on Dalvik, a custom
virtual machine for embedded use
2008 JavaOneSM Conference | java.sun.com/javaone | 76
78. Google Android approach
'Regular' Mobile Dev Different approach
• Proprietary platform • Open-source platform
• Java™ Platform, Micro Edition • All applications in Java
(Java ME) is just another programming language
application • Dedicated virtual machine
• Java applications run in the per application
same virtual machine
2008 JavaOneSM Conference | java.sun.com/javaone | 78
82. Google Android’s Boldness
Program everything in the Java programming language
Only use Android's Java Platform Runtime Environment (JRE),
which includes supported library classes
Compile with javac and convert to Android bytecode for the
Dalvik VM (.dex files)
Debug through the Dalvik Debug Monitor Server (DDMS)
which forwards ports from the emulator or device to the IDE
2008 JavaOneSM Conference | java.sun.com/javaone | 82
83. Agenda
Java programming language != JVM != Java platform
Terracotta
RIFE Continuations
Google Web Toolkit
Google Android
2008 JavaOneSM Conference | java.sun.com/javaone | 83
84. Conclusion
Using just the Java language you're able to do:
• Transparent Clustering and Coordination:
Terracotta (http://www.terracotta.org)
• Intuitive application control flow:
RIFE Continuations (http://rifers.org)
• Ajax client application development:
Google Web Toolkit (http://code.google.com/webtoolkit)
• First-class mobile application development:
Google Android (http://code.google.com/android)
Without learning new languages and tools, all these
possibilities open up
2008 JavaOneSM Conference | java.sun.com/javaone | 84
85. Boldly go where the Java programming
language has never gone before
Geert Bevin
http://terracotta.org - http://rifers.org