Basic Layout

Java code is placed in a file that must end in .java. There is a required structure for the file's contents, although some of the elements are optional. The list below shows the order of required and optional elements.

  • <Comments may be placed anywhere in the file>

  • <Package statement>

  • <Import statement(s)>

  • One or more class or interface definitions

At a minimum, a source file must contain one class or interface definition, as shown in the following code:

class LibraryCard
    {
     }

There is an important requirement for the file name. It must match the name of a class or interface defined in the .java file.

Note

Java, like UNIX, is strictly case sensitive. That means that a Date object called Today is totally different and unrelated to a ...

Get PURE Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.