SlideShare a Scribd company logo
1 of 53
Download to read offline
Scala and Java EE 7 Development
Experiences
Peter A. Pilgrim
Independent Contractor, Java Champion
Biography
■  Completed Java Sybase
course in 1998
■  Founded JAVAWUG
2004-2010
■  Independent Contractor
■  Blue-chip business:
Digitas Lbi, Barclays
Retail, Transform
September 2013
Java EE 7
Developer
Handbook
•  Overview of Scala
•  Java EE 7 architecture and design
•  Using Gradle as a build tool
•  How to create beans in Scala with dependency injection
•  JAX-RS endpoints
•  Servlet Endpoints
•  JMS Messaging
•  Scala adoption advice and hints for sustainable team
development
“The right architecture to the right application. Not all of us work
for Facebook or Twitter. If you look at their "web site" the
navigation is quite simple… For them, statelessness and NoSQL is
mandatory. But when you work on a "web application” then you
deal with complex flow management. Their problem is elsewhere :
fewer users but complex long time running transactional flows.
Stateful architecture are mandatory.
Antonio Gonclaves
Why Java EE Lost and Spring Won
http://java.dzone.com/articles/why-java-ee-lost-and-spring
Scalable Language
12/05/2014 XeNoNiQUe.co.uk (c) 2011 7
Still has a very bright future
Purely Object-Oriented
Statically-typed
Functional
JVM Language
Typing Derived from “Pascal” Tree of
Computer Language
<variableName> [: [ <Type> ]
personName: String
taxRate: Float
density: Double
found: False
persion: Person
May 12, 2014 Xenonique ©2013 8
Variables and Values
Assignment less programming
Prefer val over var

var x = 10.0; x = 10 + x
val y = 10.0
val z: Float = x
var t: Int = 42; t = t * 2
9
Scala Class
class Person (

val firstName: String

val lastName: String,

val height: Float,

val age: Int ) { 

// Write your definition here 
}

May 12, 2014 Xenonique ©2013 10
Instances of Scala Classes

val p1 = new Person( "Billy",
"Mitchell", 5.10F, 42 )

val p2 = new Person( "Kat",
"Moon", 5.8F, 39 )
May 12, 2014 Xenonique ©2013 11
Companion Objects
object Person {
private records = List[Person]()
def apply(fn: String, ln: String,
h: Float, a: Int): Person = {
val p = new Person(fn, ln, h, a );
records = p :: records.reverse // O(1)
return p
}
def recordCount() = records.size 
}
May 12, 2014 Xenonique ©2013 12
Case Classes

class Transmission( driveTrain:
String )
May 12, 2014 Xenonique ©2013 13
Scala Functions

val isEven: (Int => Boolean) = (k: Int) => k % 2 == 0



•  Functions are values, values are object
•  Ergo, functions are objects in Scala

May 12, 2014 Xenonique ©2013 14
Scala Code
def uniqueSorted[Symbol]( p: List[Symbol] ): List[Symbol] = {
val myOrdering = 
Ordering.fromLessThan[Symbol]( 
_.toString < _.toString )
var acc = SortedSet.empty(myOrdering)

def compress0( q: List[Symbol] ): Unit = {
q match {
case Nil => Nil
case x :: xs => { acc += x ; compress0(xs) }
}
}

May 12, 2014 Xenonique ©2013 15
Functions are First Class
•  In Scala, functions are first class citizens
•  Functions can return functions
May 12, 2014 Xenonique ©2013 16
SBT
•  SBT is the de-facto build tool
•  Works with Maven
•  Incremental Compilation +1
•  DSL written in Scala +1
•  Plugins Available +1
•  Complex to Understand -1
May 12, 2014 Xenonique ©2013 17
Gradle
•  Gradle is written in Groovy
•  Gradle is a DSL too +1
•  Easier to Grok +1
•  Since v1.4 Gradle support incremental
compilation through Zinc
•  Not the de-facto standard -1
May 12, 2014 Xenonique ©2013 18
ENTERPRISE
DEVELOPMENT
Modern Practice
Java EE 7 Framework Updates
Interface Boundary
Endpoints
JAX RS 2.0
JMS 2.0
Bean Validation 1.1
Management and
Storage
EJB 3.2
CDI 1.1
JPA 2.1
Web and HTML
Service Endpoints
Servlet 3.1
WebSocket 1.0
JSF 2.2
JSON 1.0
CDI and Scala
trait Processor { 

def process( payload: DataValue ) : Unit

/* ... */ 
}

@ApplicationScoped
class DatastarProcessor extends Processor {
@Inject var dataStore: DataStore = _

override def process( payload: DataValue): Unit = { 

// Do something here
}
}
What about Java SE 8?
public interface PaymentIssuer {

public void allocate( int id );
}
What about Java SE 8?
@ApplicationScoped
public class CreditCardTicketTracker() {

@Inject PaymentIssuer issuer;



public void doWork( 

 
List<Ticket> ticketBatch ) {

}
}
What about Java SE 8?

public void doWork( List<Ticket> ticketBatch ) {

 
 DateTime dt = new DateTime().minusDays(2);

 
 ticketBatch.stream()

 
.filter(

 
 t -> t.isAvailable() &&

 
 t -> t.paymentType == PaymentType.CreditCard && 

 
 t.concertDate.before( dt ) )

 .map( t -> p.getAllocationId() )

 .forEach( allocationId -> issuer.allocate(allocationId));

}
Write Annotations as Java
// In the Java source tree (src/main/java)
import javax.inject.Qualifier;
import javax.interceptor.InterceptorBinding;
import java.lang.annotation.*;
import static java.lang.annotation.ElementType.*;

@Qualifier
@InterceptorBinding
@Target({METHOD, TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface PermanentStorage { }
public @interface CachedStorage { }
public @interface TransientStorage { }
Stock CDI Advice
•  CDI does works very well with Scala POJOs
•  CDI cannot instantiate companion objects!
•  CDI beans must have a default constructor
•  CDI does not understand case classes (but
see later …)
CDI Setter Injection
•  Take advantage of Scala’s @BeanProperty
annotation
@BeanProperty
var liveStatus:String = “Default”
@Inject
def setLiveStatus(a:String):Unit=???
CDI Scopes
// Prefer CDI scopes if you use JSF in Java EE
import javax.enterprise.context.RequestScoped
import javax.enterprise.context.SessionScoped
import javax.enterprise.context.ApplicationScoped

// Instead of
import javax.faces.bean.RequestScoped
import javax.faces.bean.SessionScoped
import javax.faces.bean.ApplicationScoped
Last Advice on CDI Proxies
•  Scala POJOs need a lifecycle scope
•  Always create default no args constructor
•  Cannot be final or have final members
– (Interaction between Java and Scala)
JSF Managed Beans
import javax.enterprise.context.RequestScoped
import javax.inject.Named

@Named @RequestScoped
class BasicFlow {
def serveResponse() = "endState.xml"
}
JSF XHTML Facelet View
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html ...>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core”>
<h:head> ... </h:head>
<h:body> ... </h:body>
</html>
JSF XHTML Facelet View
<h:body> ...
<h:form>
<h:commandButton 
action="#{basicFlow.serveResponse}”
value="Invoke Action" />
</h:form>
</h:body>
Demo CDI and Scala
Produces JMS Connections in Scala
class JMSResourceProducer { 
@Resource(name = "jms/OrderConnectionFactory")
private orderConnectionFactory: QueueConnectionFactory = _
@Produces @Order @Resource(name = "jms/OrderQueue")
private orderQueue: Queue = _

@Produces @Order
def createOrderConnection(): QueueConnection = 
orderConnectionFactory.createQueueConnection()

@Produces @Order
def createOrderSession(@Order conn:QueueConnection): QueueSession
= conn.createQueueSession(true, Session.AUTO_ACKNOWLEDGE)
}
Scala and JAX-RS
•  JAX-RS 2 annotations work with Scala
POJOS out of the box
•  Annotate on public methods
•  @GET, @POST, @PUT, @DELETE
•  @Produces, @Consumes
Use Qualifiers in Scala
// In the Scala source tree (src/main/scala)
@ApplicationScoped
@PermanentStorage
class DatastarProcessor extends Processor {
@Inject
var dataStore: DataStore = _

override def process( payload: DataValue):
Unit = { /* ... */ }
}
JAX-RS
@Path("/alldata")
class AllDataServiceEndpoint {
@Inject var fastService: FastService = _
@Inject var predictorService: PredictorService = _
@Context var request: HttpServletRequest = _

@Path("/item")
@GET @Produces(Array(APPLICATION_JSON))
def listServices = ???
}
JAX-RS
def listServices = {
val listServices = 

(fastService.configuredAllServices ++ 

 
predictorService.configuredAllServices) 

map { makeElement( _ ) }
Response.ok(listServices, 
MediaType.APPLICATION_JSON).build
}
}
Jackson, Scala & JSON Support
•  JAX-RS works well with Scala POJOs
•  JAX-RS and Java EE 7 provides JSON
providers only for Java POJOs
•  Use Jackson JSON Providers for seamless
support of case classes
Jackson Scala JAX-RS
@Singleton
@Provider
@Consumes(

Array(MediaType.APPLICATION_JSON, 

"application/*+json", "text/json"))
@Produces(

Array(MediaType.APPLICATION_JSON, 

"application/*+json", "text/json"))
class JacksonScalaContextResolver extends
JacksonJaxbJsonProvider(

JacksonScalaContextResolver.getObjectMapper, 

JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS)
Jackson Scala JAX-RS
object JacksonScalaContextResolver {
def getObjectMapper: ObjectMapper = {
val mapper = new ObjectMapper with ScalaObjectMapper
mapper.registerModule(new DefaultScalaModule)
mapper.configure(
DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, 
false)
mapper.setSerializationInclusion(Include.NON_NULL);
mapper
}
}
Open Source Integration Testing
Peter Muir, David Blewin and Aslak Knutsen and from Red Hat JBoss.
Demo Alternative
Demo Servlets, CDI & EJB
Java EE 7 Demo
EXECUTIVE SUMMARY
Digital by Default with Java
“If you're frustrated that you're not getting picked, one
plan is to up your game, to hustle harder, ... But in the
era of picking yourself, it seems to me that you're
better off finding a path that doesn't require you get
picked in order to succeed.”
Seth Godin,
Getting Picked (‘need to’ versus ‘want to’)
Run It Yourself
•  https://github.com/peterpilgrim/javacro
•  Download the source code, build and run
•  Feedback, welcomed!
Thank You!
The book:
http://www.packtpub.com/java-ee-7-
developer-handbook/book
Blog:
http://xenonique.co.uk/blog/
Twitter:
@peter_pilgrim
Creative Commons Attributions
http://www.flickr.com/photos/holstphoto/3371060720/
Photo of "Chip Pattern" by Ryan Holst, March, 2009
http://www.flickr.com/photos/scarygami/5489773527/lightbox/
Photo of "Pattern" by Scarygami
http://www.flickr.com/photos/christianhaugen/3486381680/sizes/l/in/photostream/
Photo of "Patterns in the Sand" by Christian Haugen
http://www.flickr.com/photos/krunkwerke/3840127296/
Photo of a series of punch cards which are strung together, to
control the pattern woven by the Jacquard loom. John R. Southern
Creative Commons Attributions
http://www.flickr.com/photos/josefstuefer/43867840/
Proof of Pattern messh "untitled" in tan by Josef Stuefer
http://www.flickr.com/photos/josefstuefer/43972554/
Proof of Pattern mesh "untitled" in blue by Josef Stuefer
http://www.flickr.com/photos/scott1723/6290151038/
Alter photo of "Tug of War 3" by Scott Anderson

More Related Content

What's hot

JAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) BridgeJAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) BridgeJosé Paumard
 
Web注入+http漏洞等描述
Web注入+http漏洞等描述Web注入+http漏洞等描述
Web注入+http漏洞等描述fangjiafu
 
Akka Actor presentation
Akka Actor presentationAkka Actor presentation
Akka Actor presentationGene Chang
 
Demystifying Oak Search
Demystifying Oak SearchDemystifying Oak Search
Demystifying Oak SearchJustin Edelson
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at TwitterAlex Payne
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016Codemotion
 
Connect.Tech- Swift Memory Management
Connect.Tech- Swift Memory ManagementConnect.Tech- Swift Memory Management
Connect.Tech- Swift Memory Managementstable|kernel
 
Scala for scripting
Scala for scriptingScala for scripting
Scala for scriptingmichid
 
Scala introduction
Scala introductionScala introduction
Scala introductionvito jeng
 
The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論scalaconfjp
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on AndroidTomáš Kypta
 
Connect.Tech- Level Up Your Game With TravisCI
Connect.Tech- Level Up Your Game With TravisCIConnect.Tech- Level Up Your Game With TravisCI
Connect.Tech- Level Up Your Game With TravisCIstable|kernel
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsBartosz Kosarzycki
 
Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Derek Chen-Becker
 
Moving from JFreeChart to JavaFX with JavaFX Chart Extensions
Moving from JFreeChart to JavaFX with JavaFX Chart ExtensionsMoving from JFreeChart to JavaFX with JavaFX Chart Extensions
Moving from JFreeChart to JavaFX with JavaFX Chart ExtensionsBruce Schubert
 
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor ExtensionsConnect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensionsstable|kernel
 

What's hot (20)

JAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) BridgeJAX-RS and CDI Bike the (Reactive) Bridge
JAX-RS and CDI Bike the (Reactive) Bridge
 
Web注入+http漏洞等描述
Web注入+http漏洞等描述Web注入+http漏洞等描述
Web注入+http漏洞等描述
 
Akka Actor presentation
Akka Actor presentationAkka Actor presentation
Akka Actor presentation
 
Demystifying Oak Search
Demystifying Oak SearchDemystifying Oak Search
Demystifying Oak Search
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
 
55 New Features in Java 7
55 New Features in Java 755 New Features in Java 7
55 New Features in Java 7
 
Connect.Tech- Swift Memory Management
Connect.Tech- Swift Memory ManagementConnect.Tech- Swift Memory Management
Connect.Tech- Swift Memory Management
 
Scala for scripting
Scala for scriptingScala for scripting
Scala for scripting
 
Java 5 and 6 New Features
Java 5 and 6 New FeaturesJava 5 and 6 New Features
Java 5 and 6 New Features
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on Android
 
Connect.Tech- Level Up Your Game With TravisCI
Connect.Tech- Level Up Your Game With TravisCIConnect.Tech- Level Up Your Game With TravisCI
Connect.Tech- Level Up Your Game With TravisCI
 
Java 7 New Features
Java 7 New FeaturesJava 7 New Features
Java 7 New Features
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010
 
Moving from JFreeChart to JavaFX with JavaFX Chart Extensions
Moving from JFreeChart to JavaFX with JavaFX Chart ExtensionsMoving from JFreeChart to JavaFX with JavaFX Chart Extensions
Moving from JFreeChart to JavaFX with JavaFX Chart Extensions
 
