O'Reilly logo

PURE Java™ 2 by Kenneth Litwak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required