Home > Articles

Language Fundamentals

  • Print
  • + Share This
This chapter is from the book

The Structure of Java Programs

Java programs are composed of declarations of classes and interfaces. Classes define field variables, which provide named access to data. Methods perform actions that consist of operations on the data. Constructors create instances of classes, referred to as objects. Classes also define initializers, which initialize field variables, and inner classes. Inner classes are classes within a class. Data items consist of primitive data values—such as byte, char, and int values—and objects—such as arrays, I/O streams, and GUI elements.

Interfaces define collections of methods that are implemented by classes. They are also used to define constants, which are data values that cannot be changed.

Java programs are written using one or more compilation units, which are Java source code files. The names of these source code files are governed by the following rules:

  • If a source code file contains a public class or interface, then the name of the file is the public class or interface name, followed by the .java extension.

  • A source code file cannot contain more than one public class or interface.

  • Because Java identifiers are case sensitive, source code filenames are also case sensitive.

  • If a source code file does not contain a public class or interface, it can take on a name that is different from its classes and interfaces.

The above rules are important. You can expect to see more than one exam question that tests your knowledge of these rules.

  • + Share This
  • 🔖 Save To Your Account