scala
scalascala
scala
 
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor ExtensionsConnect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
 

Similar to JavaCro 2014 Scala and Java EE 7 Development Experiences

Scaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with ScalaScaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with ScalaOstap Andrusiv
 
Using spark 1.2 with Java 8 and Cassandra
Using spark 1.2 with Java 8 and CassandraUsing spark 1.2 with Java 8 and Cassandra
Using spark 1.2 with Java 8 and CassandraDenis Dus
 
Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014
Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014
Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014Roger Huang
 
PofEAA and SQLAlchemy
PofEAA and SQLAlchemyPofEAA and SQLAlchemy
PofEAA and SQLAlchemyInada Naoki
 
Singpore Oracle Sessions III - What is truly useful in Oracle Database 12c fo...
Singpore Oracle Sessions III - What is truly useful in Oracle Database 12c fo...Singpore Oracle Sessions III - What is truly useful in Oracle Database 12c fo...
Singpore Oracle Sessions III - What is truly useful in Oracle Database 12c fo...Lucas Jellema
 
Xebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_finalXebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_finalUrs Peter
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvmIsaias Barroso
 
Big Data processing with Spark, Scala or Java?
Big Data processing with Spark, Scala or Java?Big Data processing with Spark, Scala or Java?
Big Data processing with Spark, Scala or Java?Erik-Berndt Scheper
 
