Programming languages allow the inclusion of comments that are not part of the actual code. Documentation is an important aspect of writing programs as it helps the reader to understand what is going on. Java provides three different styles of comments.
Programmers try to avoid “reinventing the wheel” by using predefined libraries of code. In Java, these predefined classes are grouped into packages. The import
statement allows the program to use predefined classes.
Java comes with many packages. There are also many packages created by programmers that you can use. There are two non-standard packages supplied in this curriculum guide. The one we have been using so far is called gpdraw
. In our example program, the DrawingTool
and SketchPad
classes are imported from the gpdraw
package with the statement
Every Java program contains a main method. However, not all classes need to contain a main method, nor should they.
Most classes will contain methods to define a class’s behavior. Here we will explore the basic syntax of a method. You will learn how to utilize all of these parts in Student Lesson A4 - Object Behavior. A method has the following general syntax: