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
51
0.0 (0)
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>
|
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>