Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
101 Cards in this Set
- Front
- Back
Identifiers:What can they begin with? |
Identifiers can begin with a letter, an underscore, or a currency character.
|
|
Identifiers:Can they include digits? |
After the first character, identifiers can also include digits
|
|
Identifiers: How Long? |
Identifiers can be of any length.
|
|
Executable Java Files and main() (OCA Objective 1.3): How to compile execute command line?
|
You can compile and execute Java programs using the command-line programs javac and java, respectively. Bothprograms support a variety of command-line options.
|
|
Executable Java Files and main() (OCA Objective 1.3) : Which main() methods have special powers? |
The only versions of main() methods with special powers are those versions with method signatures equivalent to publicstatic void main(String[] args).
|
|
Executable Java Files and main() (OCA Objective 1.3) : Can Main() be overloaded? |
main() can be overloaded.
|
|
Imports (OCA Objective 1.4) :what is the job of an import statement?
|
An import statement's only job is to save keystrokes.
|
|
Imports (OCA Objective 1.4) :what is the job of an import statement? What is the * used for?
|
You can use an asterisk (*) to search through the contents of a single package.
|
|
Imports (OCA Objective 1.4) : What is the syntax when using the keyword static? |
Although referred to as "static imports," the syntax is import static….
|
|
Imports (OCA Objective 1.4) : What can you import? |
You can import API classes and/or custom classes
|
|
Source File Declaration Rules (OCA Objective 1.2) : How many public classes can a source file have?
|
A source code file can have only one public class. |
|
Source File Declaration Rules (OCA Objective 1.2) : What must the filename be with respect to the public class?
|
If the source file contains a public class, the filename must match the public class name
|
|
Source File Declaration Rules (OCA Objective 1.2) :How many package statements/ import statements can a file have?
|
A file can have only one package statement, but it can have multiple imports.
|
|
Source File Declaration Rules (OCA Objective 1.2) :Where do you put the package statement?
|
The package statement (if any) must be the first (non comment) line in a source file.
|
|
Source File Declaration Rules (OCA Objective 1.2) :Where do you put the import statement?
|
The import statements (if any) must come after the package and before the class declaration.
|
|
Source File Declaration Rules (OCA Objective 1.2) :If there are no package statement where is the import statement placed in the source file?
|
If there is no package statement, import statements must be the first (noncomment) statements in the source file.
|
|
Source File Declaration Rules (OCA Objective 1.2) :What do the package and import statements apply to?
|
package and import statements apply to all classes in the file.
|
|
Source File Declaration Rules (OCA Objective 1.2) : How many nonpublic classes can a file have?
|
A file can have more than one nonpublic class.
|
|
Source File Declaration Rules (OCA Objective 1.2) Are there naming restrictions for files with no public classes?
|
Files with no public classes have no naming restrictions.
|
|
Class Access Modifiers (OCA Objective 6.6) : What are the access modifiers?
|
There are three access modifiers: public, protected, and private.
|
|
Class Access Modifiers (OCA Objective 6.6) : What are the access levels? |
There are four access levels: public, protected, default, and private.
|
|
Class Access Modifiers (OCA Objective 6.6) : What are the types of access a class can have?
|
Classes can have only public or default access.
|
|
Class Access Modifiers (OCA Objective 6.6) : What classes can see another class with default access?
|
A class with default access can be seen only by classes within the same package
|
|
Class Access Modifiers (OCA Objective 6.6) : What classes can see another class with public access?
|
A class with public access can be seen by all classes from all packages.
|
|
Class Access Modifiers (OCA Objective 6.6) : Class visibility effects when code in one class can do these things with another class: |
Class visibility revolves around whether code in one class can
Create an instance of another class Extend (or subclass) another class Access methods and variables of another class |
|
Class Modifiers (Nonaccess) (OCA Objective 7.6) What are the keywords that can modify a class?
|
Classes can also be modified with final, abstract, or strictfp.
|
|
Class Modifiers (Nonaccess) (OCA Objective 7.6) Can a class be both final and abstract?
|
A class cannot be both final and abstract.
|
|
Class Modifiers (Nonaccess) (OCA Objective 7.6) Can a final class be subclassed?
|
A final class cannot be subclassed
|
|
Class Modifiers (Nonaccess) (OCA Objective 7.6) Can an abstract class be instantiated?
|
An abstract class cannot be instantiated.
|
|
Class Modifiers (Nonaccess) (OCA Objective 7.6) If a single method is abstract does that make the whole class abstract?
|
A single abstract method in a class means the whole class must be abstract.
|
|
Class Modifiers (Nonaccess) (OCA Objective 7.6) Can abstract class have both abstract and non abstract methods?
|
An abstract class can have both abstract and nonabstract methods.
|
|
Class Modifiers (Nonaccess) (OCA Objective 7.6) Must a concrete class that extend an abstract class implement all of its abstract methods?
|
The first concrete class to extend an abstract class must implement all of its abstract methods.
|
|
Interface Implementation (OCA Objective 7.6) What are interfaces?
|
Interfaces are contracts for what a class can do, but they say nothing about he way in which the class must do it.
|
|
Interface Implementation (OCA Objective 7.6) How are interfaces implemented?
|
Interfaces can be implemented by any class, from any inheritance tree
|
|
Interface Implementation (OCA Objective 7.6) How are interfaces implemented?What is an interface with respect to an abstract class?
|
An interface is like a 100-percent abstract class and is implicitly abstract whether you type the abstract modifier in thedeclaration or not.
|
|
Interface Implementation (OCA Objective 7.6) Can an interface have concrete methods?
|
An interface can have only abstract methods, no concrete methods allowed.
|
|
Interface Implementation (OCA Objective 7.6) Can an interface have concrete methods? What are the access modifiers for an interface.
|
Interface methods are by default public and abstract—explicit declaration of these modifiers is optional.
|
|
Interface Implementation (OCA Objective 7.6) Can an interface have constants? What access modifiers do they have if so?
|
Interfaces can have constants, which are always implicitly public, static, and final.
|
|
Interface Implementation (OCA Objective 7.6) Are constant declarations optional?
|
Interface constant declarations of public, static, and final are optional in any combination
|
|
Interface Implementation (OCA Objective 7.6) What are the legal nonabstract implementing class properties?
|
1 concrete implementations for the interface's methods. 2 must follow all legal override rules for the methods it implements 3 must not declare any new checked exceptions for an implementation method. 4 must not declare any checked exceptions that are broader than the exceptions declared in the interface method. 5 may declare runtime exceptions on any interface method implementation regardless of the interface declaration. 6 must maintain the exact signature (allowing for covariant returns) and return type of the methods it implements (butdoes not have to declare the exceptions of the interface). |
|
Interface Implementation (OCA Objective 7.6) Can a class implementing and interface itself be abstract?
|
A class implementing an interface can itself be abstract.
|
|
Interface Implementation (OCA Objective 7.6) When must all the interface methods be implemented?
|
An abstract implementing class does not have to implement the interface methods (but the first concrete subclass must)
|
|
Interface Implementation (OCA Objective 7.6) How many classes can a class extend? How many interfaces?
|
A class can extend only one class (no multiple inheritance), but it can implement many interfaces.
|
|
Interface Implementation (OCA Objective 7.6) How many Interfaces can an interface extend?
|
Interfaces can extend one or more other interfaces.
|
|
Interface Implementation (OCA Objective 7.6) Can an interface extend a class or implement a class or interface?
|
Interfaces cannot extend a class or implement a class or interface
|
|
Interface Implementation (OCA Objective 7.6) When taking the exam, verify what is legal before verifying the other code?
|
When taking the exam, verify that interface and class declarations are legal before verifying other code logic.
|
|
Member Access Modifiers (OCA Objective 6.6) :
What variables are known as "members" |
Methods and instance (nonlocal) variables are known as "members."
|
|
Member Access Modifiers (OCA Objective 6.6) :Can members use all 4 access levels?
|
Members can use all four access levels: public, protected, default, and private
|
|
Member Access Modifiers (OCA Objective 6.6) :What forms can member access come in?
|
Member access comes in two forms:
1 Code in one class can access a member of another class. 2 A subclass can inherit a member of its superclass. |
|
Member Access Modifiers (OCA Objective 6.6) :If a class cant be accessed can its members be accessed?
|
If a class cannot be accessed, its members cannot be accessed.
|
|
Member Access Modifiers (OCA Objective 6.6) :Determine what before determining member visibility?
|
Determine class visibility before determining member visibility.
|
|
Member Access Modifiers (OCA Objective 6.6) :Can public members be accessed by all other classes even in other packages?
|
public members can be accessed by all other classes, even in other packages.
|
|
Member Access Modifiers (OCA Objective 6.6) :If a superclass member is public, does the subclass inherit it- regardless of the package?
|
If a superclass member is public, the subclass inherits it—regardless of package.
|
|
Member Access Modifiers (OCA Objective 6.6) :Must members accessed without the dot operator belong to the same class?
|
Members accessed without the dot operator (.) must belong to the same class.
|
|
Member Access Modifiers (OCA Objective 6.6) :What does this. refer to?
|
this. always refers to the currently executing object.
|
|
Member Access Modifiers (OCA Objective 6.6) :this.aMethod() is the same as invoking?
|
this.aMethod() is the same as just invoking aMethod().
|
|
Member Access Modifiers (OCA Objective 6.6) :How are private members accessed?
|
private members can be accessed only by code in the same class.
|
|
Member Access Modifiers (OCA Objective 6.6) :Can private members be inherited?
|
private members are not visible to subclasses, so private members cannot be inherited.
|
|
Member Access Modifiers (OCA Objective 6.6) :Members accessed without the dot operator must ...
|
Members accessed without the dot operator (.) must belong to the same class.
|
|
Member Access Modifiers (OCA Objective 6.6) : Default and protected members differ only when subclasses are involved:
|
1 Default members can be accessed only by classes in the same package. 2 protected members can be accessed by other classes in the same package, plus subclasses regardless of package. 3 protected = package + kids (kids meaning subclasses). 4 For subclasses outside the package, the protected member can be accessed only through inheritance; a subclassoutside the package cannot access a protected member by using a reference to a superclass instance. (In otherwords, inheritance is the only mechanism for a subclass outside the package to access a protected member of itssuperclass.) 5 A protected member inherited by a subclass from another package is not accessible to any other class in thesubclass package, except for the subclass' own subclasses. |
|
Local Variables (OCA Objective 2.1) Can local variable declarations have access modifiers?
|
Local (method, automatic, or stack) variable declarations cannot have access modifiers
|
|
Local Variables (OCA Objective 2.1) What is the only modifier available to local variables?
|
final is the only modifier available to local variables.
|
|
Local Variables (OCA Objective 2.1) Can local variables get default values?
|
Local variables don't get default values, so they must be initialized before use
|
|
Other Modifiers—Members (OCA Objective 6.6): Can final methods be overridden in a subclass?
|
final methods cannot be overridden in a subclass.
|
|
Other Modifiers—Members (OCA Objective 6.6): What are abstract methods declared with? Are they implemented?
|
abstract methods are declared with a signature, a return type, and an optional throws clause, but they are notimplemented.
|
|
Other Modifiers—Members (OCA Objective 6.6): How do abstract methods end?
|
abstract methods end in a semicolon—no curly braces.
|
|
Other Modifiers—Members (OCA Objective 6.6): Three ways to spot a nonabstract method:
|
1. The method is not marked abstract. 2. The method has curly braces. 3. The method MIGHT have code between the curly braces. |
|
Other Modifiers—Members (OCA Objective 6.6): Must the first concrete class to extend and abstract class implement all of the abstract class' methods? |
The first nonabstract (concrete) class to extend an abstract class must implement all of the abstract class' abstractmethods.
|
|
Other Modifiers—Members (OCA Objective 6.6): What kind of access control can synchronized methods have? Can they be marked final?
|
synchronized methods can have any access control and can also be marked final.
|
|
Other Modifiers—Members (OCA Objective 6.6): abstract methods must be implemented by a subclass, so they must be inheritable. For that reason:
|
1 abstract methods cannot be private.
2 abstract methods cannot be final. |
|
Other Modifiers—Members (OCA Objective 6.6): The native modifier applies to what?
|
The native modifier applies only to methods.
|
|
Other Modifiers—Members (OCA Objective 6.6): What does the strictfp modifier apply to?
|
The strictfp modifier applies only to classes and methods.
|
|
Methods with var-args (OCP Only, OCP Objective 1.3) What is the var-arg method?
|
As of Java 5, methods can declare a parameter that accepts from zero to many arguments, a so-called var-arg method.
|
|
Methods with var-args (OCP Only, OCP Objective 1.3) How is the var-arg parameter declared?
|
A var-arg parameter is declared with the syntax type... name; for instance: doStuff(int... x) { }.
|
|
Methods with var-args (OCP Only, OCP Objective 1.3) How many var-arg parameters can a var-arg method have?
|
A var-arg method can have only one var-arg parameter.
|
|
Methods with var-args (OCP Only, OCP Objective 1.3) If a method has a normal parameter and a var-arg.. the var-arg must come...
|
In methods with normal parameters and a var-arg, the var-arg must come last
|
|
Variable Declarations (OCA Objective 2.1):
Instance variables can ... |
1 Have any access control 2 Be marked final or transient |
|
Variable Declarations (OCA Objective 2.1):Instance variables cant be ...
|
Instance variables can't be abstract, synchronized, native, or strictfp.
|
|
Variable Declarations (OCA Objective 2.1):What is shadowing?
|
It is legal to declare a local variable with the same name as an instance variable; this is called "shadowing."
|
|
Variable Declarations (OCA Objective 2.1):final variables have the following properties:
|
❑ final variables cannot be reassigned once assigned a value.
❑ final reference variables cannot refer to a different object once the object has been assigned to the final variable. ❑ final variables must be initialized before the constructor completes. |
|
Variable Declarations (OCA Objective 2.1): Is there such a thing as a final object? Can an object reference marked final mean the object itself cannot be changed?
|
There is no such thing as a final object. An object reference marked final does NOT mean the object itself can't change.
|
|
Variable Declarations (OCA Objective 2.1): What does the transient modifier apply to?
|
The transient modifier applies only to instance variables.
|
|
Variable Declarations (OCA Objective 2.1): What does the volatile modifier apply to?
|
The volatile modifier applies only to instance variables.
|
|
Array Declarations (OCA Objectives 4.1 and 4.2) Can arrays hold primitives or objects? Is the array itself always an object?
|
Arrays can hold primitives or objects, but the array itself is always an object.
|
|
Array Declarations (OCA Objectives 4.1 and 4.2) When you declare and array, where do you place the brackets with respect to the variable name?
|
When you declare an array, the brackets can be to the left or to the right of the variable name.
|
|
Array Declarations (OCA Objectives 4.1 and 4.2) Can you include the size of an array in the declaration?
|
It is never legal to include the size of an array in the declaration.
|
|
Array Declarations (OCA Objectives 4.1 and 4.2) Can you include the size of an array in the declaration? Can an array of objects hold any object that passes the IS-A (or instanceof) test for the declared type of the array?
|
An array of objects can hold any object that passes the IS-A (or instanceof) test for the declared type of the array. Forexample, if Horse extends Animal, then a Horse object can go into an Animal array.
|
|
Static Variables and Methods (OCA Objective 6.2) Are they tied to any particular instance of a class?
|
They are not tied to any particular instance of a class.
|
|
Static Variables and Methods (OCA Objective 6.2) Are class instances needed in order to use the static members of the class?
|
No class instances are needed in order to use static members of the class.
|
|
Static Variables and Methods (OCA Objective 6.2) How many copies of a static variable/class?
|
There is only one copy of a static variable/class and all instances share it.
|
|
Static Variables and Methods (OCA Objective 6.2) Do static methods have direct access to nonstatic members?
|
static methods do not have direct access to nonstatic members.
|
|
enums (OCA Objective 1.2 and OCP Objective 2.5) What does an enum specify?
|
An enum specifies a list of constant values assigned to a type.
|
|
enums (OCA Objective 1.2 and OCP Objective 2.5) Is an enum a String or an int?
|
❑ An enum is NOT a String or an int; an enum constant's type is the enum type. For example, SUMMER and FALL are of theenum type Season.
|
|
enums (OCA Objective 1.2 and OCP Objective 2.5) Where can an enum can be declared?
|
An enum can be declared outside or inside a class, but NOT in a method.
|
|
enums (OCA Objective 1.2 and OCP Objective 2.5) What must an enum declared outside a class not be marked?
|
An enum declared outside a class must NOT be marked static, final, abstract, protected, or private.
|
|
enums (OCA Objective 1.2 and OCP Objective 2.5) What can enums contain?
|
enums can contain constructors, methods, variables, and constant-specific class bodies.
|
|
enums (OCA Objective 1.2 and OCP Objective 2.5) Can enum constants send arguments?
|
enum constants can send arguments to the enum constructor, using the syntax BIG(8), where the int literal 8 is passed tothe enum constructor.
|
|
enums (OCA Objective 1.2 and OCP Objective 2.5) Can enum constructors have arguments? Can they be overloaded?
|
enum constructors can have arguments and can be overloaded.
|
|
enums (OCA Objective 1.2 and OCP Objective 2.5) Can enum constructors be invoked directly in code?
|
enum constructors can NEVER be invoked directly in code.
|
|
enums (OCA Objective 1.2 and OCP Objective 2.5) Is the semicolon at the end of an enum declaration optional?
|
The semicolon at the end of an enum declaration is optional. These are legal:
❑ enum Foo { ONE, TWO, THREE} ❑ enum Foo { ONE, TWO, THREE}; |
|
enums (OCA Objective 1.2 and OCP Objective 2.5) What does MyEnum.values() return?
|
MyEnum.values() returns an array of MyEnum's values called automatically when an enum is initialized.
|