Commenting in Java Code

In this lesson, we will learn how to add comments in Java code and why they are important.

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.

Press + to interact
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. ...