OCJP 6
Questions to the Certification Oracle Java 6 Programmer based on the study guide
Questions to the Certification Oracle Java 6 Programmer based on the study guide
Fichier Détails
Cartes-fiches | 51 |
---|---|
Langue | English |
Catégorie | Informatique |
Niveau | Université |
Crée / Actualisé | 08.05.2013 / 18.04.2016 |
Lien de web |
https://card2brain.ch/box/ocjp_6
|
Intégrer |
<iframe src="https://card2brain.ch/box/ocjp_6/embed" width="780" height="150" scrolling="no" frameborder="0"></iframe>
|
Créer ou copier des fichiers d'apprentissage
Avec un upgrade tu peux créer ou copier des fichiers d'apprentissage sans limite et utiliser de nombreuses fonctions supplémentaires.
Connecte-toi pour voir toutes les cartes.
member acces comes in two forms
- code in one class can acsess a member of another clas
- a subclass can inherit a member of its superclass
member access rules
- if a superclass memeber is public, the subclass inherits it - regardless of package
- members accessed without the dot operator (.) must belong to the same class
- this. always refers to the currently executing object
- this.aMehtod() is the same as just invoking aMethod()
- private members can be accessed only by cone in the same class
- private members are not visible to subclasses, so private members cannot be inherited
default and protected members
- differ only when subclasses ar involved
- default members can be accessed only by classes in the same package
- protected members can be accessed by other classes in the same package, plus subclasses reagdless of package
- protected = package plus kids (subclasses)
- inheritance is the only mechanism for a subclass outside the package to access a protected member of its superclass)
- a protected member inherited by a subclass form another package is not accessible to any other class in the subclass package, except for the subclass own subclasses
Local variables
- loca (method, automatic, or stack) variable declarations cannot have access modifiers
- final is the only modifiers available to local variables
- local variables don't get default values, so they must be initialized before use
three ways to spot an non-abstract method:
- the method is not marked abstract
- the method has curly braces
- the method has code between the curly braces
Methods with var-args
- a var-arg parameter is declared with the syntay type ... name; for instance: doStuff(int...x){ }
- a var-arg method can have only on var-arg parameter
- in methods with normal parmeters and a var-arg, the var-arg must come last
Array declarations
- arrays can hold primitives or objects, but the array itself is always an object
- brackets can be left or right of the variable name
- it is never legal to include the size of an array in the declaration
- an array of objects can hold any object that passes the IS-A (or instanceof) test for the declared type of the array. For example, if Horse extends Animal, then a Horse object can go into an Animal array
static variables an methods
- they are not tied to any particular instance of a class
- no classes instances are needed in order to use static members of the class
- ther is only one copy of a static variable / class and all instances share it
- static methods do not have direct access to non-static members
enums
- an enum specifies a list of constant values assigned to a type
- an enum is not a string or an int
- an enum can declared outside or inside a class, but NOT in a method
- outside a classe an enum must NOT marked static, final, abstract, protected or private
- the semicolon at the end of an enum declaration is optional. These are legal:
- enum Foo { ONE, TWO, THREE }
- enum Foo { ONE, TWO, THREE };
- myEnum.values() returns an array of myEnums values
enums can contain
- constructors
- methods
- variables
- constant class bodies
enum constructors
- can be send constants, using the syntax BIG(8), where the int 8 is passed to the enum constructor
- can have arguments
- can be overloaded
- can NEVER be invoked directly in code. They are always called automatically when an enum is initialized
Local Variables (definition)
- Local variables are declared in methods, constructors or blocks
- are dreated wehen teh method, constructor or block is entered and the variable will be destroyed once it exits the method, constructor or block
- access modifiers cannot be used for local variables
- local variables are implemented at stack level internally
- there is no default vlaue for local variables so local variables should be declared and an inital value should be assigned befoer the first use
instance variables (definition)
- instance variables are declared in a class, but outside a method, constructor or any block
- when a space is allocated for an object in the heap a slot for each instance variable value is created
- instance variables are created when an object is created with the use of the key word 'new' and destroyed when the object is destroyed
- instance variables hold values that must be referenced by more than one method, constructor or block, or essential parts of an objects state that must be present through out the class
- instance variables can be declared in class level before or after use
- access modifiers can be given for instance variables
- instance variables have default values. For numbers the default value is 0, for Boolean it is false and for object references it is null. Values can be assigned during the declaration or within the constructor
advantage of encapsulation
- maintainability
- flexibility
How to do encapsulation?
- keep instance variables protected (with an access modifier, often private)
- make public accessor methods, and force calling code to use those methods rather than directly accessing the instance variable
- for the methods, use the JavaBeans naming convention of set <someProperty> and get <someProperty>
Class
A template that describes the kinds of state and behavior that objects of its type support
Object
At runtime, when the Java Virtual Machine (JVM) encounters the new keyword, it will use the appropriate class to make an object which is an instance of that class. That object will have its own state, and access to all of
the behaviors defined by its class.
State (instance variables)
Each object (instance of a class) will have its own unique set of instance variables as defined in the class. Collectively, the values assigned to an object's instance variables make up the object's state.
Behavior (methods)
When a programmer creates a class, she creates methods for that class. Methods are where the class' logic is stored. Methods are where the real work gets done. They are where algorithms get executed, and data gets manipulated.
What does it mean to access a class? When we say code from one class (class A) has access to another class (class B), it means class A can do one of three things:
- Create an instance of class B.
- Extend class B (in other words, become a subclass of class B)
- Access certain methods and variables within class B, depending on the access control of those methods and variables
-> in effect, access means visibility.
Access to Class Members:
public
- From the same class
- from any class in the same package
- from a subclass in the same package
- from a scubclass outside the same package
- from any non-subclass class outside the package
Access to Class Members:
protected
- from the same class
- from any class in the same package
- from a subclass in the same package
- from a subclass outside the same package (THROUGH INHERITANCE)
Access to Class Members:
default
- from the same class
- from any class in the same package
- from a subclass in the same package
Access to Class Members:
private
- from the same class
byte
- 8 bits
- 1 byte
- mim. Range: -27
- max. Range: 27-1
short
- 16 bits
- 2 byte
- mim. Range: -215
- max. Range: 215-1
int
- 32 bits
- 4 byte
- mim. Range: -231
- max. Range: 231-1
long
- 64 bits
- 8 byte
- mim. Range: -263
- max. Range: 263 - 1
float
- 32 bits
- 4 bytes
double
- 64 bits
- 8 bytes
-
- 1 / 51
-