copyright © 2003 prosofttraining. all rights reserved. sun certified java programmer exam...

81
Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Upload: amberlynn-benson

Post on 24-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Copyright © 2003 ProsoftTraining. All rights reserved.

Sun Certified Java Programmer Exam Preparation Guide

Page 2: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Copyright © 2003 ProsoftTraining. All rights reserved.

Lesson 1:Java Language Fundamentals

Page 3: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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

Page 4: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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

Page 5: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

JavaSource Files

• Java package and import statements• class

Page 6: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Keywords

• Creating identifiers

Page 7: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

PrimitiveData Types

• Eight types– boolean, char, byte, short, int, long, float, double

• Literals– Boolean– Character– Integral– Floating-point– String

Page 8: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

The Javamain Method

• Must be defined within a class• Must be defined as follows

Public static void main(String [] args)

Page 9: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

VariableInitialization

• Member variables• Method local variables

Page 10: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

TheMath Class

• Math class methods

Page 11: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

GarbageCollection

• Frees previously allocated heap space that is no longer needed

• Helps prevent most memory leaks

Page 12: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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

Page 13: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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

Page 14: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Copyright © 2003 ProsoftTraining. All rights reserved.

Lesson 2:Java Modifiers

Page 15: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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

Page 16: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Introductionto Java Modifiers

• Access modifiers• Other modifiers

Page 17: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Classes

• Abstract classes• Final classes

Page 18: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Methods

• Abstract methods• Final methods• Native methods• Static methods• Synchronized methods

Page 19: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Variables

• Final variables• Static variables• Transient variables• Volatile variables

Page 20: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

StaticInitializers

• Free-floating blocks of code that are executed at the time a class is loaded

Page 21: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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

Page 22: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Copyright © 2003 ProsoftTraining. All rights reserved.

Lesson 3:Flow Control

in Java

Page 23: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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

Page 24: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Thewhile Loop

• Simplest type of loop• Executes a statement or code block

continuously until some Boolean expression evaluates as false

Page 25: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Thedo Loop

• Special form of the while loop• Guaranteed to execute at least once

Page 26: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Thefor 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

Page 27: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Thecontinue Statement

• Ends the current iteration of a loop and continues execution at the top of the loop

Page 28: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

The breakStatement

• Used to exit a loop prematurely

Page 29: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

The if / elseStatement

• Permits execution of a statement or code block only if some Boolean expression is true

Page 30: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

The switchStatement

• Uses an integer value to select between multiple alternative threads of execution

Page 31: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Exceptions

• Errors• Runtime exceptions• Checked exceptions

Page 32: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Java ExceptionClass Hierarchy

Throwable

Exception Error

RuntimeException

Page 33: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

ThrowingExceptions

• throws statement

Page 34: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

CatchingExceptions

• try/catch block• Using multiple catch statements• Rethrowing exceptions• finally block

Page 35: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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

Page 36: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Copyright © 2003 ProsoftTraining. All rights reserved.

Lesson 4:Operators

and Assignments

Page 37: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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

Page 38: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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

Page 39: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Introductionto Expressions

• Operators• Operator precedence

Page 40: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

UnaryOperators

• The increment (++) and decrement (--) operators

• The plus (+) and minus (-) operators• The Boolean complement operator (!)• The bitwise inversion operator (~)• The cast operator

Page 41: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

ArithmeticOperators

• The multiplication (*) and division (/) operators• The modulus operator (%)• The addition (+) and subtraction (-) operators

Page 42: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

BinaryShift Operators

• The left-shift operator (<<)• The right-shift operator (>>)• The unsigned right-shift operator (>>>)• The right operand

Page 43: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

ComparisonOperators

• The equals method• The instanceof operator• Bitwise operators• The and operator (&)• The or operator (|)• The exclusive-or operator (^)

Page 44: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Short-CircuitOperators

• Similar to bitwise operators• Only applied to Boolean operands• Always generate a Boolean result

Page 45: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

TernaryOperator

• Requires three operands

Page 46: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

AssignmentOperators

• Methods and assignments

Page 47: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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

Page 48: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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

Page 49: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Copyright © 2003 ProsoftTraining. All rights reserved.

Lesson 5:Object Orientation

Page 50: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Objectives

• State the benefits of encapsulation in object-oriented 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

Page 51: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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

Page 52: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Encapsulation

• Accessors• Mutators• Encapsulation

Page 53: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Encapsulationof the Book Class

getTitle

getAuthor

getIS

BN

titleauthor

isbn

Page 54: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Abstraction

• The process of developing classes in terms of their– Interfaces– Functionality

• Used to manage complexity

Page 55: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

MethodOverloading 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

Page 56: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Constructors

• Instantiating a class• The this keyword• Constructors and inheritance• The super keyword and constructors

Page 57: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

InnerClasses

• Member inner classes– Member access

• Static inner classes• Method inner classes• Anonymous inner classes

Page 58: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Arrays

• Array declarations• Constructing arrays• Initializing arrays

Page 59: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Summary

State the benefits of encapsulation in object-oriented 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

Page 60: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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

Page 61: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Copyright © 2003 ProsoftTraining. All rights reserved.

Lesson 6:Threads

Page 62: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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

Page 63: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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

Page 64: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

CreatingThreads

• Extending the Thread class• Implementing the Runnable interface

Page 65: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

ThreadStates

• Setting thread priority• Yielding threads• The suspended state• The sleeping state• The blocked state

Page 66: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

LiveThread States

Running

Ready

Suspended Sleeping Blocked

Page 67: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

ThreadSynchronization

• Controlling the flow of multiple simultaneous threads

• The synchronized keyword• Monitors• Synchronized code blocks• The wait, notify and notifyAll methods• Deadlock

Page 68: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Deadlock

Page 69: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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

Page 70: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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

Page 71: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Copyright © 2003 ProsoftTraining. All rights reserved.

Lesson 7:The java.awt Package

Page 72: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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

Page 73: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

LayoutManagers

• Flow layout manager• Border layout manager• Grid layout manager• Card layout manager• GridBag layout manager

Page 74: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Events

• Event classes• Event listeners• Event enabling

Page 75: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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

Page 76: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Copyright © 2003 ProsoftTraining. All rights reserved.

Lesson 8:The Collections API

Page 77: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Objective

• Make appropriate selection of collection classes/interfaces to suit specified behavior requirements

Page 78: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Introductionto Collections

• Simple collections– Vectors– Hash tables

• Types of collections– Collection– List– Set– Map

Page 79: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

TheCollections API

• Java application programming interface that provides an extensible framework for creating data structures

• Using the Collections API

Page 80: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

Summary

Make appropriate selection of collection classes/interfaces to suit specified behavior requirements

Page 81: Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide

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