Welcome!

AJAX & REA Authors: Scott Sellers, Liz McMillan, RealWire News Distribution, David Smith

Related Topics: Java, AJAX & REA

Java: Article

Developing Your First Compiled JavaFX Script Program

CompiledHelloJavaFX

From Jim Weaver's Learn JavaFX Weblog

The next JavaFX Puzzler will be posted at 18:00 GMT (1:00PM EST) on Wednesday, November 28, 2007.  It will be a compiled JavaFX Script puzzler, so you'll need to build the JavaFX Script Compiler in order to participate in the Puzzler.

To help prepare you for the Puzzler, I'd like to you to develop a very basic "Hello World" style program. After you've built the compiler, please copy and paste the following code into a file with the FX extension.  I chose CompiledHelloJavaFX.fx for my filename:

/*
*  CompiledHelloJavaFX.fx - A Hello World
* style compiled JavaFX Script program
*
*  Developed 2007 by James L. Weaver
* (jim.weaver at lat-inc.com)
*/

import java.lang.System;

class CompiledHelloJavaFX {
   attribute textToPrint:String =
"Hello Compiled JavaFX Script!";
}

var chjfx =
  CompiledHelloJavaFX {
  };

System.out.println(chjfx.textToPrint);

This simple compiled JavaFX Script program is almost identical to what it would be if it were written in interpreted JavaFX Script. The difference (attribute initialization) is noted in the Converting to the New Syntax document  that I've referred you to previously.

To compile the program, set your PATH environment variable to the dist/bin directory of where you installed the JavaFX compiler. Then execute the proper javafxc command file for your operating system, passing your FX file as an argument.  On my Windows machine, I navigate to the directory in which my FX file is located, and enter the following from the command prompt:

javafxc CompiledHelloJavaFX.fx

To run your program, set the CLASSPATH environment variable to the javafxc.jar file in the dist directory as well as the current directory, passing in the name of the JavaFX Script program without the FX extension.  On my Windows machine, I enter the following from the command prompt:

java -cp C:\openjfx-compiler\dist\javafxc.jar;. CompiledHelloJavaFX

Note: If there is a package statement in your JavaFX Script program, then navigate to the directory in which the top node of the package is located.  See Develop and Run Your First JavaFX Script Program in the Next Few Minutes for a discussion on the package statement.

For a review, or to catch up if you're new to this Learn JavaFX blog, see the posts in the JavaFX Script category to learn the syntax of interpreted JavaFX Script programs.  As I've noted before, JavaFX Script is migrating from being an interpreted language to becoming a compiled language.  When compiled JavaFX Script is mature it will eventually replace interpreted JavaFX Script. 

Please post to the Feedback thread here any questions that you have as you build the JavaFX Script Compiler, and as you compile and run this example.

More Stories By James L. Weaver

James L. (Jim) Weaver is founder and president of jMentor, formed in 2000 to provide Java programming-related training to companies and individuals. He has served as a system architect and developer for over 25 years, specializing in leading-edge software development. His specialties include Java, object-oriented, and web-based technologies. He has authored books on the Java programming language, including most recently JavaFX Script, published by Apress.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
murthy 02/15/08 07:28:28 PM EST

when i run m javafx program, there is an error!
the Frame class is not found...
please help me

Cloud Expo Breaking News
The cloud has many benefits, but when it comes to application development, how does the cloud help enterprises and development teams create custom software and applications that end users actually care about? Using real world examples from Adobe, Herff Jones and Navy Federal Credit Union, this session will highlight the advantages cloud computing provides for quickly developing custom software and applications with compelling user experiences. In their general session at the 10th International ...
Nearly every enterprise is evaluating cloud computing solutions either today or in the near term. Many have already made the leap, and many more are getting close to putting that first toe in the water. But there are key considerations that should be made, questions to be asked, and designs to consider before you can feel secure with your provider. In his session at the 10th International Cloud Expo, David Gulick, Product Manager, Hosting Product Management at Savvis, will help give you food f...
With Cloud Expo 2012 New York (10th Cloud Expo) now under four weeks away, what better time to introduce you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference... We have technical and strategy sessions for you dealing with every nook and cranny of Cloud Computing, but what of those who are presenting? Who are they, where do they work, what else have they written and/or said about the Cloud that is t...
SYS-CON Events announced today that Super Micro Computer, Inc., a global leader in high-performance, high-efficiency server technology and green computing, will exhibit at SYS-CON's 10th International Cloud Expo, which will take place on June 11–14, 2012, at the Javits Center in New York City, New York. Supermicro (NASDAQ: SMCI), the leading innovator in high-performance, high-efficiency server technology, is a premier provider of advanced server Building Block Solutions for Embedded Systems, E...
SYS-CON Events announced today that ScaleMP, a leading provider of virtualization solutions for high-end computing, will exhibit at SYS-CON's 10th International Cloud Expo, which will take place on June 11–14, 2012, at the Javits Center in New York City, New York. ScaleMP is the leader in virtualization for high-end computing, providing maximum performance and lower total cost of ownership (TCO). The innovative Versatile SMP (vSMP) architecture aggregates multiple independent systems into a sin...
Come learn real-world examples where cloud and mobile are changing the way business works and the impact they're having on efficiency and productivity. In his session at the 10th International Cloud Expo, Rodrigo Coutinho Senior Product Marketing Manager at OutSystems, will look at how mobile and the cloud are interwoven and the wave of change these two 2012 megatrends will bring to your organization. He will also provide a roadmap to assure you can navigate this sea change for business succes...
Enterprise IT organizations want to deploy a virtualized data center fabric that will provide the foundation for agile private cloud computing. Getting there does not have to be difficult, but it does require a new approach to data center infrastructure design – an approach that is non-disruptive, vendor-agnostic, and very adaptable to changing business requirements. In his session at the 10th International Cloud Expo, Bruce Fingles, Chief Information Officer and VP of Product Quality at Xsigo...
With Cloud Expo 2012 New York (10th Cloud Expo) now under four weeks away, what better time to introduce you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference...
How can businesses harness the power of APIs to reach new customers and markets? In his session at the 10th International Cloud Expo, Alistair Farquharson, CTO at SOA Software, will walk the audience through the growth and evolution of the API, why effective API management is important, and how the game changes when companies expose business applications to the outside world. He will also discuss: A brief history of the API How to use APIs to make money, save money, build brand "Appificatio...
With Cloud Expo 2012 New York (10th Cloud Expo) now under four weeks away, what better time to introduce you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference...