Here at IDRsolutions we are very excited about Java 9 and have written a series of articles explaining some of the main features. In our previous Java 9 series article we looked at the new HTTP/2 client in Java 9. This time we will be looking at HTML5 Javadocs.
In Java 8 and earlier, Javadocs are generated using HTML 4.01. While it’ll continue to be the default, with Java 9 comes the option to have your Javadocs generated in the much more modern HTML5.
Now – I’m the kind of person who prefers a more hands-on experience – so without further ado, let’s dive headfirst into creating Javadocs in HTML5.
Generating Javadocs in HTML5
First, you’ll want to get hold of the latest Java 9 Early-Access build. Once that’s installed and set up (you can check which Java version you are currently using with the command java -v
), you have 2 options:
- Generate Javadocs through your favourite IDE (For example, in IntelliJ IDEA you’ll want to use the “Generate JavaDoc…” command in the “Tools” menu – don’t forget to add -html5 in the command line arguments box
- Or with the command line (using the javadoc tool – more on that here)
Here’s an example I made earlier using the command line tool:
Hold on… this looks just like the HTML 4.01 Javadocs! At first glance, it looks exactly the same – which is (almost) true. Looking at the source, however…
…you can see at the top here that we have HTML5. Scroll further down and you’ll find some of the new HTML5 tags, such as <header>, <footer>, <main> and <nav>. While you might not see any changes to the look and feel, you get all the improvements over HTML 4.01 that come with HTML5 such as:
- Simplified, clearer syntax
- Consistent error handling
- Better mobile support
- Support for the WAR-ARIA standard
Some extra Quality-of-Life
While not limited to just HTML5, I felt it was worth discussing a cool extra feature added to the Javadocs – the search bar in the top right:
This change is very welcome – no more having to awkwardly search Javadocs using the built-in browser search.
You can search the Javadocs for the following:
- Method parameter types (Such as Int, String…)
- Module names
- Types and members
- Packages
Are you going to be switching your Javadocs to HTML5? Let us know in the comments below.