Objectives In this chapter, we discuss the basic elements of Java, including operators
and expressions, data types, garbage collection, control structures, class
declaration, parameter passing, packages and exceptions. Some of the more
commonly used classes in the Java Class Library are also discussed. A number
simple programs are presented to demonstrate string manipulation and simple
input and output. A simple animation applet is also presented.
Contents 3.1 Lexical Elements
3.1.1 Character Set
3.1.2 Identifiers
3.1.3 Primitive Types and Literals
3.1.4 Operators and Expressions
3.2 Variables and Types
3.2.1 Variable Declarations
3.2.2 Type Compatibility and Conversion
3.2.3 Reference Types
3.2.4 Arrays
3.3 Statements
3.3.1 Statement Labels
3.3.2 Statement Blocks
3.3.3 Simple Statements
3.3.4 Compound Statements
3.3.5 Multi-Level Breaking
3.4 Class Declarations
3.4.1 Class Syntax
3.4.2 Creating and Initializing Objects
3.4.3 Accessing Members
3.4.4 Method Invocation and Parameter
Passing
3.4.5 Static Fields and Methods
3.4.6 Object Reference this
3.4.7 Interfaces and Abstract Classes
3.4.8 Strings
3.4.9 Wrapper Classes
3.5 Packages
3.6 Exceptions
3.7 A Simple Animation Applet