目录

  • 1 Introduction
    • 1.1 Introduction
    • 1.2 Machine Lang, Assembly lang and High-level lang
    • 1.3 History of Java
    • 1.4 Characteristics of Java
    • 1.5 Typical Java Development Environment
    • 1.6 Introduction to Java Application
  • 2 Classes and Objects
    • 2.1 Primitive Types vs. Reference Types
    • 2.2 Classes and Objects
      • 2.2.1 Declaring a Class
      • 2.2.2 Local and Instance Variables
      • 2.2.3 Methods: A Deeper Look
      • 2.2.4 Constructors
  • 3 Control Statements
    • 3.1 Control Structures
    • 3.2 if Selection
    • 3.3 while Repetition
    • 3.4 for Repetition
    • 3.5 do…while repetition
    • 3.6 switch multiple-selection
  • 4 Arrays and Collections
    • 4.1 Arrays
    • 4.2 ArrayList
    • 4.3 Set
    • 4.4 Generic Programming
  • 5 Object-Oriented Programming: Inheritance
    • 5.1 Inheritance
    • 5.2 Superclasses and Subclasses
    • 5.3 Constructors in Subclasses
  • 6 Object-Oriented Programming: Polymorphism
    • 6.1 Polymorphism
    • 6.2 Polymorphic Behavior
    • 6.3 Enable and Disable Polymorphism
  • 7 Exception Handling
    • 7.1 Exceptions
    • 7.2 Error-Handling
  • 8 Java I/O
    • 8.1 Java I/O Streams
    • 8.2 Decorator Design Pattern
  • 9 GUI Components
    • 9.1 AWT and SWING
    • 9.2 Event Model
  • 10 Multithreading
    • 10.1 Life Cycle of a Thread
    • 10.2 Thread Synchronization
    • 10.3 Producer/Consumer
Control Structures

Control Structures


}Sequential execution: Statements in a program execute oneafter the other in the order in which they are written. 

}Transfer of control: Various Java statements, enable you tospecify that the next statement to execute is not necessarily the next one insequence. 

}Bohm and Jacopini

  §Demonstrated that programs could be written without any goto statements. 

  §All programs can be written interms of only three control structures—the sequencestructure, the selection structure and the repetitionstructure

}When we introduce Java’s control structure implementations, we’ll refer to them in the terminology of the Java Language Specification as“control statements.”

Three types of selection statements.

}if statement: 

  §Performs an action, if a conditionis true; skips it, if false. 

  §Single-selection statement—selects or ignores a single action (or group of actions). 

}ifelse statement: 

  §Performs an action if a conditionis true and performs a different action if the condition is false. 

  §Double-selection statement—selects between two different actions(or groups of actions). 

}switch statement

  §Performs one of several actions,based on the value of an expression.

  §Multiple-selection statement—selects among many different actions (orgroups of actions).

}Three repetitionstatements (also called looping statements

  §Perform statements repeatedly while a loop-continuation condition remains true. 

}while and for statements perform the action(s) in their bodies zero or more times

  §if the loop-continuation condition isinitially false, the body will not execute. 

}The dowhile statement performs the action(s) in itsbody one or more times. 

}ifelseswitchwhile,do and for are keywords.