One of the great joys of being a Java Technology Ambassador is to interact with the global Java/JavaFX development community. Here is an interview that Yolande Poirier conducted with Thierry Wasylczenko and me after our co-presentation at Devoxx/France in March 2013.
With continued progress on JDK 8 efforts, I thought we'd explore some of its features together over the next few blog posts. Features added to Java in JDK 8 include:
The first feature I'd like to touch on in this series is lambda expressions, also known as closures. A lambda expression is a function that may have parameters, an expression or block of code, optionally returning a value.
One very convenient use of lambda expressions is to simplify event handling. Typically, event handling is implemented with the help of an anonymous inner class, as shown in the following code snippet.
The anonymous inner class shown above is of type EventHandler, which has one abstract method, named handle. Any interface that has exactly one abstract method is known as a functional interface, and may be replaced by a lambda expression. The following code snippet contains a lambda expression that replaces the anonymous inner class in the previous code snippet. Note that the type of the lambda is inferred by the compiler as EventHandler<ActionEvent> because the onAction() method takes an object of type EventHandler<ActionEvent>. Furthermore, EventHandler has a single method handle(). Therefore, the lambda expression must be an implementation of the handle() method.
The parameter in this lambda expression must be an ActionEvent, because that is the type specified by the handle() method of the EventHandler interface. We can therefore simplify this lambda expression further because the parameter type is inferred, as shown in the following snippet.
When a lambda expression has a single parameter and its type is inferred, the parentheses are not required, as shown in the following snippet.
Because the block of code in our lambda expression contains only one statement, we can simplify it even further as shown in the following snippet.
The listing below contains a modified version of the MetronomeTransition example from the Pro JavaFX 2 book. Specifically, the event handlers in the listing below use lambda expressions rather than anonyomous inner classes.
Here's a screenshot of the MetronomeTransition example in action:
Future articles in this JDK 8 series will dig deeper into lambdas and related topics such as bulk data operations for collections referenced at the beginning of this post. Have fun experimenting with lambda expressions and JDK 8 in general!
Regards, James Weaver james dot weaver at oracle dot com
Just a note of appreciation to the JavaFX community in Japan for creating the JavaFX Advent Calendar, which is a series of JavaFX articles leading up to Christmas 2012. Not only did they create the articles, many of the authors translated their articles in English to share with people like me that don't currently read Japanese. There is a table in the JavaFX Advent Calendar page that has links to all of the articles that were translated to English.
Some of the articles also have JavaFX sample applications, like the sample e-book reader by a developer whose Twitter name is @tarchan:
Here's an article and game app by a developer whose Twitter name is @Fukai_yas that demonstrates why the Earth wasn't destroyed as the Mayan calendar predicted (^_^)
Please take a look at this series of articles, and join me in thanking these authors and developers for their work!
The JFXtras project, located at JFXtras.org, provides UI controls and other Java objects that developers often need in their day-to-day work, but that are currently missing from JavaFX. This project also serves as a proving ground for controls that may some day make it into the official JavaFX distribution. The brief video below gives you an introduction to the JFXtras project, and demostrates the UI controls and gauges that are currently available.
You may remember the post-punk/new wave group from the '70s known as Devo. If so, you probably get the reference in the title of this post. According to Wikipedia, Devo's music and stage show mingle kitsch science fiction themes, deadpan surrealist humor, and mordantly satirical social commentary. The group often had a very geeky appearance, as evidenced by the album cover on the right.
There is another group of geeks, known as Devoxxians, that gather every fall in Belgium to attend a Java programming conference named Devoxx. I'm very happy to say that Gerrit Grunwald and I are two of those Devoxxians, and we'll be presenting a three-hour university session on JavaFX. This session occurs on Tuesday, 13 November 2012 at 1:30pm, and is targeted at Java developers that would like to learn to use the JavaFX APIs that are now included with Java.
Much of this session will draw upon the work in the Pro JavaFX 2 book that I co-authored, as well as the UI controls and gauges that Gerrit created for the open source JFXtras project. Some of the areas that we'll cover are:
Getting started with JavaFX (Jim)
Creating a user interface (Jim)
Using Scene Builder and FXML (Jim)
Using the JavaFX UI controls (Gerrit)
Creating custom UI controls (Gerrit)
Break
Leveraging the strengths of JavaFX and HTML5 (Martin and Pär)
Overview of DataFX, calling web services (Johan Vos)
Using Scenic View (Jonathan Giles)
Using JavaFX APIs from Alternative JVM Languages (Stephen Chin)
Embedded Java/JavaFX on a Raspberry Pi (Angela Caicedo)
Embedded Java/JavaFX on a BeagleBoard (Gerrit)
Wrap-up and additional Q&A (Jim, Gerrit, et al)
During the session we'll have brief guest appearances by JavaFX developers such as Martin Gunnarson and Pär Sikö, Stephen Chin, Angela Caicedo, Jonathan Giles, Johan Vos, and Jasper Potts. We'll also be awarding ten copies of the Pro JavaFX 2 book to participative audience members :-)
We look forward to seeing you in our JavaFX university session at Devoxx!
Community activity surrounding JavaFX has been steadily growing, with tweets, blog posts, and projects increasing in number. I'm pleased to announce that there is now a JavaFX community site on Java.net at the following URL:
The main purpose of this site is to provide a focal point for the JavaFX community, where relevant blog posts, tweets, and other resources may be easily found. Gerrit Grunwald and I are the community leaders for this site, and we welcome your feedback on how we can make this JavaFX Community site more useful to you!
Many of the younger readers of this blog haven't heard of the legendary comedy team Martin and Lewis (Dean Martin and Jerry Lewis). The late singer/actor Dean Martin was the straight man of the team, and comedian/actor Jerry Lewis was the comedic foil. Each of the pair were incredibly talented, but when playing off of each other the audience routinely doubled over in laughter.
Although I'm not going to compare Martin Gunnarsson and Pär Sikö to Martin and Lewis (the latter never wrote code), Martin and Pär are incredibly funny when playing off of each other during their technical presentations. Each has won the coveted JavaOne Rockstar award, and it is a real treat to attend their presentations.
This year at JavaOne 2012, Martin and Pär will deliver a conference session entitled JavaFX Mashups. This session is scheduled on Tuesday, Oct 2 from 1p-2p in the Hilton San Francisco, and has the following description:
"A mix of content or functionality from two or more Web-based services has become known as a mashup. This presentation takes the mashup concept one step further by mixing Web content and scripts with a JavaFX program, effectively blurring the line between Web and application. This is made possible by the powerful WebView component of JavaFX. The session shows how to display Web content in a JavaFX application and how to set up two-way communications between the Java code and JavaScript code run in WebView. It includes several cool and creative examples based on this technique."
I'm really looking forward to attending this presentation in which Martin and Pär will entertain and enlighten us about how JavaFX and Web content play together well. If you haven't yet registered for JavaOne 2012, you can do so here! Hope to see you at JavaOne.
"We dance round in a ring and suppose, but the secret sits in the middle and knows." - Robert Frost
The current state, and future plans, for JDK 8 seem to be well-kept secrets, so I'm writing this post to shed some light on the subject.
Well-kept "secret" #1:
The schedule for upcoming features in JDK 8 builds is posted, listed by feature and by milestone. These lists are available from the JDK 8 page on the OpenJDK site.
Well-kept "secret" #2:
Significant progress has been made in Project Jigsaw, and active development continues. You can see working documents, a quick start guide, and sign up for the mailing list at the preceding link. You can also download an early access version of JDK 8 with Project Jigsaw to try it out.
Well-kept "secret" #3:
You can play with lambda expressions (closures and related features) now, using them, for example, in JavaFX event handlers. Check out the Project Lambda page on the OpenJDK site for very detailed documentation and early access downloads.
Have fun learning about, and playing with, these upcoming JDK features!
The title of this blog post is a Haiku that also has some poetic justice. In September 1992 the programming language named Oak that James Gosling created was first demonstrated on a PDA device named Star7. This device had a graphical interface and a smart agent called "Duke" to assist the user. The Oak programming language, named after the Oak tree outside of Gosling's window, was designed to be a new technology for programming next generation smart appliances.
Oak was subsequently renamed to Java, which went on to become a nearly ubiquitous language and runtime platform. Exactly twenty years after the first demonstration of Oak, tremendous focus and momentum is occuring in the Java embedded space. For example:
JDK 7u6, released a couple of days ago, contains a general-purpose port of the JDK to Linux ARM, making it available under the same licensing terms as Oracle Java for other platforms. This JDK release is aimed at the emerging ARM server market, and for the community working on development boards such as the BeagleBoard, PandaBoard and the Raspberry Pi. This port provides 32-bit binary for ARMv6 and v7, with full support for Swing/AWT, both client (C1) and server (C2) compilers and runs on most Linux distributions. Support for JavaFX on ARM is planned for an upcoming JDK release.
A new conference named Java Embedded @ JavaOne will provide business and technical decision makers, as well as Java embedded ecosystem partners, with a unique opportunity to meet together and learn about how they can use Java embedded technologies to enable new business strategies. This conference will occur during JavaOne 2012, and can be attended as a standalone conference, or as an add-on to the JavaOne conference. Learn more about the business session line-up.
One aspect of embedded Java that excites me is the ability to use a common language and UI toolkit to develop applications for devices, thereby drastically reducing the development and maintenance costs.
Java Embedded @ JavaOne promises to be a very exciting and useful conference, so I hope to see you there!
Note to reader: This "guest post" was written by Dr. James Thompson, who is using JavaFX to develop scientific applications. I've included a brief bio for Dr. Thompson after this post.
Java has a rich history in the scientific community. Applications and frameworks such as the NIH's ImageJ, CERN's Colt framework and Apache Commons Math library immediately spring to mind when working in scientific computing. My first exposure to Java in science came as a graduate student at Oxford. We needed to analyze many large noisy datasets, typically stacked (multi-page) TIFF image files. ImageJ and its excellent plugin framework was the environment of choice for this work. Other groups such as the Mosaic group at the ETH in Switzerland did similar work and have extended it beyond what we did a few years ago.
So where does JavaFX 2 come in? Well, in my recent work we've had a need to develop image analysis software yet again. It turns out this is a common theme in biology, physics and engineering labs nowadays. I decided to have a look into what was available on the JVM which was when I learned of the new Java FX 2 pure Java library. It instantly appealed as it was well documented, had plenty of examples and was free! Scientists are a diverse group too, so the ability to write once and run on Macs, Windows and Linux boxes is a massive bonus. In academic science these days you often find diverse backgrounds and amalgamations of people with broadly different skill-sets. A nice user interface, easy installation and pleasant work environment on the computer desktop is therefore imperative.
A few features stood out immediately as I began browsing examples and reading the API. These included in my order of priority: extensive graphing tools, ObservableList, easy integration with native file systems (open / save dialogs), a simple syntax, great API documentation, FXML and good Netbeans tooling. Later on Scene Builder came onto the scene (pardon the terrible pun). Having done some work with XCode for Cocoa on the Mac I thought it would be hard to stand up to it. I was wrong. Scene Builder was mature out of the box. Laying out 'AnchorPanes' or anything else for that matter is very straightforward. CSS integration also enables easy skinning for apps. This is generally much more difficult in other frameworks.
Living on the JVM and being pure Java, integration with other JVM languages is easy too. My recent forays into Scala have proven very fruitful with JavaFX. I've been building some fairly involved numerical analysis code, and it's very easy to code in Scala. I've been able to use JavaFX in pure Scala classes, extending the 'Initializable' interface and load FXML classes easily.
I've had to develop a few things building directly on the JavaFX framework, such as for example tools to load multi-page TIFF files and write various bit-depth TIFF data to JavaFX 'Image' objects. But generally plotting tools and data handling are a breeze with JavaFX 2.
IntelliJ IDEA, Netbeans and Simple Build Tool for Scala all enable mixed projects and help with building greatly. I stumbled across an sbt-javafx plugin a few days ago, which has enabled me to package my projects for distribution among my colleagues.
In short, if you have a need to develop applets for scientific work, need to load and save data with a GUI, plot graphs and get actual science done, JavaFX 2 has to be given some serious consideration! I can't imagine trying to do what I've been able to in any other framework. I hope more scientists decide to develop things with JavaFX 2, so that we can extend the body of open source code and make development even easier.
Please have a look at a couple of movies I made showing my GUIs in action. These projects are a work in progress, but demonstrate the power of JavaFX and its application to scientific computing front ends.
James did his PhD at Oxford in the Physical and Theoretical Chemistry Laboratory, researching membrane protein biophysics. After finishing, James went to Harvard Medical School for a year to work on an imaging project before moving to his present role as a post-doc at USC in Los Angeles this year. His work revolves around biophysics but uses techniques from molecular biology, chemistry, microscopy and computer science. James maintains interests in single molecule biophysics, membranes, imaging, protein structure and function and computation with Java, Scala and GPUs. His twitter handle is: drJamesThompson