Adding geospatial features to a java web app
Adding geospatial features to a java web appAdding geospatial features to a java web app
Adding geospatial features to a java web appMatti Tahvonen
 
Intro to Spark and Spark SQL
Intro to Spark and Spark SQLIntro to Spark and Spark SQL
Intro to Spark and Spark SQLjeykottalam
 
Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)Davide Cerbo
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryTatsuhiko Miyagawa
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejsNick Lee
 
What's new and noteworthy in Java EE 8?
What's new and noteworthy in Java EE 8?What's new and noteworthy in Java EE 8?
What's new and noteworthy in Java EE 8?gedoplan
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalMichael Stal
 

Similar to JavaCro 2014 Scala and Java EE 7 Development Experiences (20)

Spring data requery
Spring data requerySpring data requery
Spring data requery
 
Scala and Spring
Scala and SpringScala and Spring
Scala and Spring
 
Scaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with ScalaScaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with Scala
 
Kpi driven-java-development
Kpi driven-java-developmentKpi driven-java-development
Kpi driven-java-development
 
Using spark 1.2 with Java 8 and Cassandra
Using spark 1.2 with Java 8 and CassandraUsing spark 1.2 with Java 8 and Cassandra
Using spark 1.2 with Java 8 and Cassandra
 
Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014
Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014
Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014
 
Scala 20140715
Scala 20140715Scala 20140715
Scala 20140715
 
PofEAA and SQLAlchemy
PofEAA and SQLAlchemyPofEAA and SQLAlchemy
PofEAA and SQLAlchemy
 
Singpore Oracle Sessions III - What is truly useful in Oracle Database 12c fo...
Singpore Oracle Sessions III - What is truly useful in Oracle Database 12c fo...Singpore Oracle Sessions III - What is truly useful in Oracle Database 12c fo...
Singpore Oracle Sessions III - What is truly useful in Oracle Database 12c fo...
 
Xebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_finalXebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_final
 
Json generation
Json generationJson generation
Json generation
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvm
 
Big Data processing with Spark, Scala or Java?
Big Data processing with Spark, Scala or Java?Big Data processing with Spark, Scala or Java?
Big Data processing with Spark, Scala or Java?
 
Adding geospatial features to a java web app
Adding geospatial features to a java web appAdding geospatial features to a java web app
Adding geospatial features to a java web app
 
