📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (176K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
- Single Line Comment
//text
- Multi-Line Comment
/* text */
- Documentation Comment
/** documentation */
Learn complete Java programming language at Java Tutorial | Learn Java Programming with Examples.
Usage of three types of comments example
package com.javaguides.corejava;
/**
* First Java Helloworld Program.
* @author Ramesh Fadatare
* @version 1.8
* @since 2018
*/
public class HelloWorld {
/*
* main() method is entry point of the program.
* JVM searches for main() method
*/
public static void main(String[] args) {
// Prints Hello world string to console
System.out.println("Hello world");
}
}
Hello world
Example from JDK Library
package java.lang;
/**
* The <code>Runnable</code> interface should be implemented by any
* class whose instances are intended to be executed by a thread. The
* class must define a method of no arguments called <code>run</code>.
* <p>
* This interface is designed to provide a common protocol for objects that
* wish to execute code while they are active. For example,
* <code>Runnable</code> is implemented by class <code>Thread</code>.
* Being active simply means that a thread has been started and has not
* yet been stopped.
* <p>
* In addition, <code>Runnable</code> provides the means for a class to be
* active while not subclassing <code>Thread</code>. A class that implements
* <code>Runnable</code> can run without subclassing <code>Thread</code>
* by instantiating a <code>Thread</code> instance and passing itself in
* as the target. In most cases, the <code>Runnable</code> interface should
* be used if you are only planning to override the <code>run()</code>
* method and no other <code>Thread</code> methods.
* This is important because classes should not be subclassed
* unless the programmer intends on modifying or enhancing the fundamental
* behavior of the class.
*
* @author Arthur van Hoff
* @see java.lang.Thread
* @see java.util.concurrent.Callable
* @since JDK1.0
*/
@FunctionalInterface
public interface Runnable {
/**
* When an object implementing interface <code>Runnable</code> is used
* to create a thread, starting the thread causes the object's
* <code>run</code> method to be called in that separately executing
* thread.
* <p>
* The general contract of the method <code>run</code> is that it may
* take any action whatsoever.
*
* @see java.lang.Thread#run()
*/
public abstract void run();
}
What is Javadoc?
The Javadoc Tags
The General Form of a Documentation Comment
/**
* First Java Helloworld Program.
* @author Ramesh Fadatare
* @version 1.8
* @since 2018
*/
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello world");
}
}
What Javadoc Outputs
An Example that Uses Documentation Comments
/**
* This class demonstrates documentation comments.
*
* @author Ramesh Fadatare
* @version 1.8
*/
public class SquareNum {
/**
* This method returns the square of num. This is a multiline description. You
* can use as many lines as you like.
*
* @param num The value to be squared.
* @return num squared.
*/
public double square(double num) {
return num * num;
}
/**
* This method inputs a number from the user.
*
* @return The value input as a double.
* @exception IOException On input error.
* @see IOException
*/
public double getNumber() throws IOException {
// create a BufferedReader using System.in
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader inData = new BufferedReader(isr);
String str;
str = inData.readLine();
return (new Double(str)).doubleValue();
}
/**
* This method demonstrates square().
*
* @param args Unused.
* @exception IOException On input error.
* @see IOException
*/
public static void main(String args[]) throws IOException {
SquareNum ob = new SquareNum();
double val;
System.out.println("Enter value to be squared: ");
val = ob.getNumber();
val = ob.square(val);
System.out.println("Squared value is " + val);
}
}
Enter value to be squared:
2
Squared value is 4.0
Javadoc Generation
Javadoc Command Line Tool
$ javadoc -d documentation src\*
Javadoc With Maven Plugin
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<tags>
...
</tags>
</plugin>
</plugins>
</build>
$ mvn javadoc:javadoc
Learn complete Java programming language at Java Tutorial | Learn Java Programming with Examples.
Comments
Post a Comment
Leave Comment