• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/112

Click to flip

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;

112 Cards in this Set

  • Front
  • Back
  • 3rd side (hint)
What types of characters can a legal identifier start with?
Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( _ ). Identifiers cannot start with a number!
Identifiers cannot start with a number!
What types of characters can a legal identifier start with?
Alpha,
Connector (such as Underscore)
Currency ($)
Cannot start with numeric.
After the first character of a identifier, what character types can be used for a legal identifier
After the first character, identifiers can contain any combination of letters, currency characters, connecting characters, or numbers.
What is the max. size of a name of a legal identifier?
In practice, there is no limit to the number of characters an identifier can contain.
What java keywords can be used as a identifier?
None of them. You can't use a Java keyword as an identifier.
Is the identifier named foo the same as the identifier named FOO?
No. Identifiers in Java are case-sensitive;
List the 50 java keywords.
See list from book.
What java keywords have uppercase characters in their names?
None. All java keywords consist of lowercase letters.
What is Sun Convention for naming a class?
first letter should be capitalized, and if several words are linked together to form the name, the first letter of the inner words should be uppercase (a format that's sometimes called "camelCase"). For classes, the names should typically be nouns.
What are Sun Naming Conventions for Interfaces?
For interfaces, the names should typically be adjectives like Methods The first letter should be lowercase, and then normal camelCase
What are Sun Conventions for Method Names?
The first letter should be lowercase, and then normal camelCase rules should be used. In addition, the names should typically be verb-noun pairs. For example:
Method name should be patterned as "verb noun" format
What are Sun standards for naming variable identifiers.
the camelCase format should be used, starting with a lowercase letter. Sun recommends short, meaningful names, which sounds good to us.
What are Sun conventions for naming static variables.
Java constants are created by marking variables static and final. They should be named using uppercase letters with underscore characters as separators:
For a Java Bean, What is the naming rule for a property that is not a boolean?
There must be a getter method with a prefix of "get". There must be a setter method with a prefix of "set". An instance variable with the property name need not exist.
If the property is not a boolean, the getter method's prefix must be get. For example, getSize() is a valid JavaBeans getter name for a property named "size." Keep in mind that you do not need to have a variable named size? (although some IDEs expect it). The name of the property is inferred from the getters and setters, not through any variables in your class. What you return from getSize() is up to you.
For a JavaBean property that is a boolean, what is the proper name of the variable?
the property is a boolean, the getter method's prefix is either get or is. For example, getStopped() or isStopped() are both valid JavaBeans names for a boolean property.
Either get or is can be used as a prefix.
For a java bean, what is a valid name for a setter method?
The setter method's prefix must be 'set'. For example, setSize() is the valid JavaBean name for a property named size.
What access modifier's are permitted for a setter method of a Java Bean?
Setter method signatures must be marked public, with a void return type and an argument that represents the property type.
For a java bean, what return types are permitted for a setter method?
void (only)
What are java bean rules, for a getter method?
Getter method signatures must be marked public, take no arguments, and have a return type that matches the argument type of the setter method for that property.
must be public access modifier
includes no arguments
return type that matches setter method for that property.
What are the objects called that are notified when an event occurs?
The objects that receive the information that an event occurred are called listeners.
Methods that add or remove listeneres from an event must conform to java bean naming standards. True or False?
True. the methods that are used to add or remove listeners from an event must also follow JavaBean naming standards:
What is an example of a valid listener method name that will be used to register a listener with an event source?
Listener method names used to "register" a listener with an event source must use the prefix add, followed by the listener type. For example, addActionListener() is a valid name for a method that an event source will have to allow others to register for Action events.
What is an example of a valid listener method name that will be used to unregister a listener from an event source?
Listener method names used to remove ("unregister") a listener must use the prefix remove, followed by the listener type (using the same rules as the registration add method).
What is an example of a valid argument list of a listener method used to regsiter or unregister a listener?
The type of listener to be added or removed must be passed as the argument to the method.
How many public class statements can be included in a valid source code file?
There can be only one public class per source code file.
Test this.
Where on a line in a source file, can comments appear?
Comments can appear at the beginning or end of any line in the source code file; they are independent of any of the positioning rules discussed here.
If there is a public class entered in a source file, what must the source file be named?
If there is a public class in a file, the name of the file must match the name of the public class. For example, a class declared as public class Dog { } must be in a source code file named Dog.java.
Public class name should be the same as the source code file name.
What is the positioning rule for using a package statement in a source files.
If the class is part of a package, the package statement must be the first line in the source code file, before any import statements that may be present.
what are the positioning rules for import statements relative to the package statement and the class declaration statement.
If there are import statements, they must go between the package statement (if there is one) and the class declaration. If there isn't a package statement, then the import statement(s) must be the first line(s) in the source code file. If there are no package or import statements, the class declaration must be the first line in the source code file.
If you declare multiple classes in a file, how do you organize them to use different packages or different imports.
import and package statements apply to all classes within a source code file. In other words, there's no way to declare multiple classes in a file and have them in different packages, or use different imports.
How many classes can be contained into one source file?
A file can have more than one nonpublic class.
What are the naming options for a file that does not contain any public classes?
Files with no public classes can have a name that does not match any of the classes in the file
What is the minimal code for a class that will compile just fine?
class MyClass { }
Test
Class Modifiers fall into two categories: access modifiers and non-access modifiers. What are the access modifiers and what do they mean?
public - class can be accessed by any other class
protected - any class that is in the same package can be accessed
private -
Class Modifiers fall into two categories: access modifiers and non-access modifiers. What are the non-access modifiers and what do they mean?
strictfp, abstract, final
There are 3 access modifiers and 4 access levels. What is the fourth access level called that is not an explicit access modifier?
The fourth access control level (called default or package access) is what you get when you don't use any of the three access modifiers.
All four access controls work for most method and variables declarations. But only two access controls work for class declarations. What are there names?
Although all four access controls (which means all three modifiers) work for most method and variable declarations, a class can be declared with only public or default access; the other two access control levels don't make sense for a class, as you'll see.
Test
Java is a package-centric language. What is the purpose of a package?
Packages enable the developer to organize his classes and also clarify what version of a class to use if there is more than one class with the same class name.
What does class Access mean? What does it mean when one Class, Class A can access Class B?
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. If class A can't see class B, the access level of the methods and variables within class B won't matter; class A won't have any way to access those methods and variables.
Test
What does class access mean when the class access modifier is not stated?
Default Access A class with default access has no modifier preceding it in the declaration! It's the access control you get when you don't type a modifier in the class declaration. Think of default access as package-level access, because a class with default access can be seen only by classes within the same package. For example, if class A and class B are in different packages, and class A has default access, class B won't be able to create an instance of class A, or even declare a variable or return type of class A. In fact, class B has to pretend that class A doesn't even exist, or the compiler will complain.
What does the public access modifier mean?
Public Access A class declaration with the public keyword gives all classes from all packages access to the public class. In other words, all classes in the Java Universe (JU) have access to a public class.
When do you need to use an import statement?
if a public class you're trying to use is in a different package from the class you're writing, you'll still need to import the public class.
When would you consider using the non-access modifier 'final'?
You should make a final class only if you need an absolute guarantee that none of the methods in that class will ever be overridden. If you're deeply dependent on the implementations of certain methods, then using final gives you the security that nobody can change the implementation out from under you.
What is the purpose of the non-access modifier 'abstract'?
Abstract Classes An abstract class can never be instantiated. Its sole purpose, mission in life is to be extended (subclassed).
Note, however, that you can compile and execute an abstract class, as long as you don't try to make an instance of it.
When a method is marked as abstract what changes in the body of the method?
An abstract method does not have a body. It ends with a semi-colon.
What non-access modifiers must be used for a class to implement an abstract method?
If a method is in a class—as opposed to an interface—then both the method and the class must be marked abstract.
What non-access modifier is required of a class that has a abstract method?
if even a single method is abstract, the whole class must be declared abstract.
When can a class be marked with the non-access modifiers 'final' and 'abstract' ?
you can't mark a class or a method as both abstract and final. They have nearly opposite meanings. An abstract class must be subclassed, whereas a final class must not be subclassed.
The code will not compile.
What is the purpose of an interface?
When you create an interface, you're defining a contract for what a class can do, without saying anything about how the class will do it.
What is the difference between an abstract class and an interface?
Abstract class may have at least one abstract method. An interface has nothing but abstract methods. An interface will not have method implementations .
What access-modifiers are allowed for an interface?
All interface methods are implicitly declared as public and abstract.
What variable access modifiers can be declared in an interface?
All variables defined in an interface must be public, static, and final—in other words, interfaces can declare only constants, not instance variables.
What non-access modifiers can be used for interface methods?
Because interface methods are abstract, they cannot be marked final, strictfp, or native.
What are the rules for extending an interface?
An interface can extend another interface. An interface can extend nothing other than an interface. Interfaces don't implement anything.
What are two ways to use non-access modifiers to declare an interface
public abstract interface Rollable{ }
public interface Rollable{ }
Both of these declarations are valid and interchangeable.
What two access modifiers can be used with an interface?
public access and default access (package)
What access-modifiers can be used by an Interface method?
All interface methods are public and abstract regardless of what is in the interface definition
You must remember that all interface methods are public and abstract regardless of what you see in the interface definition. Look for interface methods declared with any combination of public, abstract, or no modifiers. For example, the following five method declarations, if declared within their own interfaces, are legal and identical!
What access modifiers are considered valid declarations for interface constants?
interface constants are defined in an interface, they don't have to be declared as public, static, or final. They must be public, static, and final, but you don't have to actually declare them that way. public, static, final is implied.
When can the value of a constant declared in an interface be changed?
You can't change the value of a constant! Once the value has been assigned, the value can never be modified.
This is due to the use of the 'final' non-access modifier.
What are considered class members?
instance variables and methods. local variables are not considered class members.
What access-levels can be used for a class?
Whereas a class can use just two of the four access control levels (default or public), members can use all four: public protected default private
What access-levels can be used for a method?
Whereas a class can use just two of the four access control levels (default or public), members can use all four: public protected default private
What is the difference between the default access control and protected access control?
Default protection is what you get when you don't type an access modifier in the member declaration. The default and protected access control types have almost identical behavior, except for one difference:
What does it mean for code in one class to have access to a member of another class?
For now, ignore any differences between methods and variables. If class A has access to a member of class B, it means that class B's member is visible to class A.
What are the three ways to access a method?
1. Put the method in the same class.
2. Invoke the method using a reference to the class the method is in.
3. Invoke an inherited method.
What access modifiers can be used for a subclass to be able to inherit a superclass member even if both classes are not in the same package?
For a subclass, if a member of its superclass is declared public, the subclass inherits that member regardless of whether both classes are in the same package:
What does a reference to 'this' mean?
The reference this always refers to the currently executing object—in other words, the object running the code where you see the this reference. Because this reference is implicit, you don't need to preface your member access code with it, but it won't hurt.
What does the 'private' access modifier mean?
Members marked private can't be accessed by code in any class other than the class in which the private member was declared.
What happens when a subclass tries to access a 'private' member in it's superclass?
When a member is declared private, a subclass can't inherit it. For the exam, you need to recognize that a subclass can't see, use, or even think about the private members of its superclass.
Can a subclass override a superclass member that is marked private?
No. You can, however, declare a matching method in the subclass. But regardless of how it looks, it is not an overriding method.
What are recommended access modifiers for instance variables?
protected or private. Getters and setters should be used to access the value of the variables. These accessor methods can then test the value to insure it is valid.
What is the difference between default access and protected access?
The protected and default access control levels are almost identical, but with one critical difference. 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.
Default and protected behavior differ only when we talk about subclasses. If the protected keyword is used to define a member, any subclass of the class declaring the member can access it through
What access modifiers can apply to local variables?
Access modifiers can not be applied to local variables. The only modifier that can be applied to a local variable is 'final'.
When would you consider using 'final' on a method that is in a superclass?
final keyword prevents a method from being overridden in a subclass, and is often used to enforce the API functionality of a method.
What modifiers can be applied to method arguments?
Method arguments are essentially the same as local variables. This means they can also have the modifier final. In other words, a final argument must keep the same value that the parameter had when it was passed into the method.
Can you have an abstract class that does not contain an abstract method?
An abstract class can be valid if it does not have any abstract methods.
What are three clues to determine if a class is abstract or not?
The method is not marked abstract. The method declaration includes curly braces, as opposed to ending in a semicolon. In other words, the method has a method body.
The method provides actual implementation code.
What should you look for to find invalid concrete classes?
Look for concrete classes that don't provide method implementations for abstract methods of the superclass.
What is an overloaded method?
it is simply an overloaded method (a method using the same identifier, but different arguments).
What does the modifier synchronized mean?
The synchronized keyword indicates that a method can be accessed by only one thread at a time.
What access-modifiers can the synchronized modfier be combined with?
You should also know that the synchronized modifier can be matched with any of the four access control levels (which means it can be paired with any of the three access modifier keywords).
What class members are able to use the synchronized modifier?
synchronized modifier can be applied only to methods—not variables, not classes, just methods.
What is the modifer 'native' used for? What class members are able to use the 'native' modifier?
The native modifier indicates that a method is implemented in platform-dependent code, often in C. other than Know that native is a modifier (thus a reserved keyword) and that native can be applied only to methods—not classes, not variables, just methods. Note that a native method's body must be a semicolon (;) (like abstract methods), indicating that the implementation is omitted.
You don't need to know how to use native methods for the exam. Native methods do not have a body.
What is the purpose of the modifier strictfp?
strictfp forces floating points (and any floating-point operations) to adhere to the IEEE 754 standard.
What class members can strictfp be used with?
Only the class and method members?
What are Variable Argument Lists (var-args) ?
Introduced in Java 5.0. Used to define methods that have a variable number of arguments. AKA var-args
What are declaration rules for using var-args?
1. Can only use one var-arg per method.
2. To declare a method using a var-arg parameter, you follow the type with an ellipsis (…), a space, and then the name of the array that will hold the parameters received.
3. The var-arg must be the last parameter in the method's signature, and you can have only one var-arg in a method.
Parameter type can be primitive or an object.
Example:
doStuff(Animal... animal)
What are the differences between a constructor and a method?
The first thing to notice is that constructors look an awful lot like methods. A key difference is that a constructor can't ever, ever, ever, have a return type…ever! Constructor declarations can however have all of the normal access modifiers, and they can take arguments (including var-args), just like methods. The other BIG RULE, to understand about constructors is that they must have the same name as the class in which they are declared. Constructors can't be marked static (they are after all associated with object instantiation), they can't be marked final or abstract
What are the two types of variables in Java:
Once a primitive has been declared, its primitive type can never change, although in most cases its value can change.
Primitives and Object References.
What are the eight types of primitive variables?
A primitive can be one of eight types: char, boolean, byte, short, int, long, double, or float.
What is a reference variable?
A reference variable is used to refer to (or access) an object. A reference variable is declared to be of a specific type and that type can never be changed.
A reference variable can be used to refer to any object of the declared type, or of a subtype of the declared type (a compatible type).
For the types of integer and floating point primitives List the types in order by size of their ranges.
Integers: byte, short, int, long.
floating point: float, double.
What is the range of floating point types such as float and double?
float is 32 bits long
double is 64 bits long.
There are 6 number primitives. Name them and their size?
byte = 1 byte
short = 2 bytes
int = 4 bytes
long = 8 bytes
a boolean does not have a range.
char 1 byte
What is a local variable?
Local variables are variables declared within a method.
That means the variable is not just initialized within the method, but also declared within the method.
Just as the local variable starts its life inside the method, it's also destroyed when the method has completed.
Local variables are always on the stack, not the heap.
What modifiers can a local variable be associated with?
variable declarations can't use most of the modifiers that can be applied to instance variables, such as public (or the other access modifiers), transient, volatile, abstract, or static, but as we saw earlier, local variables can be marked final.
What are rules relating to initializaing local variables?
The key is to remember that a local variable must be initialized before you try to use it. The compiler will reject any code that tries to use a local variable that hasn't been assigned a value, because—unlike instance variables—local variables don't get default values.
What is the scoope of a local variable?
A local variable can't be referenced in any code outside the method in which it's declared.
Describe what an array is including the types an array can hold? Can an array hold primitives and object referencese?
In Java, arrays are objects that store multiple variables of the same type, or variables that are all subclasses of the same type. Arrays can hold either primitives or object references,
How do you declare an array of primitives or an array of objects?
int [ ] myNumbers;
Customer[ ] customers;
alternate syntax is also valid:
int myNumbers[ ] ;
Customer customers [ ];
Why would you want to use one of the Collection types in java.util instead of using an array?
Collections can dynamically adjust their size where an array can not.
How would you declare a 2 dimensional array?
int [ ] [ ] myNumbers;
How do you declare an array using a fixed size?
You don't. You never specify the size in declaration. Size matters when the array is constructed.
What does final mean when a primitive variable is declared as final?
Once the variable is initialized the value will not be able to be changed for the life of the variable.
What does final mean when a object reference variable is declared as final?
Once the variable is initialized the object reference can not be used to refer to another object. You can modify the state of the variable but not the object that is being referenced.
There are no final objects, just final object references.
What does it mean to use the transient modifier on a class member?
Transient modifer only applies to instance variables. You mark an instance variable as transient, you're telling the JVM to skip (ignore) this variable when you attempt to serialize the object containing it.
What does it mean to use the volatile modifier on a class member?
The volatile modifier tells the JVM that a thread accessing the variable must always reconcile its own private copy of the variable with the master copy in memory. It only applies to instance variables.
What are static variables?
The static modifier is used to create variables and methods that will exist independently of any instances created for the class. All static members exist before you ever make a new instance of a class. All instances of a given class share the same value for any given static variable.
What can you declare as static in a class?
methods, instance variables, initialization block, nested classes.
What is the purpose of an enum?
In 5.0, Java lets you restrict a variable to having one of only a few pre-defined values—in other words, one value from an enumerated list. (The items in the enumerated list are called, surprisingly, enums.)
Demonstrate how to define an enum outside of a class?
Declaring an enum outside a class:

The however they must not be declared within a method! Declaring an enum outside a class: The preceding code can be part of a single file.
What are enums?
Enums are not strings or ints. They are instances of the type.