Like Greg said, the API is your best friend:
Java Platform SE 8
You also need some familiarity with OOP. The Graphics class is an abstract class, and Graphics2D is the concrete implementation of it. The paintComponent() method takes a Graphics argument, but in actuality the argument is an instance of Graphics2D.
Your question of "why did they use the grahpics2d and not the canvas" doesn't make any sense. You paint *with* an instance of Graphics2D (which is just a subclass of Graphics) *to* a Component such as Canvas or JPanel. You question is like asking "why did the artist paint with the brush instead of the canvas".
Recommended reading:
Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)