Dynamic and rich web application using the good ol\' JVM - Java One Brazil

31
December 9th 2010 JavaOne 2010 Daniel López Janáriz Web developer Universitat de les Illes Balears (UIB) JavaTools Community @ java.net JavaOne SM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/ Dynamic and rich web application using the good ol' JVM

description

The talk I gave at JavaOne Brazil 2010.

Transcript of Dynamic and rich web application using the good ol\' JVM - Java One Brazil

Page 1: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

December 9th 2010JavaOne 2010

Daniel López JanárizWeb developer

Universitat de les Illes Balears (UIB)JavaTools Community @ java.net

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

Dynamic and rich web application using the

good ol' JVM

Page 2: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

Introduction

Web applications turned the development world upside down.

Ever changing requirementsHeterogeneous equipment (client OS, browsers,

application servers, server OS)Heterogeneous teams (programming, designing,

SEO, accesibility, usability...)Development in “web time”“Peter Pan” technology

And then we have to choose...

Page 3: Dynamic and rich web application using the good ol\' JVM - Java One Brazil
Page 4: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

Introduction II

What technology?How to choose?Which ones to try? What is important?

Adoption?Compatibility?Background?

Is there any “magic bullet”?That makes our team look like this...

Page 5: Dynamic and rich web application using the good ol\' JVM - Java One Brazil
Page 6: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

Introduction III

How can we improve the situation:Learn the various choices you can make so you can

decide between themAdapt your architecture to the web development

world.So, we are here to:

Showcase some technologies that can be used in the Java plattform.

Demonstrate that an architecture can be adaptable.The end goal is that the choice looks like...

Page 7: Dynamic and rich web application using the good ol\' JVM - Java One Brazil
Page 8: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

Learning: why the JVM?

Java is/was popular for a reason. Among other thingsVery good virtual machineTons of libraries, utilities, frameworks, API...

So, should we start from scratch?Sometimes not possible (100% one-step migration)Small steps help you move from a safe location to a

closer safe location.

Page 9: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

Learning: how?

The JVM is a bytecode interpreter/dynamic compiler so...

Generate compatible bytecode from the new language. (ex. Scala)

Implement in bytecode an interpreter for the new language. (ex. BeanShell)

Combine both solutions. (ex. Groovy)The “interpreted” languages can be accessed

Through a custom APIThrough the Java Scripting API (JSR-232, Java >=6)

Page 10: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

Learning: Java Scripting API

ScriptEngineManager theScriptEngineManager = new ScriptEngineManager();ScriptEngine theSE = theScriptEngineManager.getEngineByExtension(extension);Reader reader = ...;...// To interpret the script directlytheAnswer = theSE.eval(reader);

// If you call a function inside the scripttheSE.eval(reader);Invocable inv = (Invocable) theSE;theAnswer = inv.invokeFunction(functionName);

Page 11: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

Architecture: How to be prepared?

In order to be able to adapt to different requierements, we will use an architecture built around the Separation of Concerns (SoC) pattern.The overall goal is to have an architecture where the different parts communicate through clearly defined interfaces, so the don't step into each other toes.Using an “opinionated” artechitecture with tight integration brings other advantages and drawbacks.

Page 12: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

But don't go overboard with it or...

Page 13: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

… it will look like this:

Page 14: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

Architecture: Tiers

This is the web development SoC architecture we have usedWhere we have separated these main Concerns:

User interfacePresentation logicControllerApplication/business logicPersistence

Page 15: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

Architecture: Showcase application

A simple CRUD application on one table(Items).Every “concern” is implemented with different technologies:

To test if they really can be used independently.To find out some of the benefits and drawbacks of each

alternative.To do some mythbusting!

Page 16: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

Showcase: Implementations

PersistenceOracle, HSQLDB

Business logic JDBC, Hibernate, JPA, Ibatis, Groovy(x2), JRuby, JavaScript(x2),

Jython, Scala, Pnuts, PHP, PL/SQLController

WebLEAFPresentation logic

JSP, FreeMarker, XSLT, GroovletsUser interface

HTML, RIA: JavaScript (ExtJS, GWT), Flex, Java (Applet, JWS)Comunications

JSON, XML/HTTP, Web Services

Page 17: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

951

Possibilities!!(495 if we exclude the DB)

Page 18: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

Application & businessLogic

Page 19: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

App. Logic: Java/JDBC

Page 20: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

App. Logic: Groovy

Page 21: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

App. Logic: Jython

Page 22: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

App. Logic: Scala

Page 23: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

UserInterface

Page 24: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

UI: HTML

Page 25: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

UI: JavaScript RIA

Page 26: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

UI: Flex RIA

Page 27: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

UI: Java Applet RIA

Page 28: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

UI: PDF

Page 29: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

Etc... (demo)

http://localhost:8080/

http://www.greeneyed.org/test/

Page 30: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

Conclusions

The JVM is not only Java and you don't have to abandon completely the Java platform.There are many different languages with different styles that are more or less useful depending on your needs.Learning different approaches to face all the different challenges is the way to be prepared.SoC architectures are an option to facilitate having different approaches at hand, even though it's not the only one and it is not necessarily the best.Implementing such an experiment is quite an experience and acts as a vaccine against language bigotry.Next question is... is any of this really useful in real life?

We have alredy used it to migrate the business logic from one option to another and reduce memory consumption and CPU load on the DB to move it to the application server so clustering of those elements is more effective.

We have also used it to modify and “spice up” some UIs with some AJAX/JavaScript widgets.

Page 31: Dynamic and rich web application using the good ol\' JVM - Java One Brazil

JavaOneSM Brazil 2010 | Dec. 9th | Sala 3 | 2:00 PM | http://www.oracle.com/br/javaonedevelop/en/

Thank you for your attention

Questions?