Adam Bien's Weblog

My JavaOne 2015 Session Schedule

Conference: JavaOne
Session Type: User Group Forum Session
Session ID: UGF10284
Session Title: Building Nanoservices with Java EE and Java 8
Venue / Room: Moscone South—307
Date and Time: 10/25/15, 18:30 - 19:15

Conference: JavaOne
Session Type: User Group Forum Session
Session ID: UGF10300
Session Title: Being Productive with Maven, Java EE, and the Cloud
Venue / Room: Moscone South—310
Date and Time: 10/25/15, 11:00 - 11:45

Conference: JavaOne
Session Type: BOF (Birds-of-a-Feather) Session
Session ID: BOF1849
Session Title: Most Popular Java (EE) Q&A: Airhacks.tv Live
Venue / Room: Parc 55—Cyril Magnin II/III
Date and Time: 10/26/15, 19:00 - 19:45

Conference: JavaOne
Session Type: Conference Session
Session ID: CON1851
Session Title: From Macro to Micro(Services) and Back: Onstage Hacking with Java EE 7
Venue / Room: Parc 55—Cyril Magnin II/III
Date and Time: 10/26/15, 17:30 - 18:30

Conference: JavaOne
Session Type: Conference Session
Session ID: CON6699
Session Title: What's the Best IDE for Java EE?
Venue / Room: Hilton—Imperial Ballroom A
Date and Time: 10/27/15, 12:30 - 13:30

Conference: JavaOne
Session Type: Conference Session
Session ID: CON1850
Session Title: Nashorn: The “42” for Startups and Enterprises
Venue / Room: Hilton—Continental Ballroom 5
Date and Time: 10/28/15, 10:00 - 11:00


NEW dates, new workshop: Java EE 7 Workshops: Bootstrap, Effective, Architectures, JavaScript Bootstrap and HTML 5 December, 7th-11th
NEW: Effective Java EE 7 -- Available For Streaming

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Rulz For EntityManager v0.0.2 and Rulz For JAX-RS Released v0.0.3

New releases of Rulz EntityManager and Rulz JAX-RS are available in maven central.

JAX-RS provider comes with three custom matchers (successful(), noContent() and created()):


import static com.airhacks.rulz.jaxrsclient.HttpMatchers.successful;

public class JAXRSClientProviderTest {

    @Rule
    public JAXRSClientProvider provider = JAXRSClientProvider.buildWithURI("http://www.java.com");

    @Test
    public void pingJavaAndVerifyWithMatcher() {

        Response response = (...)
        assertThat(response, is(successful()));
    }


Now the whole library comprises 2 classes...

The Rulz For EntityManager comes with no additional features -- just a superfluous persistence.xml was removed from the project.

See Rulz in episode 5 in the online version of the Effective Java EE 7 workshop.


NEW dates, new workshop: Java EE 7 Workshops: Bootstrap, Effective, Architectures, JavaScript Bootstrap and HTML 5 December, 7th-11th
NEW: Effective Java EE 7 -- Available For Streaming

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Java EE 7: Sending JSON Objects Over WebSockets

Java EE 7 and particularly JSR 356: Java API for WebSockets supports Encoders to serialize any custom object into WebSocket stream. With JSR 353: Java API for JSON Processing the conversion between JsonObject instances and streams is straightforward:


import java.io.IOException;
import java.io.Writer;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonWriter;
import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;

public class JsonEncoder implements Encoder.TextStream<JsonObject> {

    @Override
    public void init(EndpointConfig config) {}

    @Override
    public void encode(JsonObject payload, Writer writer) throws EncodeException, IOException {
        try (JsonWriter jsonWriter = Json.createWriter(writer)) {
            jsonWriter.writeObject(payload);
        }
    }

    @Override
    public void destroy() {}
}


The Encoder instance needs to be registered with the @ServerEndpoint annotation:


[...]
@ServerEndpoint(value = "/changes", encoders = {JsonEncoder.class})
public class ToDoChangeTracker {

    private Session session;

    @OnOpen
    public void onOpen(Session session) {
        this.session = session;
    }

    @OnClose
    public void onClose() {
        this.session = null;
    }

    public void onToDoChange([...]) throws EncodeException {
        if (this.session != null && this.session.isOpen()) {
            try {

                JsonObject event = Json.createObjectBuilder().
                        add("name",[...]).
                        build();
                this.session.getBasicRemote().sendObject(event);

            } catch (IOException ex) {
                //we ignore this
            }
        }
    }

}

This example was taken from the 38th episode of the Effective Java EE Online Workshop. Sources are available from github.com/AdamBien/doit


NEW dates, new workshop: Java EE 7 Workshops: Bootstrap, Effective, Architectures, JavaScript Bootstrap and HTML 5 December, 7th-11th
NEW: Effective Java EE 7 -- Available For Streaming

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

From #2 To #1: Java Stronger In The Lead

Java gained 4.29% on popularity in one year and now Java is leading again the Tiobe programming language index. Seems like Java is not only hot on github... Also an interesting observation:

"[...]Surprisingly or may be not, Java is consuming a large part of the market share that Objective-C is losing, while Objective-C's successor Swift was supposed to do this [...]"
From: [Tiobe Index for August 2015]

Big thanks to Samuel Santos @samaxes for the hint.


NEW dates, new workshop: Java EE 7 Workshops: Bootstrap, Effective, Architectures, JavaScript Bootstrap and HTML 5 December, 7th-11th
NEW: Effective Java EE 7 -- Available For Streaming

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

JUGs, Conferences and (Streaming) Events

  1. August, 28th, 12:45 pm, Free Live Streaming: "A Note On Java EE Testing" for codepot.pl conference.
  2. September, 3rd, Zurich, Workshop: "Genug ASCII-User Interfaces mit Java EE 7"
  3. September, 14th, 6 pm (CET) Airhacks Live Questions and Answers streaming show. Ask questions now. Also see: archives
  4. September, 16th, evening: free Session: "Java EE 7 — Simply The Best". Stay tuned
  5. September, 17th, evening. Fee JUG Streaming session for JUG Gothenborg. Stay tuned.
  6. October, 6th, 9am, Hannover, Java Forum Nord, Conference Keynote
  7. October 25–29, 2015, San Francisco, JavaOne Conference. Sessions: From Macro to Micro(Services) and Back: Onstage Hacking with Java EE 7 [CON1851], Most Popular Java (EE) Q&A: Airhacks.tv Live [BOF1849], Nashorn: The “42” for Startups and Enterprises [CON1850], Being Productive with Maven, Java EE, and the Cloud [UGF10300], Building Nanoservices with Java EE and Java 8 [UGF10284], What's the Best IDE for Java EE? [CON6699]
  8. November, 3rd, Munich, w-jax conference. Sessions: "Enterprise Scripting mit Nashorn: Tipps & Tricks live on Stage" and "Transactions? ACID, XA, BASE or what?"
  9. December 7th-11th. Airhacks Java EE Workshops at MUC Airport. If Munich is too far, try the streaming or download version: Effective Java EE


NEW dates, new workshop: Java EE 7 Workshops: Bootstrap, Effective, Architectures, JavaScript Bootstrap and HTML 5 December, 7th-11th
NEW: Effective Java EE 7 -- Available For Streaming

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Running JavaFX On Mobile Devices With Gluon And Afterburner

Johan, could you please briefly introduce yourself? Why do you like JavaFX?

I am a Java developer, working with Java since it was released. From day 1, I was interested in running Java on small devices. When Enterprise Java started to become popular, my interest moved into combining the world of the small devices with the world of the large back-end systems. Today, that translates into combining JavaFX on embedded, mobile and desktop with Java EE and Cloud systems.

I think JavaFX is important to many Java Enterprise developers. At this moment, many Java Enterprise developers are using a framework to create web pages, based on the business functionality they have to provide. However, there is a clear evolution towards mobile. People and also companies are today rather using mobile devices (phones and tablets) instead of desktops and laptops to do their job.
On mobile, native apps are much more valued than sites that are viewed via a web browser. Hence, most of the business transactions in the future will start from native mobile applications.
Good enough, JavaFX is a perfect platform for writing native mobile applications. And that is great news for all those Java Enterprise developers! They can use their favorite Java language, and still address the future (mobile) needs of their customers. Moreover, thanks to the cross-platform functionality of JavaFX, their client application works on all mobile devices. There is no need to write different versions of the business logic, but there is also no need to write different versions of the user interface. It is really easy to create and to maintain a JavaFX client application that is truly and completely cross-platform.

You ported afteburner.fx to mobile. Was it hard?

No, that was easy. Afterburner.fx is well-structured and uses a few classes only. Also, JavaFX 8 on mobile supports almost the entire JavaFX 8 API. Since JavaFX applications currently run on top of Dalvik, though, we can not use the Stream API's and I had to replace those Java 8 API's with Java 7 API's.

How did you find afterburner? Why do you decided to use it?

There are a number of ideas on how to use enterprise functionality in JavaFX and it is not easy to find the perfect balance between known and trusted enterprise patterns on one side, and client restrictions on the other side. In general, I think developers have to realize that even though client CPU's might be very performant, there are still huge differences between server environments (in a cloud or dedicated datacenter) and client systems.
Afterburner provides an excellent mix, as it allows for Injection to be used, without the need of a complex framework. It is probably the simplest yet functional MVP framework for JavaFX. For server-side projects, I'm always very cautious to not include external dependencies that are not really needed. On the client, I'm even more careful about this.
The Afterburner framework is very small, but it can easily be extended for specific needs. This is important on clients in general, and mobile clients in particular.

What is gluonhq.com? How afterburner is related to gluonhq.com?

I earlier said that JavaFX provides an excellent platform for Java developers to create Java clients applications that work on all kinds of client, and that provide the business functionality that in the past would exclusively be offered via a web interface. While JavaFX is really great, there are a number of issues Java Enterprise developers will probably encounter. With Gluon, we are trying to fill this gap.
Gluon provides products and services for Java Client development. Our tools extend the JavaFX functionality, and bring it to the world of mobile clients as well. JavaFX, which essentially is the standard Java Component for Java on the Client, provides a great set of API's for creating and managing user interfaces. The Gluon products extend this functionality in two directions:

  • With Charm, our client library, it becomes easy to create compelling user interfaces that look excellent on mobile devices, as Charm provides a Material Design look and feel. Also, Charm provides the client API to synchronize data across clients, and to store data remotely in a JavaFX friendly way (by leveraging concepts as Observable, and taking into account the Threading issues that might occur in a JavaFX application)
  • With Gluon Cloud, we manage the data that needs to be stored or synchronized. Gluon Cloud connects client devices with each other, with its persistent storage, or with customer-specific enterprise systems or cloud providers.

What was your coolest Java EE project?

That is a very difficult question, as Enterprise Java changed considerable over the past years. Today, Java EE development is much smoother and easy than it used to be. I do remember we did a large scale voting application in 2010, with thousands of concurrent users. This was our first large-scale deployment of GlassFish on Amazon EC2 infrastructure. It was really exciting to watch Google Analytics Real-Time and see how the number of concurrent users went up while the 2 GlassFish instances were holding fine.

What was your coolest Java FX project?

We have a number of really cool customer projects that I am not allowed to discuss, unfortunately. Apart from the Gluon products we are developing, we have this nice kiosk application we created for CultuurNet Vlaanderen. We run a JavaFX application on an embedded device with an NFC reader, and when people swipe their card, we send this to a back-end. The monitoring of these devices is also done by a JavaFX application we created.
We have a number of similar, form-based applications that we are working on for customers that want to use mobile devices for their employees.
Another cool project we are currently working on, is based on OpenMapFX. For a customer, we provide location-based functionality on top of the geo-maps that are rendered by OpenMapFX.

Any resources, links, ideas you can share with us?

I really recommend Java Enterprise developers to create a simple mobile JavaFX Application, and connect that to their backend system. Gluon currently provides plugins for NetBeans and IntelliJ to make this JavaFX development really easy -- see http://docs.gluonhq.com/charm/latest/#_ide_plugins for more information.
Developers that are interested in creating JavaFX Applications on mobile should have a look at javafxports.org.
People can find everything on Gluon on our website gluonhq.com. Keep an eye on our news section, as we are constantly announcing new stuff.

Johan, thank you for the interview!


NEW dates, new workshop: Java EE 7 Workshops: Bootstrap, Effective, Architectures, JavaScript Bootstrap and HTML 5 December, 7th-11th
NEW: Effective Java EE 7 -- Available For Streaming

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Effective Java EE Workshop Available For Streaming And Drm-Free Download

4 hours of Effective Java EE Workshop "On Demand" or 42+ videos are available for streaming and drm-free download.

During the workshop I'm building a "ToDo / Reminders" app with focus on productivity, design and pragmatism covering: Maven, BCE structure, testing (unit, integration and system-tests), JAX-RS, Bean Validation, JSF, JPA, WebSockets, exception handling, monitoring, CDI and EJB.

Any questions left? Then see you at each first Monday of the month at 6 P.M. live.

Also see you in person at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting


NEW dates, new workshop: Java EE 7 Workshops: Bootstrap, Effective, Architectures, JavaScript Bootstrap and HTML 5 December, 7th-11th
NEW: Effective Java EE 7 -- Available For Streaming

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

JAXB JSON POJO Serialization Example

To serialize a POJO into JSON using JAXB you will have to use a custom JAXB runtime like e.g. EclipseLink MOXy:


<dependency>
	<groupId>org.eclipse.persistence</groupId>
	<artifactId>org.eclipse.persistence.moxy</artifactId>
	<version>2.6.0</version>
</dependency>

According to the discovery process, you will have to put a jaxb.properties file in the same package as your model classes (e.g. src/main/resources/com/airhacks) with the following content:


javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

Now an ordinary JAXB POJO:


@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Workshop {

    private String title;
    private String description;

    public Workshop() {
    }

    public Workshop(String title, String description) {
        this.title = title;
        this.description = description;
    }

    @Override
    public int hashCode() {
 	//...
    }

    @Override
    public boolean equals(Object obj) {
	//...
    }

}

Can be serialized / deserialized without any additional ceremony:


import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import ...

public class WorkshopIT {

