Search⌘ K

Commenting in Java Code

Explore how to enhance Java code clarity by applying block comments, line comments, and Javadoc comments. Understand their uses to make your code easier to read and maintain.

In an earlier lesson, we saw the following code draw a smiley face on the screen. The same code is shown in the code widget below. Just by looking at the code, you may not know how this code is drawing the smiley face, or whether it is drawing it at all.

Java
import com.educative.graphics.*;
class SmileyDrawing
{
public static void main(String[] args)
{
Canvas c = new Canvas(500,500);
c.fill("#FFFF00");
c.circle(250,250,150);
c.circle(250,250,100);
c.stroke("#FFFF00");
c.rect(150,150,200,140);
c.fill("#000000");
c.circle(200,200,10);
c.circle(300,200,10);
c.triangle(245,250,255,250,250,240);
}
}

Reading and understanding code can be a challenge for expert programmers, let alone the novices. Therefore, we can add comments to the code. This way, a reader can understand what a specific code snippet does.

There are three ways to ...