Expand Authors Top

If you have a few years of experience in the Java ecosystem and you’d like to share that with the community, have a look at our Contribution Guidelines.

November Discount Launch 2022 – Top
We’re finally running a Black Friday launch. All Courses are 30% off until next Friday:

>> GET ACCESS NOW

November Discount Launch 2022 – TEMP TOP (NPI)
We’re finally running a Black Friday launch. All Courses are 30% off until next Friday:

>> GET ACCESS NOW

Expanded Audience – Frontegg – Security (partner)
announcement - icon User management is very complex, when implemented properly. No surprise here.

Not having to roll all of that out manually, but instead integrating a mature, fully-fledged solution - yeah, that makes a lot of sense.
That's basically what Frontegg is - User Management for your application. It's focused on making your app scalable, secure and enjoyable for your users.
From signup to authentication, it supports simple scenarios all the way to complex and custom application logic.

Have a look:

>> Elegant User Management, Tailor-made for B2B SaaS

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.

November Discount Launch 2022 – Bottom
We’re finally running a Black Friday launch. All Courses are 30% off until next Friday:

>> GET ACCESS NOW

Generic footer banner
Comments are closed on this article!