Oracle has announced the release of JavaFX 2.0 Beta SDK release. In this post, I will have a look at JavaFX, its background, current situation, and the problems it is facing.

 

Brief History of JavaFX

Rich Internet Application (RIA) is an important trend for web/windows applications, and development of such applications needs well-equipped frameworks. Adobe with Flash platfrom (targetted for Flash/AIR client runtimes), and Microsoft with Silverlight and Windows Presentation Framework (WPF) have been much faster and successful in developing RIA technologies and acquising market. Traditionally, Sun Microsystems with Java, has been behind the Adobe and Microsoft in providing RIA frameworks. To deal with this problem, Sun introduced JavaFX as RIA technology. Let's see a brief history of JavaFX from official site of JavaFX:

 

 At the JavaOne 2007 conference, Sun Microsystems introduced the JavaFX
 platform to help content developers and application developers to create
 content-rich applications for mobile devices, desktops, televisions, and
 other consumer devices. The initial offering consisted of the JavaFX
 Mobile platform and the JavaFX Script language. Multiple public releases
 were delivered after the initial announcement; the 1.3 version was
 released on April 22, 2010.
 
 After Oracle's acquisition of Sun Microsystems, Oracle announced during
 the JavaOne 2010 conference that support for the JavaFX Script language
 would be discontinued. However, it was also announced that the JavaFX
 Script APIs will be ported to Java and would be released as part of the
 JavaFX 2.0 product. This announcement meant that the JavaFX capabilities
 will become available to all Java developers, without the need for them to
 learn a new scripting language. With this announcement, Oracle has
 committed to making JavaFX the premier environment for rich client
 applications.
 

 

Requirements for Rich Internt Applications (RIAs)

I believe that in order to have a successful and proper RIA technology,one should follow at least four following rules:

  • RULE (1): Separation of UI contents and UI behavior. It is basic idea of MVC (Model-View-Controller). By following this rule, the UI designers can concentrate on contents, and application developers concentrate on coding, and they can smoothly co-work together.
  • RULE (2): Unique/Consistent UI contents modeling.  UIs are needed for a vast variety of applications: mobile device appliations, web applications, desktop applications, and so on. From viewpoint of programmers, it is not effective to learn different UI modeling languages for each application type.
  • RULE (3): Seperation of UI contents modeling from rendering engine. From viewpoint of RIA technology, it will use same UI modeling language for all application types (windows application, mobile device application, and so on), and it only needs to provide different rendering engines according to target device or application type. Therefore, rendering engines should be implementing in a different layer, which is completey separated from UI contents modeling languages layer.
  • RULE (4): Modeling UI contents in declarative markup language. According to RULE (1), both designers and developers need to understand and modify UI contents. They use different tools and approaches; so, modeling the UI contents in an extensible and interchangable format is important. Accordign to RULEs (2) and (3), regradless of target device or application type, UI contents should be modeled in a unique/consistent manner, which makes it necessary to have interchangable format for UI contents modeling. Considering the available technologies, I think the proper answer for format is declarative markup language, or XML.

 

 

Comparing RIA Technologies

Considering the above requirements, I have done a comparision on the approaches have been used by three major RIA technology providers. Results are summarized in the following table.

 

RIA TechnologyFrameworkGUI Contents ModellingGUI Behavior Implementation
Flash platform by AdobeAdobe Flex

MXML files

(extension: .mxml)

(is XML file)

ActionScript files

(extension: .as)

.NET platform by Microsoft

XAML UI Modelling for .NET (used by: Windows Presentation Framework (WPF),Silverlight, Windows Phone and so on)

XAML files

(extension: .xaml)

(is XML file)

Code behind files

(extension: .cs or .vb)

JavaFX by Oracle (Sun Microsystems)

JavaFX 1.3

JavaFX script files

(extension: .fx)

(is script file)

JavaFX script files or

Java files

(extension: .fx or .java)

JavaFX 2.0

(from JavaFX 2.0, JavaFX script language is discontinued)

Java files

(extension: .java)

Java files

(extension: .java)

 

 

Let's see a simple sample code for modeling of UI contents for each of above RIA technologies. Assume that UI is a dialog showing one label, one input box, and one button.

 

Code for Adobe Flex 4.5 is:

 <?xml version="1.0" encoding="utf-8"?>
 <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" 
           layout="absolute">
     <mx:Label x="52" y="38" text="Your Name:"/>
     <mx:TextInput x="154" y="36" width="219" id="name"/>
     <mx:Button x="124" y="85" label="Submit" id="submit"/> 
 </mx:WindowedApplication>

 

Code for .NET 3.5 is:

 <Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="298" Width="522">
      <Grid>
           <Label Margin="52,38,0,0" Name="label1" Height="28"
                VerticalAlignment="Top" HorizontalAlignment="Left" 
                Width="120">Your Name:</Label>
           <TextBox Height="23" Margin="154,36,0,0" Name="name"
                VerticalAlignment="Top" HorizontalAlignment="Left"
                Width="219" />
           <Button Height="23" HorizontalAlignment="Left" Margin="124,85,0,0"
                Name="submit" VerticalAlignment="Top" 
                Width="75">Submit</Button>
      </Grid>
 </Window>

 

Code for JavaFX 1.3 is:

 import javafx.stage.Stage;
 import javafx.scene.Scene;
 import javafx.scene.control.*;
  
 Stage {
     title: "Sample Dialog"
     scene: Scene {
          width: 522
          height: 298 
          content: 
               Label {text: "Your Name:" layoutX: 52 layoutY:38 }
               TextBox {layoutX: 154 layoutY: 36 columns: 10}
               Button { text:"Submit" width: 75  height: 23 layoutX: 124
                     layoutY:85 }
     }//Scene
 }//Stage

 

Code for JavaFX 2.0 is: 

 import javafx.stage.Stage;
 import javafx.scene.Scene;
 import javafx.scene.control.*;
 public class Main extends Application {

   @Override
   public void start(Stage stage) {
       Group root = new Group();
       Scene scene = new Scene(root, 522, 298, Color.BLACK);
       
       Label label1 = new Label ("Your Name");
       label1.setTranslateX(52);
       label1.setTranslateY(38);
       
       Button button1 = new Button("Submit");
       button1.setTranslateX(124);
       button1.setTranslateY(85);
       
       TextBox textBox1 = new TextBox ();
       textBox1.setTranslateX(154);
       textBox1.setTranslateY(36);
       
       root.getChildren().addAll(label1,button1,textBox1);

       stage.setTitle("JavaFX Scene Graph Demo");
       stage.setScene(scene);
       stage.setVisible(true);
   }

   public static void main(String[] args) {
       launch(args);
   }
 }
  

 

For the Flex or .NET, you can see that all the above RULEs are valid.

 

With reagrds to RULEs 1 and 4, both  Flex and .NET have modeled UI contents as an extension of XML language, and XML model file for UI contents is completely separated from UI behavior file (which is ActionScript or C#.NET or VB.NET languages). In .NET, UI designers can use Microsoft Expression Blend to create XAML files, and programmers can use Microsoft Visual Studio .NET to add behavior for those XAML files. Different tools, but, all deal with same data types/files for UI contents.

 

With regards to RULEs 2 and 3, Microsoft has done an amazing job by using XAML technology as a consistent format for different application types, like: windows application, silverlight application, windows phone, xbox, and so on. XAML is not a sub-project of WPF or Sliverlight or other technologies. But, it is a much wider project that is used by those technologies. As they have mentioned in this site: "XAML is the language behind the visual presentation of an application that you develop in Microsoft Expression Blend, just as HTML is the language behind the visual presentation of a Web page."

 

 

But, how about JavaFX?

I think both JavaFX 1.3 and 2.0 fail to satisfy almost all above four rules. I have summarized evaluation results in the following table:

 

No.RULEJavaFX 1.3 evaluationJavaFX 2.0 evaluation
1Separation of UI contents and UI behaviorthe .fx files contain both UI contents and UI behavior. Basically, .fx files are scripting files, which should not include UI contents. It is a really big mistake to mix those scripts with UI contents.exactly same problems as JavaFX 1.3 exist. The only difference is that JavaFX 2.0 uses Java API code, instead of script files.
2Unique/consistent UI contents modelingfor each category of applications, Java has different APIs: Swing, JavaFX API, applets, JavaFX scripts, and so on. No consistent solution exists.
3Separation of UI contents modeling from rendering engine
4Modeling UI contents in declarative markup languagenot using declarative markup languages, but, script files.not using markup languages, but, java code files.

 

I beleive stopping support for scripts of JavaFX 1.3 was a good decision, but, unfortunately, JavaFX 2.0, instead of solving problem, is just making it worse. Using JavaFX APIs for JavaFX 2.0 is not the solution. Some people even say that JavaFX 2.0 has become like a Swing++ library, nothing more...

 

I know that in JavaFX 2.0, Oracle is adding support for FXML file format for modeling UI contents. The idea of FXML files come from BXML files of Apache Pivot. As very first steps, it may be good action, but, it is not really enough.

 

What should be done?

I believe JavaFX (actually, Java language) needs to re-design its policies for having a consistens and declarative markup language for modeling of visual presentation for different application types of Java (swing, applets, mobile phones, RIAs, and even web applications). This modeling language should not be a sub-project of current Java presentation frameworks, but, it should be on top of them, and guide those presentation frameworks.

 

I guess that starting a new JCP for JavaFX specification should be a good start point. The power of Java comes from JCP process, so, why not use this process for JavaFX?

 

OK. JavaOne 2011 will be hold on October 2-6. Let's wait and see the official presentations of Oracle to understand their plans for extending JavaFX. Hope it is going to correct the current wrong direction of JavaFX, and make a move to right path. Otherwise, Orcale (and we, as Java developers) will be behind Adobe and Microsoft in RIA technologies, same as before.

 

P.S.: There is a framework, called "Metawidget", that you can find details about it in this link. The idea behind this framework seems interesting, and near to rules I have explained above. There is a presentation about this framework in JavaOne 2011 in this link, as following:

 

Presentation: "DRY UIs: Let the metadata do the work"

Speakers: Dan Allen, Richard Kennard