Transcript Document

Sun Certified Java Programmer
Exam Preparation Guide
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 1:
Java Language Fundamentals
Copyright © 2002 ProsoftTraining. All rights reserved.
Objectives
• Identify correctly constructed source files,
package declarations, import statements,
class declarations, interface declarations and
implementations, method declarations,
variable declarations and identifiers
• State the correspondence between index
values in the argument array passed to a main
method and command-line arguments
• Identify all Java programming language
keywords and correctly constructed identifiers
Objectives
(cont’d)
• State the effect of using a variable or array
element of any kind when no explicit
assignment has been made to it
• State the range of all primitive data types
• State the behavior that is guaranteed by the
garbage collection system
• Write code using methods of the
java.lang.Math class
Java
Source Files
• Java package and import statements
• class
Keywords
• Creating identifiers
Primitive
Data Types
• Eight types
– boolean, char, byte, short, int, long,
float, double
• Literals
– Boolean
– Character
– Integral
– Floating-point
– String
The Java
main Method
• Must be defined within a class
• Must be defined as follows
Public static void main(String [] args)
Variable
Initialization
• Member variables
• Method local variables
The
Math Class
• Math class methods
Garbage
Collection
• Frees previously allocated heap space that is
no longer needed
• Helps prevent most memory leaks
Summary
 Identify correctly constructed source files,
package declarations, import statements,
class declarations, interface declarations and
implementations, method declarations,
variable declarations and identifiers
 State the correspondence between index
values in the argument array passed to a main
method and command-line arguments
 Identify all Java programming language
keywords and correctly constructed identifiers
Summary
(cont’d)
 State the effect of using a variable or array
element of any kind when no explicit
assignment has been made to it
 State the range of all primitive data types
 State the behavior that is guaranteed by the
garbage collection system
 Write code using methods of the
java.lang.Math class
Lesson 2:
Java Modifiers
Copyright © 2002 ProsoftTraining. All rights reserved.
Objectives
• Declare classes, inner classes, methods,
instance variables, static variables, and
automatic variables making appropriate use of
all permitted modifiers. State the significance
of each of these modifiers both singly and in
combination, and state the effect of package
relationships on declared items qualified by
these modifiers
Introduction
to Java Modifiers
• Access modifiers
• Other modifiers
Classes
• Abstract classes
• Final classes
Methods
•
•
•
•
•
Abstract methods
Final methods
Native methods
Static methods
Synchronized methods
Variables
•
•
•
•
Final variables
Static variables
Transient variables
Volatile variables
Static
Initializers
• Free-floating blocks of code that are executed
at the time a class is loaded
Summary
 Declare classes, inner classes, methods,
instance variables, static variables, and
automatic variables making appropriate use of
all permitted modifiers. State the significance
of each of these modifiers both singly and in
combination, and state the effect of package
relationships on declared items qualified by
these modifiers
Lesson 3:
Flow Control
in Java
Copyright © 2002 ProsoftTraining. All rights reserved.
Objectives
• Write code using if and switch statements
• Write code using all forms of loops, and state
the values taken by loop control variables
during and after loop execution
• Write code that makes proper use of
exceptions and exception handling clauses,
and declare methods and overriding methods
that throw exceptions
The
while Loop
• Simplest type of loop
• Executes a statement or code block
continuously until some Boolean expression
evaluates as false
The
do Loop
• Special form of the while loop
• Guaranteed to execute at least once
The
for Loop
• Allows you to initialize a variable and perform
some iterative arithmetic on that variable,
executing a loop until some Boolean condition
evaluates to false
• Comma separators
The
continue Statement
• Ends the current iteration of a loop and
continues execution at the top of the loop
The break
Statement
• Used to exit a loop prematurely
The if / else
Statement
• Permits execution of a statement or code
block only if some Boolean expression is true
The switch
Statement
• Uses an integer value to select between
multiple alternative threads of execution
Exceptions
• Errors
• Runtime exceptions
• Checked exceptions
Java Exception
Class Hierarchy
Throwable
Exception
Error
RuntimeException
Throwing
Exceptions
• throws statement
Catching
Exceptions
•
•
•
•
try/catch block
Using multiple catch statements
Rethrowing exceptions
finally block
Summary
 Write code using if and switch statements
 Write code using all forms of loops, and state
the values taken by loop control variables
during and after loop execution
 Write code that makes proper use of
exceptions and exception handling clauses,
and declare methods and overriding methods
that throw exceptions
Lesson 4:
Operators
and Assignments
Copyright © 2002 ProsoftTraining. All rights reserved.
Objectives
• Determine the result of applying any operator,
to operands of any type, class, scope or
accessibility, or any combination of these
• Determine the result of applying the Boolean
equals(Object) method to objects of any
combination of the classes
java.lang.String, java.lang.Boolean
and java.lang.Object
Objectives
(cont'd)
• In an expression involving the operators &, |,
&&, || and variables of known values, state
which operands are evaluated and the value of
the expression
• Determine the effect upon objects and
primitive values of passing variables into
methods and performing assignments or other
modifying operations in that method
Introduction
to Expressions
• Operators
• Operator precedence
Unary
Operators
• The increment (++) and decrement (--)
operators
• The plus (+) and minus (-) operators
• The Boolean complement operator (!)
• The bitwise inversion operator (~)
• The cast operator
Arithmetic
Operators
• The multiplication (*) and division (/) operators
• The modulus operator (%)
• The addition (+) and subtraction (-) operators
Binary
Shift Operators
•
•
•
•
The left-shift operator (<<)
The right-shift operator (>>)
The unsigned right-shift operator (>>>)
The right operand
Comparison
Operators
•
•
•
•
•
•
The equals method
The instanceof operator
Bitwise operators
The and operator (&)
The or operator (|)
The exclusive-or operator (^)
Short-Circuit
Operators
• Similar to bitwise operators
• Only applied to Boolean operands
• Always generate a Boolean result
Ternary
Operator
• Requires three operands
Assignment
Operators
• Methods and assignments
Summary
 Determine the result of applying any operator,
to operands of any type, class, scope or
accessibility, or any combination of these
 Determine the result of applying the Boolean
equals(Object) method to objects of any
combination of the classes
java.lang.String, java.lang.Boolean
and java.lang.Object
Summary
(cont'd)
 In an expression involving the operators &, |,
&&, || and variables of known values, state
which operands are evaluated and the value of
the expression
 Determine the effect upon objects and
primitive values of passing variables into
methods and performing assignments or other
modifying operations in that method
Lesson 5:
Object Orientation
Copyright © 2002 ProsoftTraining. All rights reserved.
Objectives
• State the benefits of encapsulation in objectoriented design, and write code that
implements tightly encapsulated classes and
the "is a" and "has a" relationships
• Write code to invoke overridden or overloaded
methods and parental or overloaded
constructors
• Write code to construct instances of any
concrete class
Objectives
(cont'd)
• State the legal return types for any method
given the declarations of all related methods
in this or parent classes
• Write code that declares, constructs and
initializes arrays of any base type using any of
the permitted forms for both declaration and
initialization
• For a given class, determine whether a default
constructor will be created, and state the
prototype of that constructor
Encapsulation
• Accessors
• Mutators
• Encapsulation
title
author
isbn
getAuthor
tl e
tTi
ge
ge
tIS
BN
Encapsulation
of the Book Class
Abstraction
• The process of developing classes in terms of
their
– Interfaces
– Functionality
• Used to manage complexity
Method
Overloading and Overriding
• Overloading
– Defining several methods with the same
name within a single class
• Overriding
– Refining the functionality of a subclass by
modifying a class method under certain
circumstances
• The super keyword
Constructors
•
•
•
•
Instantiating a class
The this keyword
Constructors and inheritance
The super keyword and constructors
Inner
Classes
• Member inner classes
– Member access
• Static inner classes
• Method inner classes
• Anonymous inner classes
Arrays
• Array declarations
• Constructing arrays
• Initializing arrays
Summary
 State the benefits of encapsulation in objectoriented design, and write code that
implements tightly encapsulated classes and
the "is a" and "has a" relationships
 Write code to invoke overridden or overloaded
methods and parental or overloaded
constructors
 Write code to construct instances of any
concrete class
Summary
(cont'd)
 State the legal return types for any method
given the declarations of all related methods
in this or parent classes
 Write code that declares, constructs and
initializes arrays of any base type using any of
the permitted forms for both declaration and
initialization
 For a given class, determine whether a default
constructor will be created, and state the
prototype of that constructor
Lesson 6:
Threads
Copyright © 2002 ProsoftTraining. All rights reserved.
Objectives
• Write code to define, instantiate and start
new threads using both
java.lang.Thread and
java.lang.Runnable
• Recognize conditions that might prevent
a thread from executing
Objectives
(cont'd)
• Write code using synchronized, wait,
notify and notifyAll to protect against
concurrent access problems and to
communicate between threads. Define the
interaction between threads, and between
threads and object locks
• Identify correctly constructed source files,
package declarations, import statements,
class declarations, interface declarations and
implementations, method declarations,
variable declarations and identifiers
Creating
Threads
• Extending the Thread class
• Implementing the Runnable interface
Thread
States
•
•
•
•
•
Setting thread priority
Yielding threads
The suspended state
The sleeping state
The blocked state
Live
Thread States
Running
Suspended
Ready
Sleeping
Blocked
Thread
Synchronization
• Controlling the flow of multiple simultaneous
threads
• The synchronized keyword
• Monitors
• Synchronized code blocks
• The wait, notify and notifyAll methods
• Deadlock
Deadlock
Thread2
ObjectA
{
synchronized methodA()
}
Thread1
blocked
blocked
ObjectB
{
synchronized methodB()
}
Summary
 Write code to define, instantiate and start new
threads using both java.lang.Thread and
java.lang.Runnable
 Recognize conditions that might prevent a
thread from executing
Summary
(cont'd)
 Write code using synchronized, wait,
notify and notifyAll to protect against
concurrent access problems and to
communicate between threads. Define the
interaction between threads, and between
threads and object locks
 Identify correctly constructed source files,
package declarations, import statements,
class declarations, interface declarations and
implementations, method declarations,
variable declarations and identifiers
Lesson 7:
The java.awt Package
Copyright © 2002 ProsoftTraining. All rights reserved.
Objectives
• Write code using component, container and
layout manager classes of the java.awt
package to present a GUI with specified
appearance and resize behavior, and
distinguish the responsibilities of layout
managers from those of containers
• Write code to implement listener classes and
methods; in listener methods, extract
information from the event to determine the
affected component, mouse position, nature
and time of the event
Layout
Managers
•
•
•
•
•
Flow layout manager
Border layout manager
Grid layout manager
Card layout manager
GridBag layout manager
Events
• Event classes
• Event listeners
• Event enabling
Summary
 Write code using component, container and
layout manager classes of the java.awt
package to present a GUI with specified
appearance and resize behavior, and
distinguish the responsibilities of layout
managers from those of containers
 Write code to implement listener classes and
methods; in listener methods, extract
information from the event to determine the
affected component, mouse position, nature
and time of the event
Lesson 8:
The Collections API
Copyright © 2002 ProsoftTraining. All rights reserved.
Objective
• Make appropriate selection of collection
classes/interfaces to suit specified behavior
requirements
Introduction
to Collections
• Simple collections
– Vectors
– Hash tables
• Types of collections
– Collection
– List
– Set
– Map
The
Collections API
• Java application programming interface that
provides an extensible framework for creating
data structures
• Using the Collections API
Summary
 Make appropriate selection of collection
classes/interfaces to suit specified behavior
requirements
Sun Certified Java Programmer
Exam Preparation Guide








Java Language Fundamentals
Java Modifiers
Flow Control in Java
Operators and Assignments
Object Orientation
Threads
The java.awt Package
The Collections API