In the following program, we use two classes java.swing and java.awt to draw a rectangle using these classes we can draw different shapes we want. For the rectangle we have to mention the co-ordinates to draw rectangle these co-ordinates are taken as an input of the point, these points will spread according to given co-ordinates and makes a rectangle.
Program to draw a rectangle in java
Output

need an explanation for this answer? contact us directly to get an explanation for this answer