Upload
yeri-yezyan
View
217
Download
0
Embed Size (px)
Citation preview
8/7/2019 Java Notas
1/14
Sun Certified Programmer for Java 2 Study Guide Tables and Figures
JCTV 1 3/12/2007
8/7/2019 Java Notas
2/14
Sun Certified Programmer for Java 2 Study Guide Tables and Figures
JCTV 2 3/12/2007
8/7/2019 Java Notas
3/14
Sun Certified Programmer for Java 2 Study Guide Tables and Figures
JCTV 3 3/12/2007
8/7/2019 Java Notas
4/14
Sun Certified Programmer for Java 2 Study Guide Tables and Figures
JCTV 4 3/12/2007
8/7/2019 Java Notas
5/14
Sun Certified Programmer for Java 2 Study Guide Tables and Figures
JCTV 5 3/12/2007
8/7/2019 Java Notas
6/14
Sun Certified Programmer for Java 2 Study Guide Tables and Figures
JCTV 6 3/12/2007
8/7/2019 Java Notas
7/14
Sun Certified Programmer for Java 2 Study Guide Tables and Figures
JCTV 7 3/12/2007
Car extends Vehicle means Car IS-A Vehicle.Subaru extends Car means Subaru IS-A Car.
8/7/2019 Java Notas
8/14
Sun Certified Programmer for Java 2 Study Guide Tables and Figures
JCTV 8 3/12/2007
8/7/2019 Java Notas
9/14
Sun Certified Programmer for Java 2 Study Guide Tables and Figures
JCTV 9 3/12/2007
Modifiers and Access Modifiers
Local Variables Variables (non-Local) Methods Classes
finalpublic
protectedprivatestatic
publicdefault
final
finalpublic
protectedprivatestatic
transient
abstractsynchronized
strictfpnative
Final
Modifiers and Access Modifiers
Modifier Class Variable Method ConstructorFree-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
synchronizedno no yes no yes
8/7/2019 Java Notas
10/14
Sun Certified Programmer for Java 2 Study Guide Tables and Figures
JCTV 10 3/12/2007
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, twos complement
\u0000\uFFFF
byte signed integer 0 8 bits, twos complement-2
7 2
7-1
short signed integer 0 16 bits, twos complement
-2
15 2
15-1
int signed integer 0 32 bits, twos complement
-2
31 2
31-1
long signed integer 0 64 bits, twos 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
8/7/2019 Java Notas
11/14
Sun Certified Programmer for Java 2 Study Guide Tables and Figures
JCTV 11 3/12/2007
Class Member Accessibility
Member VisibilityModifier
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
defaultprivate
Same class yes yes yes yesClass in same package yes yes yes
Subclass in same package yes yes yes
Subclass in different package yes yes
Non-subclass, different package yes
8/7/2019 Java Notas
12/14
8/7/2019 Java Notas
13/14
Sun Certified Programmer for Java 2 Study Guide Tables and Figures
JCTV 13 3/12/2007
Java Modifiers
Modifier Used On Meaning
classThe class contains unimplemented methods and cannot beinstantiated.
interface
All interfaces are abstract. The modifier is optional in interface
declarations.abstract
methodNo body is provided for the method (it is provided by a subclass).The signature is followed by a semicolon. The enclosing classmust also be abstract.
class The class may not be subclassed.
fieldThe field may not have its value changed (compiler mayprecompute expressions).
method The method may not be overridden (compiler may optimize).final
variableJava 1.1 and later: the local variable or method or exceptionparameter may not have its value changed.
native methodThe 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
interface A non-public interface is accessible only in its packagenone (package)
memberA member that is not private, protected, or public has packagevisiblity and is accessible only within its package.
private member The member is only accessible within the class that defines it.
protected memberThe member is only accessible within the package in which it isdefined, and within subclasses.
class The class is accessible anywhere its package is.
interface The interface is accessible anywhere its package is.public
member The member is accessible anywhere its class is.
class In Java 1.1, a class delared static is a toplevel class, not an innerclass.
fieldA static field is a "class field." There is only one instance of thefield, regardless of the number of class instances created. It maybe accessed through the class name.
initializerThe intializer is run when the class is loaded, rather than when aninstance is created.
static
methodA static method is a "class method." It is not passed as an implicitthis object reference. It may be invoked through the class name.
synchronized method
The method makes non-atomic modifications to the class orinstance, and care must be taken to ensure that two threadscannot modify the class or instance at the same time. For a staticmethod, a lock for the class is acquired before executing the
method. For a non-static method, a lock for the specific objectinstance is acquired.
transient fieldThe field is not part of the persistent state of the object, and shouldnot be serialized with the object.
volatile fieldThe field may be accessed by unsynchronized threads, so certaincode optimizations must not be performed on it.
8/7/2019 Java Notas
14/14
Sun Certified Programmer for Java 2 Study Guide Tables and Figures
JCTV 14 3/12/2007
Strings
Consider this table showing two situations using the == operator and equals():
s1 == s2 s1.equals(s2)
AString s1 = Java;
String s2 = Java;true true
BString s = Ja;
String s1 = s + va;
String s2 = Java;
false true
In situation A, the evaluation will always return true, since there is only one Stringobject 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 asdifferent objects.
In situation B, s1 and s2 are pointing to different objects, because s1 is created at
runtime.
byte intshort long
float
char
double
Legal Conversions Between Numeric Types