Generating your own Javadocs for your Package

Reading Time: 4 minutes

Documenting whatever work you are doing as a developer or tester is always a good idea hence we are going to learn about Generating JavaDocs for your own package.

Documentation can easily describe info about which method/class/entity to use and when.

Hence, a reliable documentation is a must for a developer. Just think if you are not aware of a certain language then how difficult it will get to code without any trust-able documentation about the language. Documentation helps in building and maintaining the code as well as transfer knowledge to other developers too.

As we know, documentation for java is already available but have you ever thought of creating your own java documentation?

In this blog, we will learn how to create our own documentation for java packages automatically using JavaDoc tool so that you can create your own documentation easily.

What is JavaDoc Tool?

  • JavaDoc is a tool that allows us to create documentation in HTML format for our own created package.
  • Java provides various tags for classes or packages to help create JavaDoc documentation.
  • JavaDoc generates a documentation in HTML format using the java source code.
  • JavaDoc tool comes built-in with JDK. (Java Development Kit)

Tags for class or a package

  • @author – this tag is used when we want to add an author name.
  • @version – this tag is used to add version.
  • @Since – this tag is used to add when was this version written.
  • @See – this tag adds a see also heading with a link.

Similarly, there are few tags available for methods as well

  • @param – this tag describes parameters of a method.
  • @return – this tag describes about the return value.
  • @throws – this tag describes the exceptions thrown.
  • @deprecated – this tag describes about the deprecation status.

Let’s know how to generate documentation using JavaDoc tool in IntellijIdea!

Step 1

Open your java program in IntelliJ.

Step 2

Go to Tools and then select “Generate JavaDoc” from the drop down menu.

Tools>Generate JavaDoc…

Step 3

You will see a pop up menu as soon as you click on Generate JavaDoc and accordingly select the project and packages you want to generate JavaDoc for.

Select the classes you want to generate JavaDoc for and then by default the tool will create documentation for all the classes that are present in your project.

Also, don’t forget to specify the Output directory as this is the place where your JavaDoc will be saved.

Step 4

Lastly, just click OK and you are good to go and the JavaDoc will be saved to your specified location.

Below is a Snapshot of how JavaDoc Documentation looks like

Likewise you can create your own JavaDoc documentation for your packages.

Reference Code

package com.javadoc.documentation;

public class LearnJavaDoc {

static void hello()
{
System.out.println(“Let’s create a JavaDoc!!”);
}

static void hello(String one){
System.out.println(“The value of the parameter is: ” + one);
}

static void hello(String one, String two){
System.out.println(“The value of first parameter is: ” + one + “\nThe value of second parameter is: ” + two);
}

static void hello(String one, String two, String three){
System.out.println(“The value of first parameter is: ” + one + “\nThe value of second parameter is: ” + two
+ “\nThe value of third parameter is: ” +three);
}

public static void main(String[] args) {

//Method Overloading
hello();
hello(“Learn Java!”);
hello(“JavaDoc”, “Java Documentation”);
hello(“Knoldus”, “Tech”, “Blogs”);

}
}

Stay tuned for the second part of this JavaDoc series. We will learn the tags used for documenting classes in JavaDocs.

To know more about JavaDoc, you can visit this link.

To read more tech blogs, feel free to visit Knoldus Blogs.

Written by 

Sakshi Mittal is a Software Consultant at Knoldus Software. She has completed her MCA from BCIIT and Bachelors in Computer Applications from GGSIPU. Her practice area is Java but she loves to explore machine learning field as well. She likes writing tech blogs and contribute to open source. When not working you will find her watching travel and food vlogs.

Leave a Reply