Basically, a class can have fields, constructors, methods and nested types. The following pseudocode shows the skeleton of a Java class:

You will learn about modifiers, constructors, methods and nested types later in the topic 6 lessons. For now, knowing that a Java class can have these elements is more than enough to keep moving forward.

The main Method

The main method of a class is optional. It’s the entry point for running a program and allows more than one valid form:

Preferred convention public static void main(String[] args)
Different modifiers order static public void main(String[] args)
Different parameter name public static void main(String[] anyVarName)
Using vargars public static void main(String... args)

Comments

Classes can include comments (code with documentation purposes that is never run). Probably you know everything about comments, but it never hurts to remember that there are three kinds of them, each one with its own purpose:

Kind Example Purpose
Line // line of code or local comment Compiler ignores from // to the end of the line
Block /* block of code */ Compiler ignores this block of code
Javadoc /** Class or method documentation */ Compiler ignores it, but the javadoc tool uses it

Leave a Reply