Let's learn java programming language with easy steps. This Java tutorial provides you complete knowledge about java technology.

Sunday, 25 December 2016

Comments in Java

 

Comments

Comments are statements that are not executed by compiler and interpreter. Comments in java explain the actions of particular piece of code.They are used to provide summary of code in plain english to help future developers or people to better understand the code.


Comments In Java


There are 3 types of java comments

  1. single line comments
  2. multiline  comments
  3. documentation comments 

1)  Single line comment in java

Single line comment in java is used to comment only one line in java. Java single line comment starts with two forward slashes with no white space (//). If the comments exceeds one line then put two more consecutive slashes on next line and continue the comment.

Syntax:

//This is single line comment in java  
//I am single line comment in java programming language

For example:

class SingleLineComment
{
//this is main method in java
public static void main(String args[])
{
//i am single line comment
System.out.println("this is single line comment in java");
}


output: this is single line comment in java   

2) Multiple line  comment in java

Multiple line comment are used to comment multiple line in java. Java 's multi-line comment is a piece of text enclosed in slash-star (/*) and star-slash(*/) e.g /*-------*/.

Syntax:

/* this is multiple lines comment
   in java.
java is object oriented language 
java is secure programming language.
*/

For example:

class MultipleLineComment
{
public static void main(String[] args)
{
/* java is  high level
    and 
secure 
programming language */
System.out.println("multi line comment in java");
/* This is multi line comment in java 
programming language*/
}


output: multi line comment in java


3)  Documentation comment in java

The documentation comment in java is used to create document API. To create document API, you need javadoc tool. Javadoc is a tool which come with JDK and this javadoc tool is used for generating java code documentation in HTML format from the java source file(.java file). By using java documentation comments classes, fields, constructor and method are documented. Javadoc comment e.g /** documentation */.

Syntax:

/** this is documentation
  comment 
in 
java
*/


Javadoc Comments in program

Java documentation comments or Javadoc comment is placed just before the entity to be documented. It can be class, method, field, constructor

For example:

/** 
* First sentence of the comment should be a summary sentence .
* Documentation comment is written in HTML so it can contain html
* in description part.
* @author  Anurag Singh
* @since 2016
*/
public class  DemoOfJavadoc
{
/**
* main method
* @param args String[]
*/
public static void main(String[] args)
{
/**
* printing hello javadoc
*/
System.out.println("hello java doc");
}
}
  
save it DemoOfJavadoc.java

javac  DemoOfJavadoc.java

javadoc DemoOfJavadoc.java

  • now save it in particular directory or folder with extension .java file
  • compile it by javac tool (From cmd)
  • using javadoc tool, generate  html documentation file (From cmd)
  • now go to your current directory where you save java file
  • open html file


There are some Javadoc tags

  • @author
  • @version
  • @param
  • @return
  • @exception
  • @see
  • @since
  • @serial
  • @deprecated


Share:

2 comments:

  1. android app development in amprotechvalley, a juggernaut in the IT Solutions domain, empowers its clients by developing highly-customized software & services tailored exclusively.

    ReplyDelete
  2. Nice Post. Thank you for this information. Visit to learn Python - UX Python

    ReplyDelete

Facebook Page Likes

Follow javatutorial95 on twitter

Popular Posts

Translate