Explain Codes LogoExplain Codes Logo

Linking to an external URL in Javadoc?

java
javadoc
external-links
api-documentation
Nikita BarsukovbyNikita Barsukov·Nov 4, 2024
TLDR

To incorporate an external URL in your Javadoc, you can make use of the @see tag complemented with an inline HTML <a> tag, as demonstrated below:

/** * For more info, check {@see <a href="https://example.com">Example</a>} */

This handy piece of code places a direct, clickable path to Example.com within your Javadoc documentation.

With Javadoc, you can wield standard HTML to create impactful and unambiguous external links within your documentation:

/** * This method tricks complex sorting algorithms into doing your laundry. * * @see <a href="https://en.wikipedia.org/wiki/Sorting_algorithm">Wikipedia: Sorting Algorithm</a> - for unsuspecting algorithms */ public void sortMyLaundry() { // Some sorting wizardry }

Few key points to keep in mind:

  • Utilize absolute links for constant, reliable resources.
  • Reserve relative links only when referencing resources within your local project or server.
  • Steer clear of false beliefs like non-existing Javadoc tags such as @linktourl as, sadly, they're as real as unicorns in software development.

Crafting insightful Javadoc references

To assemble a top-notch Javadoc, your links should serve a greater purpose - delivering beneficial insights and assisting users of your APIs.

Effortless understanding via trimming

Minimize bloated phrases and unnecessary jargon; keep your Javadoc focused and flexible. For example, instead of "Please find, on the line below, a link you could use to obtain more information", you can streamline to "Learn more at: <link>."

Magnify meaningful content

Highlight pivotal external resources at the start of your Javadoc, allowing other developers to uncover key resources swiftly and efficiently. You know, best things first:

/** * This method is not a mathematician, but it can still compute Fibonacci sequence pretty well. * * @see <a href="https://mathworld.wolfram.com/FibonacciNumber.html">MathWorld: Fibonacci Number</a> - who knew Fibonacci could be this cool? */ public int fibonacci(int n) { // The golden ratios do their magic here }

Look and learn from source code

Investigate well-documented libraries like javax.ws.rs.core.HttpHeaders to gain insights into real-world implementations of Javadoc with external links. They are like cookbooks for crafting tasteful API documentation.