Most programming languages ship with a set of tools to help you build great software. Java has debuggers, compilers, syntax highlighting, and more bug reporting systems than you can shake a stick at. We even have great reference manuals. And yet the API documentation itself always gets the short end of the stick. JavaDoc was breathtaking in it's simplicity and elegance when first released in 1995. At the time HTML was new and the most advanced competing documentation was WinHelp. Today, however, well... let's just say you can have your breath back.
Java's API documentation hasn't changed much since the mid-90s and it's starting to show. There are a lot of good reasons for the slow pace of change, but it certainly gets annoying. When we started developing JavaFX we set out to make some serious changes to the platform, and API documentation was part of that. The JavaFX SDK ships with a new documentation tool creatively named javafxdoc. My initial suggestion was AwesomeDocs 5000, but sadly that was turned down by the trademark lawyers. Despite the pedestrian name, however, it remains awesome. Go check it out here.
javafxdoc: Awesome docs, but why?
So what makes it awesome? It could be all of the new GUI goodness we added like the accordion control and javascript animation, but those are secondary to the really cool thing: we built it to be future proof. Unlike javadoc, javafxdoc doesn't directly produce HTML at all. Instead it generates a large XML file which is fed into a second transformation step. This transformation currently produces the semantic & strict XHTML you see today, but in the future we could generate PDFs instead. Or a mobile phone version. Or push it into a database for searching and annotation. Or something else no one has thought of yet. No longer will we be locked into a single output format for all time. When the next great way to visualize API docs comes along we'll be ready.
A New Look and Feel
So with our new infrastructure in place, what can we do with it? Well, first we enlisted the help of a graphic designer to create a style that looks modern, clean, and easy to skim. Next, we took advantage of modern browser support for CSS and Javascript to change the navigation. We don't use frames anymore. Instead we have an accordion control on the far left, provided by the excellent open source Mootools project. HTML Frames are rife with problems, so we are happy to be rid of them. Finally you can bookmark the actual class you are on, not the frameset as a whole. And when the CSS and JavaScript is turned off (as it would be in a screen reader for the blind or a search engine), our new docs still make logical sense.

The class selection accordion
Inline Examples
Next we added support for inline examples. Code examples often get stale, meaning the code no longer compiles or references older versions of the API. Additionally, graphical APIs need lots of screenshots to explain their usage, but authors don't like to do screenshots. They take time and must be redone whenever the API changes. It's busy-work. To deal with this we added the @example doc tag. Now, rather than having the doc writer type some code into a <code> block, which will then quickly go out of date, the author can put the code after the @example tag. The doc tool itself will do syntax highlighting on the code (making the final documentation more readable), then compile the code and execute it, creating a final screenshot automatically. Less busy-work for the doc writers means better documentation.

Inline highlighted code and examples
Profiles
Finally, we wanted direct support for profiles. JavaFX has just one platform and one SDK for all devices, so why shouldn't there be one set of documentation as well. However, JavaFX also has profiles. Certain classes and functions are only available in certain environments & devices. We could add a note to each function letting you know which profile it is in, but wouldn't it be great to only show you the functions you are actually interested in? With just a bit of Javascript we can do that. There are buttons in the the upper right of every page which let you switch the current profile, automatically hiding the classes not in the profile. This means we can support any number of profiles in the future, but you still only have to download one set of docs. It's documentation that scales.

Profile Switcher
Since this is the first release of the SDK we still have bugs in our docs, both in the text and in the JavaScript & CSS formatting. As you find these bugs please report them. Our goal is for JavaFX to have world class documentation, both in content and presentation, and the only way to do that is with your help.
Thanks,
Josh

wonderful tool indeed. now how can i use it? i could hardly find any docs on the tool and failed miserably when i just tried to use it.
btw, i wanted to use it to generate xml only, that way, i can write a javafx doc viewer worthy of its name, in javafx.
Posted by Walter Chang on August 10, 2008 at 10:25 PM PDT #
am i the only guy who hits show all classes and does ctrl-v to find the one i want? it appears you cannot do this with these new javascript based docs.
Posted by 79.77.133.172 on August 11, 2008 at 03:52 AM PDT #
Looks cool! Is there a reason the same tool could not be replacing javadoc for Java? Or at the very least, re-use the transformation step and just require we plug-in a new parser?
Posted by Casper Bang on August 11, 2008 at 04:27 AM PDT #
Can we use this tool for plain java code?
Posted by Soma on August 11, 2008 at 04:43 AM PDT #
API is simply looking awesome now !
Posted by Vaibhav on August 11, 2008 at 08:00 AM PDT #
Thanks for the insights. The notion that javadoc only generates HTML is, however, nonsense. Javadoc uses doclets to specify the output format. The standard doclet produces HTML, but there are many doclets available out there that produce PDF, xml-fo, JavaBeans, and a whole lot of other stuff. Check http://www.doclet.com/ as a starting point. Basically, javadoc already uses the two-stage model you are touting.
Posted by Erwin on August 11, 2008 at 08:31 AM PDT #
Ok that's just slick. Can you get temporarily hired on the Javadoc team?
Posted by Ravi on August 11, 2008 at 08:58 AM PDT #
glad to see you're raising awareness in this area. writing a program that persists javadocs into a database was an open source project i undertook [i think back] in 2001. it's the right design/solution for the task:
- it decouples what you process from what you produce, allowing you to produce all kinds of front-ends to the same back-end data;
- it enables search, and the placement of multiple api docs into a single, seamless repository
anyhow, glad to see you're applying those ideas to javafx docs.
/ eitan
Posted by eitan on August 11, 2008 at 09:00 AM PDT #
Walter Chang: the tool isn't well documented yet since we've only been using it to doc the SDK itself. This will change by the 1.0 release. If you want to learn more people join the openjfx-compiler mailing list or email me directly. There is an option to just produce the XML and not do the transformation stage.
79.77.133.172: you are not the only one who just does a search through the whole page. I plan to add a nice index page in the next version.
Casper Bang: it is actually implemented as a custom Doclet, so it *will* work on Java code. I haven't tested this in a while and so it probably still has bugs, but the goal is full Java and JavaFX compatibility to support mixed projects.
Erwin: you are correct that this has been possible for years using doclets (and in fact our XML is provided as a custom doclet). I originally started by looking for an XML doclet on doclets.com, but found nothing usable. I hope with XML being easier to use than a full custom doclet we will start to see more alternative views of API docs.
Eitan: Hi Eitan! Your work is what originally started me in this direction a few years ago (before the JavaFX initiative was launched). I really appreciate your work.
Posted by Josh Marinacci on August 11, 2008 at 09:26 AM PDT #