I have a background in web-based programming (php, jsf,...) and minimal background with swing and swt.
Currently I'm looking at java fx 2.x for a new desktop application and I'm wondering about best practices concerning building the actual GUI. I could go the declarative route with fxml or I could go the procedural route. Currently for some quick prototyping I'm doing the latter but I was wondering whether there were compelling reasons to use fxml.
In the end I went the FXML route for an average-sized project and even though the scene builder beta is still somewhat unstable on my linux system, it has proven to be vastly superior to the original procedural prototype. By far the biggest advantage is that a lot of elements (especially hbox, vbox, labels, tabs,...) no longer clutter my code as they exist only in the fxml.
See the Oracle advice:
Oracle do recommend FXML for layout definition over the Java API.
Alternate Declarative Technologies for JavaFX
A semi-declarative method is the JavaFX Builder API, but you might want to avoid that as the builder api will be deprecated in future JavaFX versions.
In general the use of declarative syntax has mainly won over procedural programming for the majority of UI markup tasks. This be seen by the prominence of technologies such as HTML, CSS, FXML, XAML, MXML, XUL, etc.
Low Level Programming
For low-level tasks such as developing a custom JavaFX control, manipulating a JavaFX canvas or processing image data, the procedural Java API is best suited rather than using declarative FXML - none of the JavaFX codebase in openjfx uses FXML.
Personal Choices and Advice
In the end, there is no right answer here. The choice is left up to the developer to choose the approach they like best.
For small programs I like just writing some code in the IDE, compiling and running it without having to deal with the context switch between XML based FXML and Java code. But I have found that this procedural only approach doesn't easily scale well to larger projects. Having the view separated into FXML helps to enforce separation of concerns and modularization. It is far too easy to mix these view and logic concerns up without the artificial separation which FXML demands.
I don't really like XML as a UI layout language. I think the now defunct FXD format from the obsolete JavaFX 1.x branch was far superior. However, FXML is the most accessible and widely used declarative UI syntax for JavaFX 2.
I use CSS with JavaFX programs a lot and like using it with both FXML declarative code and Java API procedural code. In my opinion, it is at least as important to separate style from code as it is to separate layout from code.
When using CSS, it is always best to put your styles in a separate style sheet rather than inline the styles in code.
As pointed out in another answer, the JavaFX SceneBuilder visual design tool currently only works with FXML and, all other things aside, that is reason enough for many to use FXML to define their JavaFX UI.
If you're separating the layout (FXML) from the application code, the chance is higher that you can ask some UX guys to work on the layout using the SceneBuilder only rather than requiring them a whole IDE.