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;
41 Cards in this Set
- Front
- Back
Java Identifiers
|
All the Java components-classes, variables, and methods
need names. In Java these names are called identifiers. |
|
Inheritance
|
Concept of inheritance allows code defined in one class to be reused in other classes.
|
|
Interfaces
|
Interfaces are like a 100-percent abstract superclass that defines the methods a subclass must support, but
not how they must be supported. |
|
Cohesion
|
High cohesion means a class should only do what it is supposed to do, and does it fully. Do not overload it with functions that it is not supposed to do.
|
|
Legal Identifiers
|
1. Must start with a letter, ( $ ), or ( _ )
2. Cannot start with a number 3. Can contain numbers after the first character. 4. No limit to the number of characters. 5. Java built-in keywords can not be used as identifiers. |
|
Constants
|
Java constants are created by marking variables static and
final. |
|
JavaBeans
|
JavaBeans are Java classes that have properties
|
|
JavaBean Property Naming Rules
|
Non-boolean property, the getter method's prefix must be "get".
Boolean property, the getter method's prefix is either "get" or "is". Setter method's prefix must be "set". getSize(), setSize() & isValid |
|
Class declaration rules
|
One public class per source code file.
Name of the file must match the name of the public class. Comments can appear anywhere in the source code file. package statement, import statement(s), class declaration import and package statements apply to all classes within a source code file. A file can have more than one nonpublic class. Files with no public classes can have a name that does not match any of the classes in the file. Class can be declared with only public or default access |
|
Modifiers
|
Access modifiers: public, protected, private.
Non-access modifiers: abstract, final, strictfp. |
|
Class - Default Access
|
default access is a package-level access, because a class with default access can be seen only by classes within the same package.
|
|
Class Other - Nonaccess Class Modifiers
|
final, abstract, or strictfp
final and abstract cannot be used together |
|
strictfp
|
any method code in the class will conform to the IEEE 754 standard rules for floating points.
|
|
final class
|
final class cannot be sub-classed (extend)
|
|
abstract class
|
abstract class can never be instantiated, it is only to be sub-classed
abstract class Car { private double price; private String model; private String year; public abstract void goFast(); public abstract void goUpHill(); public abstract void impressNeighbors(); } Methods marked abstract end in a semicolon rather than curly braces. An abstract class can have both abstract and non-abstract methods. |
|
interface class declaration
public abstract interface Rollable { } Is this legal interface declaration? |
Yes, but typing in the abstract modifier is considered redundant. So both of these declarations are identical:
public abstract interface Rollable { } public interface Rollable { } |
|
interface methods
|
All interface methods are implicitly public and abstract
void methodName(); will be public abstract void methodName(); |
|
interface variables
|
All variables defined in an interface must be public, static, and final, in other words, interfaces can declare only constants, not instance variables.
So int BAR = 42; will be public static final int BAR = 42; |
|
Interface methods can be static?
|
No
|
|
Interface methods can be marked final, strictfp, or native?
|
No
|
|
Interface can be extended?
|
Yes
|
|
Interface can be extended by another class?
|
No, Interface can be extended by another interface only.
|
|
Can interface implement another interface or class?
|
No, an interface cannot implement another interface or class.
|
|
Class member access modifiers?
|
public, protected, default, private
|
|
Difference between default and protected class members?
|
A default member may be accessed only if the class accessing the member belongs to the same package, whereas a protected member can be accessed (through inheritance) by a subclass even if the subclass is in a different package.
|
|
Can access modifiers be applied to local variables?
|
No
|
|
Which access modifier can be applied to local variables?
|
final
|
|
What are non-access method modifiers?
|
final, abstract, static, transient, synchronized, native, strictfp
|
|
Can method arguments be declared as final?
|
Yes
|
|
abstract modifier can be combined with static for methods?
|
No
|
|
What are synchronized methods?
|
Synchronized method can be accessed by only one thread at a time.
|
|
Native modifier can be applied to class, method and variables?
|
No, native modifier can be applied only to methods.
|
|
Difference between arguments and parameters
|
arguments: Things between parentheses while invoking method
parameters: Things in the method's signature |
|
What is ellipsis?
|
(...)
|
|
How to write method with var-args
|
void doStuff(int... x) { }
|
|
Can a constructor have a return type?
|
No
|
|
Which modifiers are restricted for constructor?
|
static, final, abstract
|
|
Types of variables
|
Primitive and reference variables
|
|
List of primitives
|
char, boolean, byte, short, int, long, double, float
|
|
What are instance variables?
|
Instance variables are defined inside the class but outside any method and are only initialized when the class instantiates.
|
|
|
nothing
|