Partner – Microsoft – NPI (cat=Java)
announcement - icon

Microsoft JDConf 2024 conference is getting closer, on March 27th and 28th. Simply put, it's a free virtual event to learn about the newest developments in Java, Cloud, and AI.

Josh Long and Mark Heckler are kicking things off in the keynote, so it's definitely going to be both highly useful and quite practical.

This year’s theme is focused on developer productivity and how these technologies transform how we work, build, integrate, and modernize applications.

For the full conference agenda and speaker lineup, you can explore JDConf.com:

>> RSVP Now

1. Introduction

While writing our code, we might refer to articles on the internet like wiki pages, guides, or official documentation of a library. It could be a good idea to add the links to such reference articles in the Javadoc.

In this tutorial, we’ll learn how to reference an external URL in Javadoc.

Java does not offer any special tools for external links, but we can just use standard HTML. The following syntax is used to create an in-line link:

/**
 * Some text <a href="URL#value">label</a> 
 */

Here, the URL#value can be a relative or absolute URL.

Let’s consider an example:

/** 
 * Refer to <a href="http://www.baeldung.com">Baeldung</a> 
 */

This will render as:

Refer to Baeldung

Another way is to create a heading containing the link. The @see tag is used as follows to achieve this:

/**
 * @see <a href="URL#value">label</a>
 */

Consider the following example:

/**
 * @see <a href="http://www.baeldung.com">Baeldung</a> 
 */

This will create a ‘See Also’ heading containing the link:
See Also:
Baeldung

The @link tag is specifically used to link to the Javadoc of other classes and methods. This is an inline tag that converts to an HTML hyperlink pointing to the documentation of the given class or method reference:

{@link <class or method reference>}

Suppose we have a class DemoOne containing a method demo:

/** 
 * Javadoc
 */
class DemoOne {
  
  /**
   * Javadoc
  */
  void demo() {
    //some code
  }
}

Now, we can link to the Javadoc of the above class and method from another class, in the following ways:

/** 
 * See also {@link org.demo.DemoOne}
 */
/**
 * See also {@link org.demo.DemoOne#demo()}
 */

This tag can be used anywhere that a comment can be written, while @see creates its own section.

To summarize, @link is preferred when we use a class or method name in the description. On the other hand, @see is used when a relevant reference is not mentioned in the description or as a replacement for multiple links to the same reference.

5. Conclusion

In this article, we learned about the ways to create an external link in Javadoc. We also looked at the difference between the @see and @link tags.

Course – LS (cat=Java)

Get started with Spring and Spring Boot, through the Learn Spring course:

>> CHECK OUT THE COURSE
res – REST with Spring (eBook) (everywhere)
Comments are closed on this article!