prev next prev next
  Course navigation
 
Lesson 2
Objective
Source files and compilation units
Relationship between Java programs, source files, and compilation units
    Source Code Files
Source files and compilation units
Describe the relationship between Java programs, source files, and compilation units.
You write Java programs by declaring classes and interfaces in source code files, referred to as compilation units.
Classes are the cornerstone of Java programs. They declare variables, methods , and constructors .
  1. Variables are used to store the values of primitive types and provide references to objects .
  2. Methods are used to access variables and perform operations on them.
  3. Constructors are used to create objects, which are instances of classes.
Interfaces define constants and methods. For a class to implement a particular interface, it must implement all of the methods that are defined in the interface. A class can define any constant whether or not the constants are already defined in the interfaces implemented by the class.
The structure of Java programs
Java source code files end with the .java extension and contain at least one class or interface declaration. A source code file may declare, at most, one public class or interface. If a source code file declares a public class or interface, the file's name must match that of the class or interface.
  Course navigation