    private JAXBContext jaxbContext;
    private Unmarshaller unmarshaller;
    private Marshaller marshaller;

    @Before
    public void init() throws JAXBException {
        this.jaxbContext = JAXBContext.newInstance(Workshop.class);
        this.marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty("eclipselink.media-type", "application/json");
        this.unmarshaller = jaxbContext.createUnmarshaller();
        unmarshaller.setProperty("eclipselink.media-type", "application/json");
    }

    @Test
    public void serialize() throws JAXBException {
        Workshop origin = new Workshop("java ee", "rocking platform");

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        this.marshaller.marshal(origin, baos);

        byte[] content = baos.toByteArray();
        System.out.println(new String(content));

        ByteArrayInputStream bais = new ByteArrayInputStream(content);
        Workshop copy = (Workshop) this.unmarshaller.unmarshal(bais);

        assertNotSame(origin, copy);
        assertEquals(origin, copy);
    }

}


See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting


NEW dates, new workshop: Java EE 7 Workshops: Bootstrap, Effective, Architectures, JavaScript Bootstrap and HTML 5 December, 7th-11th
NEW: Effective Java EE 7 -- Available For Streaming

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Favorite Servers and DBs, Kafka, Skinny WARs, Threading And Co. or Answers For The Questions at 17th Airhacks.tv

Thanks to the +90 live attendees of the 17th airhacks.tv streaming event for participating and all the interactions from twitter and IRC. 10+ questions were answered. Any questions left? Ask now and see you in September, 7th, at 6pm CET!

Subscribe to airhacksnews.com newsletter and receive the meta-updates (upcoming conferences, shows events and activity).

See also other screencasts at: tv.adam-bien.com or subscribe to youtube.com/c/bienadam.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting


NEW dates, new workshop: Java EE 7 Workshops: Bootstrap, Effective, Architectures, JavaScript Bootstrap and HTML 5 December, 7th-11th
NEW: Effective Java EE 7 -- Available For Streaming

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

realworldpatterns.com
Online Workshops
...the last 150 posts
...the last 10 comments
License