3

I understand that JavaFX GUI can be built from either Java programming language or from XML markup language. I was wondering if someone can highlight the main differences between the two and whether one of them is the industry standard.

Thanks!

1 Answer 1

3

XML based definition of a JavaFX scene graph is an example of declarative programming.

Writing Java source code against the JavaFX APIs is an example of imperative programming.

The two different programming styles are not mutually exclusive and are often complementary.

If you are used to web style programming, you can think of FXML as similar to HTML and Java source as similar to the JavaScript that backs a dynamic HTML page. If you view source on most modern HTML pages, you will see that they contain both HTML and JavaScript.

FXML is good for defining the overall broad elements of the scene and it's structure. It is amenable to tool based creation and manipulation using tools such as SceneBuilder.

The entire JavaFX system contains no FXML in it's source. FXML is more for application level development than system level development.

The Java API is good for:

  • crafting low level libraries (such as a control library) to be referenced in FXML.
  • generating highly dynamic behaviour.
  • creating frameworks which render FXML pages.
  • writing business logic.
  • defining data models and binding them to UI.
  • many other things.

When first learning JavaFX, programming in Java against the JavaFX API is a good way to get to understand the low level details of the JavaFX system. As you start writing larger programs, you may find it quicker and more effective to start defining your UI using SceneBuilder to generate it's initial scene graph in FXML.

It is possible to write a JavaFX program without FXML but it is not possible to write a JavaFX programming without using some kind of imperative programming language such as Java.

In short, you need to at least learn the Java API, but it is almost certainly worthwhile learning FXML as well. When you are proficient using both, then you will be able to use them in conjunction where they are most effective and appropriate.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.