Vous êtes sur la page 1sur 14

Sun Certified Programmer for Java 2 Study Guide

Tables and Figures

Sun Certified Programmer for Java 2 Study Guide Tables and Figures JCTV 1 3/12/2007
Sun Certified Programmer for Java 2 Study Guide Tables and Figures JCTV 1 3/12/2007
Sun Certified Programmer for Java 2 Study Guide Tables and Figures JCTV 1 3/12/2007

Sun Certified Programmer for Java 2 Study Guide

Tables and Figures

Sun Certified Programmer for Java 2 Study Guide Tables and Figures JCTV 2 3/12/2007

Sun Certified Programmer for Java 2 Study Guide

Tables and Figures

Sun Certified Programmer for Java 2 Study Guide Tables and Figures JCTV 3 3/12/2007

Sun Certified Programmer for Java 2 Study Guide

Tables and Figures

Sun Certified Programmer for Java 2 Study Guide Tables and Figures JCTV 4 3/12/2007

Sun Certified Programmer for Java 2 Study Guide

Tables and Figures

Sun Certified Programmer for Java 2 Study Guide Tables and Figures JCTV 5 3/12/2007
Sun Certified Programmer for Java 2 Study Guide Tables and Figures JCTV 5 3/12/2007

Sun Certified Programmer for Java 2 Study Guide

Tables and Figures

Sun Certified Programmer for Java 2 Study Guide Tables and Figures JCTV 6 3/12/2007
Sun Certified Programmer for Java 2 Study Guide Tables and Figures JCTV 6 3/12/2007

Sun Certified Programmer for Java 2 Study Guide

Tables and Figures

Programmer for Java 2 Study Guide Tables and Figures “Car extends Vehicle” means “Car IS-A Vehicle.”

“Car extends Vehicle” means “Car IS-A Vehicle.” “Subaru extends Car” means “Subaru IS-A Car.”

Sun Certified Programmer for Java 2 Study Guide

Tables and Figures

Sun Certified Programmer for Java 2 Study Guide Tables and Figures JCTV 8 3/12/2007

Sun Certified Programmer for Java 2 Study Guide

Tables and Figures

Modifiers and Access Modifiers

Local Variables

Variables (non-Local)

Methods

Classes

final public public protected final default private public static protected final private static abstract
final
public
public
protected
final
default
private
public
static
protected
final
private
static
abstract
transient
synchronized
Final
strictfp
native
 

Modifiers and Access Modifiers

 

Modifier

Class

Variable

Method

Constructor

Free-Floating

Block

public

yes

yes

yes

yes

no

protected

no

yes

yes

yes

no

(default)

yes

yes

yes

yes

yes

private

no

yes

yes

yes

no

final

yes

yes

yes

no

no

abstract

yes

no

yes

no

no

static

no

yes

yes

no

yes

native

no

no

yes

no

no

transient

no

yes

no

no

no

volatile

no

yes

no

no

no

synchronized

no

no

yes

no

yes

Sun Certified Programmer for Java 2 Study Guide

Tables and Figures

Default Values for Array Elements

Array Type

Default Value

byte

0

char

'\u0000'

short

0

int

0

long

0L

float

0.0F

double

0.0

Boolean

false

Object reference

null

 

Java Primitive Data Types

 

Type

Contains

Default

 

Size

Min/Max Value

boolean

true or false

false

1

bit

N.A.

       

N.A.

char

Unicode character

\u0000

16

bits, two’s complement

\u0000

       

\uFFFF

byte

signed integer

0

8

bits, two’s complement

-2 7 2 7 -1

       

short

signed integer

0

16

bits, two’s complement

-2 15 2 15 -1

       

int

signed integer

0

32

bits, two’s complement

-2 31 2 31 -1

       

long

signed integer

0

64

bits, two’s complement

-2 63 2 63 -1

       

float

floating-point

0.0

32

bits, IEEE 754

+/-1.40239846E-45

       

+/-3.40282347E+38

double

floating-point

0.0

64

bits, IEEE 754

+/-4.94065645841246544E-324

       

+/-1.79769313486231570E+308

 

Java Escape Sequences

Escape Sequence

Unicode Equivalent

Meaning

\b

\u0008

Backspace

\t

\u0009

Horizontal tab

\n

\u000a

Linefeed

\f

\u000c

Form feed

\r

\u000d

Carriage return

\"

\u0022

Double quote

\'

\u0027

Single quote

\\

\u005c

Backslash

\xxx

\u0000 to \u00ff

The character corresponding to the octal value xxx

Sun Certified Programmer for Java 2 Study Guide

Tables and Figures

 

Class Member Accessibility

   

Modifier

 

Member Visibility

 

same class

same package

subclass

Universe

private

yes

     

default

yes

yes

   

protected

yes

yes

 

yes

 

public

yes

yes

 

yes

 

yes

 

Class Member Accessibility

 
   

Member Visibility

 

Accessible to:

public

protected

package o

private

default

Same class

yes

yes

yes

yes

Class in same package

yes

yes

yes

 

Subclass in same package

yes

yes

yes

 

Subclass in different package

yes

yes

   

Non-subclass, different package

yes

     

Sun Certified Programmer for Java 2 Study Guide

Tables and Figures

 

Java Operators

 

Prec.

Operator

Operand Type(s)

Assoc.

Operation Performed

1

++

arithmetic

pre-or-post increment (unary)

 

--

arithmetic

pre-or-post decrement (unary)

 

+, -

arithmetic

unary plus, unary minus

 

~

integral

bitwise complement (unary)

 

!

boolean

logical complement (unary)

 

(type)

any

cast

2

*, /, %

arithmetic

multiplication, division, remainder

3

+, -

arithmetic

addition, subtraction

 

+

string

string concatenation

4

<<

integral

left shift

 

>>

integral

right shift with sign extension

 

>>>

integral

right shift with zero extension

5

<, <=

arithmetic

less than, less than or equal

 

>, >=

arithmetic

greater than, greater than or equal

 

instanceof

object, type

type comparison

6

==

primitive

equal (have identical values)

 

!=

primitive

not equal (have different values)

 

==

object

equal (refer to same object)

 

!=

object

not equal (refer to different objects)

7

&

integral

bitwise AND

 

&

boolean

boolean AND

8

^

integral

bitwise XOR

 

^

boolean

boolean XOR

9

|

integral

bitwise OR

 

|

boolean

boolean OR

10

&&

boolean

conditional AND

11

||

boolean

conditional OR

12

?:

boolean, any, any

conditional (ternary) operator

13

=

variable, any

assignment

 

*=, /=, %=, +=, -=, <<=, >>=, >>>=, &=, ^=, |=

variable, any

assignment with operation

Sun Certified Programmer for Java 2 Study Guide

Tables and Figures

 

Java Modifiers

Modifier

Used On

 

Meaning

 

class

The class contains unimplemented methods and cannot be instantiated.

abstract

interface

All interfaces are abstract. The modifier is optional in interface declarations.

method

No body is provided for the method (it is provided by a subclass). The signature is followed by a semicolon. The enclosing class must also be abstract.

 

class

The class may not be subclassed.

final

field

The field may not have its value changed (compiler may precompute expressions).

method

The method may not be overridden (compiler may optimize).

variable

Java 1.1 and later: the local variable or method or exception parameter may not have its value changed.

native

method

The method is implemented in C, or in some other platform- dependent way. No body is provided; the signature is followed by a semicolon.

 

class

A non-public class is accessible only in its package

none (package)

interface

A non-public interface is accessible only in its package

member

A member that is not private, protected, or public has package

 

visiblity and is accessible only within its package.

private

member

The member is only accessible within the class that defines it.

protected

member

The member is only accessible within the package in which it is defined, and within subclasses.

 

class

The class is accessible anywhere its package is.

public

interface

The interface is accessible anywhere its package is.

member

The member is accessible anywhere its class is.

 

class

In

Java 1.1, a class delared static is a toplevel class, not an inner

class.

 

A

static field is a "class field." There is only one instance of the

field

field, regardless of the number of class instances created. It may

static

be accessed through the class name.

initializer

The intializer is run when the class is loaded, rather than when an instance is created.

method

A

static method is a "class method." It is not passed as an implicit

this object reference. It may be invoked through the class name.

synchronized

method

The method makes non-atomic modifications to the class or instance, and care must be taken to ensure that two threads cannot modify the class or instance at the same time. For a static method, a lock for the class is acquired before executing the method. For a non-static method, a lock for the specific object instance is acquired.

transient

field

The field is not part of the persistent state of the object, and should not be serialized with the object.

volatile

field

The field may be accessed by unsynchronized threads, so certain code optimizations must not be performed on it.

Sun Certified Programmer for Java 2 Study Guide

Tables and Figures

Legal Conversions Between Numeric Types

byte

byte short char int long float double

short

char int
char
int

long

float double
float
double

Strings

Consider this table showing two situations using the == operator and equals():

   

s1 == s2

s1.equals(s2)

A

String s1 = “Java”; String s2 = “Java”;

true

true

 

String s

= “Ja”;

   

B

String s1 = s + “va”; String s2 = “Java”;

false

true

In situation A, the evaluation will always return true, since there is only one String object created (s1 and s2 are both pointing to the same one).

To avoid the above situation, use the new keyword so that s1 and s2 are created as different objects.

In situation B, s1 and s2 are pointing to different objects, because s1 is created at runtime.