Intro to Spark and Spark SQL
Intro to Spark and Spark SQLIntro to Spark and Spark SQL
Intro to Spark and Spark SQL
 
Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 
What's new and noteworthy in Java EE 8?
What's new and noteworthy in Java EE 8?What's new and noteworthy in Java EE 8?
What's new and noteworthy in Java EE 8?
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
 

More from Peter Pilgrim

Devoxx 2019 - Why we pair?
Devoxx 2019 - Why we pair?Devoxx 2019 - Why we pair?
Devoxx 2019 - Why we pair?Peter Pilgrim
 
Cloud native java are we there yet go tech world 2019
Cloud native java   are we there yet  go tech world 2019Cloud native java   are we there yet  go tech world 2019
Cloud native java are we there yet go tech world 2019Peter Pilgrim
 
LJC 2018 - PEAT UK - Java EE - Ah, ah, ah! Staying Alive!
LJC 2018 - PEAT UK - Java EE - Ah, ah, ah! Staying Alive!LJC 2018 - PEAT UK - Java EE - Ah, ah, ah! Staying Alive!
LJC 2018 - PEAT UK - Java EE - Ah, ah, ah! Staying Alive!Peter Pilgrim
 
CON6148 - You Are Not Cut Out To Be A Java Contractor - JavaOne 2017
CON6148 - You Are Not Cut Out To Be A Java Contractor - JavaOne 2017CON6148 - You Are Not Cut Out To Be A Java Contractor - JavaOne 2017
CON6148 - You Are Not Cut Out To Be A Java Contractor - JavaOne 2017Peter Pilgrim
 
JavaOne 2015 CON5211 Digital Java EE 7 with JSF Conversations, Flows, and CDI...
JavaOne 2015 CON5211 Digital Java EE 7 with JSF Conversations, Flows, and CDI...JavaOne 2015 CON5211 Digital Java EE 7 with JSF Conversations, Flows, and CDI...
JavaOne 2015 CON5211 Digital Java EE 7 with JSF Conversations, Flows, and CDI...Peter Pilgrim
 
Java EE & Glass Fish User Group: Digital JavaEE 7 - New and Noteworthy
Java EE & Glass Fish User Group: Digital JavaEE 7 - New and NoteworthyJava EE & Glass Fish User Group: Digital JavaEE 7 - New and Noteworthy
Java EE & Glass Fish User Group: Digital JavaEE 7 - New and NoteworthyPeter Pilgrim
 
AOTB2014: Agile Testing on the Java Platform
AOTB2014: Agile Testing on the Java PlatformAOTB2014: Agile Testing on the Java Platform
AOTB2014: Agile Testing on the Java PlatformPeter Pilgrim
 
JavaCro 2014 Digital Development with Java EE and Java Platform
JavaCro 2014 Digital Development with Java EE and Java PlatformJavaCro 2014 Digital Development with Java EE and Java Platform
JavaCro 2014 Digital Development with Java EE and Java PlatformPeter Pilgrim
 
ACCU 2013 Taking Scala into the Enterpise
ACCU 2013 Taking Scala into the EnterpiseACCU 2013 Taking Scala into the Enterpise
ACCU 2013 Taking Scala into the EnterpisePeter Pilgrim
 
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...Peter Pilgrim
 
JavaOne 2011 Progressive JavaFX 2.0 Custom Components
JavaOne 2011 Progressive JavaFX 2.0 Custom ComponentsJavaOne 2011 Progressive JavaFX 2.0 Custom Components
JavaOne 2011 Progressive JavaFX 2.0 Custom ComponentsPeter Pilgrim
 
ACCU 2011 Introduction to Scala: An Object Functional Programming Language
ACCU 2011 Introduction to Scala: An Object Functional Programming LanguageACCU 2011 Introduction to Scala: An Object Functional Programming Language
ACCU 2011 Introduction to Scala: An Object Functional Programming LanguagePeter Pilgrim
 

More from Peter Pilgrim (12)

Devoxx 2019 - Why we pair?
Devoxx 2019 - Why we pair?Devoxx 2019 - Why we pair?
Devoxx 2019 - Why we pair?
 
Cloud native java are we there yet go tech world 2019
Cloud native java   are we there yet  go tech world 2019Cloud native java   are we there yet  go tech world 2019
Cloud native java are we there yet go tech world 2019
 
LJC 2018 - PEAT UK - Java EE - Ah, ah, ah! Staying Alive!
LJC 2018 - PEAT UK - Java EE - Ah, ah, ah! Staying Alive!LJC 2018 - PEAT UK - Java EE - Ah, ah, ah! Staying Alive!
LJC 2018 - PEAT UK - Java EE - Ah, ah, ah! Staying Alive!
 
CON6148 - You Are Not Cut Out To Be A Java Contractor - JavaOne 2017
CON6148 - You Are Not Cut Out To Be A Java Contractor - JavaOne 2017CON6148 - You Are Not Cut Out To Be A Java Contractor - JavaOne 2017
CON6148 - You Are Not Cut Out To Be A Java Contractor - JavaOne 2017
 
JavaOne 2015 CON5211 Digital Java EE 7 with JSF Conversations, Flows, and CDI...
JavaOne 2015 CON5211 Digital Java EE 7 with JSF Conversations, Flows, and CDI...JavaOne 2015 CON5211 Digital Java EE 7 with JSF Conversations, Flows, and CDI...
JavaOne 2015 CON5211 Digital Java EE 7 with JSF Conversations, Flows, and CDI...
 
Java EE & Glass Fish User Group: Digital JavaEE 7 - New and Noteworthy
Java EE & Glass Fish User Group: Digital JavaEE 7 - New and NoteworthyJava EE & Glass Fish User Group: Digital JavaEE 7 - New and Noteworthy
Java EE & Glass Fish User Group: Digital JavaEE 7 - New and Noteworthy
 
AOTB2014: Agile Testing on the Java Platform
AOTB2014: Agile Testing on the Java PlatformAOTB2014: Agile Testing on the Java Platform
AOTB2014: Agile Testing on the Java Platform
 
JavaCro 2014 Digital Development with Java EE and Java Platform
JavaCro 2014 Digital Development with Java EE and Java PlatformJavaCro 2014 Digital Development with Java EE and Java Platform
JavaCro 2014 Digital Development with Java EE and Java Platform
 
ACCU 2013 Taking Scala into the Enterpise
ACCU 2013 Taking Scala into the EnterpiseACCU 2013 Taking Scala into the Enterpise
ACCU 2013 Taking Scala into the Enterpise
 
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...
Devoxx UK 2013 Test-Driven Development with JavaEE 7, Arquillian and Embedded...
 
JavaOne 2011 Progressive JavaFX 2.0 Custom Components
JavaOne 2011 Progressive JavaFX 2.0 Custom ComponentsJavaOne 2011 Progressive JavaFX 2.0 Custom Components
JavaOne 2011 Progressive JavaFX 2.0 Custom Components
 
ACCU 2011 Introduction to Scala: An Object Functional Programming Language
ACCU 2011 Introduction to Scala: An Object Functional Programming LanguageACCU 2011 Introduction to Scala: An Object Functional Programming Language
ACCU 2011 Introduction to Scala: An Object Functional Programming Language
 

Recently uploaded

Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEaurabinda banchhor
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxruthvilladarez
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 

Recently uploaded (20)

Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSE
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 

JavaCro 2014 Scala and Java EE 7 Development Experiences

  • 1. Scala and Java EE 7 Development Experiences Peter A. Pilgrim Independent Contractor, Java Champion
  • 2. Biography ■  Completed Java Sybase course in 1998 ■  Founded JAVAWUG 2004-2010 ■  Independent Contractor ■  Blue-chip business: Digitas Lbi, Barclays Retail, Transform
  • 3. September 2013 Java EE 7 Developer Handbook
  • 4. •  Overview of Scala •  Java EE 7 architecture and design •  Using Gradle as a build tool •  How to create beans in Scala with dependency injection •  JAX-RS endpoints •  Servlet Endpoints •  JMS Messaging •  Scala adoption advice and hints for sustainable team development
  • 5. “The right architecture to the right application. Not all of us work for Facebook or Twitter. If you look at their "web site" the navigation is quite simple… For them, statelessness and NoSQL is mandatory. But when you work on a "web application” then you deal with complex flow management. Their problem is elsewhere : fewer users but complex long time running transactional flows. Stateful architecture are mandatory. Antonio Gonclaves Why Java EE Lost and Spring Won http://java.dzone.com/articles/why-java-ee-lost-and-spring
  • 6.
  • 7. Scalable Language 12/05/2014 XeNoNiQUe.co.uk (c) 2011 7 Still has a very bright future Purely Object-Oriented Statically-typed Functional JVM Language
  • 8. Typing Derived from “Pascal” Tree of Computer Language <variableName> [: [ <Type> ] personName: String taxRate: Float density: Double found: False persion: Person May 12, 2014 Xenonique ©2013 8
  • 9. Variables and Values Assignment less programming Prefer val over var var x = 10.0; x = 10 + x val y = 10.0 val z: Float = x var t: Int = 42; t = t * 2 9
  • 10. Scala Class class Person ( val firstName: String val lastName: String, val height: Float, val age: Int ) { // Write your definition here } May 12, 2014 Xenonique ©2013 10
  • 11. Instances of Scala Classes val p1 = new Person( "Billy", "Mitchell", 5.10F, 42 ) val p2 = new Person( "Kat", "Moon", 5.8F, 39 ) May 12, 2014 Xenonique ©2013 11
  • 12. Companion Objects object Person { private records = List[Person]() def apply(fn: String, ln: String, h: Float, a: Int): Person = { val p = new Person(fn, ln, h, a ); records = p :: records.reverse // O(1) return p } def recordCount() = records.size } May 12, 2014 Xenonique ©2013 12
  • 13. Case Classes class Transmission( driveTrain: String ) May 12, 2014 Xenonique ©2013 13
  • 14. Scala Functions val isEven: (Int => Boolean) = (k: Int) => k % 2 == 0 •  Functions are values, values are object •  Ergo, functions are objects in Scala May 12, 2014 Xenonique ©2013 14
  • 15. Scala Code def uniqueSorted[Symbol]( p: List[Symbol] ): List[Symbol] = { val myOrdering = Ordering.fromLessThan[Symbol]( _.toString < _.toString ) var acc = SortedSet.empty(myOrdering) def compress0( q: List[Symbol] ): Unit = { q match { case Nil => Nil case x :: xs => { acc += x ; compress0(xs) } } } May 12, 2014 Xenonique ©2013 15
  • 16. Functions are First Class •  In Scala, functions are first class citizens •  Functions can return functions May 12, 2014 Xenonique ©2013 16
  • 17. SBT •  SBT is the de-facto build tool •  Works with Maven •  Incremental Compilation +1 •  DSL written in Scala +1 •  Plugins Available +1 •  Complex to Understand -1 May 12, 2014 Xenonique ©2013 17
  • 18. Gradle •  Gradle is written in Groovy •  Gradle is a DSL too +1 •  Easier to Grok +1 •  Since v1.4 Gradle support incremental compilation through Zinc •  Not the de-facto standard -1 May 12, 2014 Xenonique ©2013 18
  • 20.
  • 21.
  • 22. Java EE 7 Framework Updates Interface Boundary Endpoints JAX RS 2.0 JMS 2.0 Bean Validation 1.1 Management and Storage EJB 3.2 CDI 1.1 JPA 2.1 Web and HTML Service Endpoints Servlet 3.1 WebSocket 1.0 JSF 2.2 JSON 1.0
  • 23. CDI and Scala trait Processor { def process( payload: DataValue ) : Unit /* ... */ } @ApplicationScoped class DatastarProcessor extends Processor { @Inject var dataStore: DataStore = _ override def process( payload: DataValue): Unit = { // Do something here } }
  • 24. What about Java SE 8? public interface PaymentIssuer { public void allocate( int id ); }
  • 25. What about Java SE 8? @ApplicationScoped public class CreditCardTicketTracker() { @Inject PaymentIssuer issuer; public void doWork( List<Ticket> ticketBatch ) { } }
  • 26. What about Java SE 8? public void doWork( List<Ticket> ticketBatch ) { DateTime dt = new DateTime().minusDays(2); ticketBatch.stream() .filter( t -> t.isAvailable() && t -> t.paymentType == PaymentType.CreditCard && t.concertDate.before( dt ) ) .map( t -> p.getAllocationId() ) .forEach( allocationId -> issuer.allocate(allocationId)); }
  • 27. Write Annotations as Java // In the Java source tree (src/main/java) import javax.inject.Qualifier; import javax.interceptor.InterceptorBinding; import java.lang.annotation.*; import static java.lang.annotation.ElementType.*; @Qualifier @InterceptorBinding @Target({METHOD, TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface PermanentStorage { } public @interface CachedStorage { } public @interface TransientStorage { }
  • 28. Stock CDI Advice •  CDI does works very well with Scala POJOs •  CDI cannot instantiate companion objects! •  CDI beans must have a default constructor •  CDI does not understand case classes (but see later …)
  • 29. CDI Setter Injection •  Take advantage of Scala’s @BeanProperty annotation @BeanProperty var liveStatus:String = “Default” @Inject def setLiveStatus(a:String):Unit=???
  • 30. CDI Scopes // Prefer CDI scopes if you use JSF in Java EE import javax.enterprise.context.RequestScoped import javax.enterprise.context.SessionScoped import javax.enterprise.context.ApplicationScoped // Instead of import javax.faces.bean.RequestScoped import javax.faces.bean.SessionScoped import javax.faces.bean.ApplicationScoped
  • 31. Last Advice on CDI Proxies •  Scala POJOs need a lifecycle scope •  Always create default no args constructor •  Cannot be final or have final members – (Interaction between Java and Scala)
  • 32. JSF Managed Beans import javax.enterprise.context.RequestScoped import javax.inject.Named @Named @RequestScoped class BasicFlow { def serveResponse() = "endState.xml" }
  • 33. JSF XHTML Facelet View <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html ...> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:f="http://xmlns.jcp.org/jsf/core”> <h:head> ... </h:head> <h:body> ... </h:body> </html>
  • 34. JSF XHTML Facelet View <h:body> ... <h:form> <h:commandButton action="#{basicFlow.serveResponse}” value="Invoke Action" /> </h:form> </h:body>
  • 35. Demo CDI and Scala
  • 36. Produces JMS Connections in Scala class JMSResourceProducer { @Resource(name = "jms/OrderConnectionFactory") private orderConnectionFactory: QueueConnectionFactory = _ @Produces @Order @Resource(name = "jms/OrderQueue") private orderQueue: Queue = _ @Produces @Order def createOrderConnection(): QueueConnection = orderConnectionFactory.createQueueConnection() @Produces @Order def createOrderSession(@Order conn:QueueConnection): QueueSession = conn.createQueueSession(true, Session.AUTO_ACKNOWLEDGE) }
  • 37. Scala and JAX-RS •  JAX-RS 2 annotations work with Scala POJOS out of the box •  Annotate on public methods •  @GET, @POST, @PUT, @DELETE •  @Produces, @Consumes
  • 38. Use Qualifiers in Scala // In the Scala source tree (src/main/scala) @ApplicationScoped @PermanentStorage class DatastarProcessor extends Processor { @Inject var dataStore: DataStore = _ override def process( payload: DataValue): Unit = { /* ... */ } }
  • 39. JAX-RS @Path("/alldata") class AllDataServiceEndpoint { @Inject var fastService: FastService = _ @Inject var predictorService: PredictorService = _ @Context var request: HttpServletRequest = _ @Path("/item") @GET @Produces(Array(APPLICATION_JSON)) def listServices = ??? }
  • 40. JAX-RS def listServices = { val listServices = (fastService.configuredAllServices ++ predictorService.configuredAllServices) map { makeElement( _ ) } Response.ok(listServices, MediaType.APPLICATION_JSON).build } }
  • 41. Jackson, Scala & JSON Support •  JAX-RS works well with Scala POJOs •  JAX-RS and Java EE 7 provides JSON providers only for Java POJOs •  Use Jackson JSON Providers for seamless support of case classes
  • 42. Jackson Scala JAX-RS @Singleton @Provider @Consumes( Array(MediaType.APPLICATION_JSON, "application/*+json", "text/json")) @Produces( Array(MediaType.APPLICATION_JSON, "application/*+json", "text/json")) class JacksonScalaContextResolver extends JacksonJaxbJsonProvider( JacksonScalaContextResolver.getObjectMapper, JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS)
  • 43. Jackson Scala JAX-RS object JacksonScalaContextResolver { def getObjectMapper: ObjectMapper = { val mapper = new ObjectMapper with ScalaObjectMapper mapper.registerModule(new DefaultScalaModule) mapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) mapper.setSerializationInclusion(Include.NON_NULL); mapper } }
  • 44. Open Source Integration Testing Peter Muir, David Blewin and Aslak Knutsen and from Red Hat JBoss.
  • 47. Java EE 7 Demo
  • 48. EXECUTIVE SUMMARY Digital by Default with Java
  • 49. “If you're frustrated that you're not getting picked, one plan is to up your game, to hustle harder, ... But in the era of picking yourself, it seems to me that you're better off finding a path that doesn't require you get picked in order to succeed.” Seth Godin, Getting Picked (‘need to’ versus ‘want to’)
  • 50. Run It Yourself •  https://github.com/peterpilgrim/javacro •  Download the source code, build and run •  Feedback, welcomed!
  • 52. Creative Commons Attributions http://www.flickr.com/photos/holstphoto/3371060720/ Photo of "Chip Pattern" by Ryan Holst, March, 2009 http://www.flickr.com/photos/scarygami/5489773527/lightbox/ Photo of "Pattern" by Scarygami http://www.flickr.com/photos/christianhaugen/3486381680/sizes/l/in/photostream/ Photo of "Patterns in the Sand" by Christian Haugen http://www.flickr.com/photos/krunkwerke/3840127296/ Photo of a series of punch cards which are strung together, to control the pattern woven by the Jacquard loom. John R. Southern
  • 53. Creative Commons Attributions http://www.flickr.com/photos/josefstuefer/43867840/ Proof of Pattern messh "untitled" in tan by Josef Stuefer http://www.flickr.com/photos/josefstuefer/43972554/ Proof of Pattern mesh "untitled" in blue by Josef Stuefer http://www.flickr.com/photos/scott1723/6290151038/ Alter photo of "Tug of War 3" by Scott Anderson