Monday, January 25, 2016

Anatomy of a JAVA Program


  • Comments 

    In Java, comments are preceded by two slashes (//) in a line, or enclosed between /* and */ in one or multiple lines. When the compiler sees //, it ignores all text after // in the same line. When it sees /*, it scans for the next */ and ignores any text between /* and */.

  • Package 

    A package is a grouping of related types providing access protection and name space management. Note that types refers to classes, interfaces, enumerations, and annotation types. Enumerations and annotation types are special kinds of classes and interfaces, respectively, so types are often referred to in this lesson simply as classes and interfaces.

  • Reserved Words

  • Reserved words or keywords are words that have a specific meaning to the compiler and cannot be used for other purposes in the program. For example, when the compiler sees the word class, it understands that the word after class is the name for the class. Their use will be introduced later in the course.

  • Modifiers


    Java uses certain reserved words called modifiers that specify the properties of the data, methods, and classes and how they can be used. Examples of modifiers are public and static. Other modifiers are private, final, abstract, and protected. A public datum, method, or class can be accessed by other programs. A private datum or method cannot be accessed by other programs. Modifiers are discussed in later chapter.
  • Statements

  • A statement represents an action or a sequence of actions. The statement System.out.println("Welcome to Java!") in the program is a statement to display the greeting "Welcome to Java!“. Every statement in Java ends with a semicolon (;).
  • Blocks

  • A pair of braces in a program forms a block that groups components of a program.

  • Classes


    The class is the essential Java construct. A class is a template or blueprint for objects. To program in Java, you must understand classes and be able to write and use them. The mystery of the class will continue to be unveiled throughout this course. For now, though, understand that a program is defined by using one or more classes.

  • Methods


    What is System.out.println? It is a method : a collection of statements that performs a sequence of operations to display a message on the console. It can be used even without fully understanding the details of how it works. It is used by invoking a statement with a string argument. The string argument is enclosed within parentheses. In this case, the argument is "Welcome to Java!" You can call the same println method with a different argument to print a different message.

  • The main method


    The main method provides the control of program flow. The Java interpreter executes the application by invoking the main method.
      public static void main( String[] args ) {
      // Statements;
      }

1 comment: