Study your flashcards anywhere!

Download the official Cram app for free >

  • 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

How to study your flashcards.

Right/Left arrow keys: Navigate between flashcards.right arrow keyleft arrow key

Up/Down arrow keys: Flip the card between the front and back.down keyup key

H key: Show hint (3rd side).h key

A key: Read text to speech.a key


Play button


Play button




Click to flip

59 Cards in this Set

  • Front
  • Back
Legal Identifiers
-connecting chars (i.e. "_")
-currency chars (NOT ".")

can't start with a number
What is the format of JavaBean property getters & setters?
all public.

SETTER (return void)

(only boolean can use either)

what is the format of a JavaBean Listener?
add + ListenerType(ListenerType x)

public void addMyListener (MyListener m);

remove + ListenerType(ListenerType x)

public void removeMyListener(MyListener m);
Name the 2 groupings of modifiers.
Name the class access modifiers.
-NOT protected or private
Package Naming Strategy

-reverse domain name
-division (if applic.)
-project name
i.e. com.hype7.blame
What is the modifier "strictfp" do? What java things can it modify?
Guarantees that floating point calculations will be done in deterministic, IEEE 754 way (vs. system dependent way)

Classes and methods can use this modifier.
What is the difference between the format of an abstract method and non-abstact method declaration?
Abstract method has no body (brackets filled with N number of statement). Instead, it has a semicolon. This format is called a prototype.
If you declare a class method abstract, what else do you have to declare abstract?
If it's a class method, the class also must be modified with "abstract".

If we were declaring an interface method (vs. a class method) since interfaces are implicitly abstract the interface would not need be modified with the "abstract" keyword, though that would be legal and allowed.
What are the implied modifiers of ALL interface methods?
There is no need to explcity modify interface methods declarations with the public modifier (its optional) and you can't modify it with the abstract keyword even though the method actually is abstract.

When a class implements an interface, though, it MUST explicitly declare the method public.
void bounce();
compliler sees prototype as as this:
public abstract void bounce();
When implementing an interface method in a class, must you always use the prototype exactly as it's delcared in the interface?
No. An interface method may leave off the "public" modifier in it's declaration (interface methods are ALWAYS public and abstract). But in the class implementation it must explicitly be implemented as public.
Can an interface have non-abstract methods?
What are the implicit modifiers of all interface variables?
Can interface methods be static?
When declaring an interface method, can it be modified with "strictfp"? final? native?
No, no, and no.
Can interfaces implement interfaces?
How many interfaces is an interface allowed to extend?
As many as it wants.
Are the available access modifiers the same for classes and interfaces?
B extends A
A -> private void foo(){}
B -> public int foo(){}

Will this compile?
Yes. B's foo() isn't an attempt to override because A's foo()is marked private. B's foo() is not obligated to worry about the rules of overriding with respect to A's foo().
When does method binding happen at compile time?
When a method is declared PRIVATE or STATIC.

Compile time binding means these methods will not be affected by the dynamic method allocation that happens at runtime
Can a subclass in a different package than it's superclass always see the protected variable members in that superclass?
No. It can see the protected ivars it has inherrited into its own instance, but it cannot hold a reference to another instance of a superclass object and see those protected it's versions of the protected variables.
Why can't you mark method parameters as 'final' For example:
void foo(final int i){} ?
You can!
What are the possible combinations of these non-access modifiers on methods: abstract final static?
abstract (by itself)
final (by itself)
static (by itself)
final static

NOTE: static methods don't override each other but they can hide one another in sub-classes. Marking a method "final static" prevents the class from being hidden in a subclass.
Is the following legal?
private synchronized void foo(){}
What elements can be modified by 'native'?
Only methods. Classes, interfaces, and variables cannot be native.
What does a native method body declaration ALWAYS look like?
A single semi-colon. ';' It's just like an abstract method declaration

public native void printText ();
Is this legal?
strictfp int i;
No. strictfp modifies classes and methods only.

(Also allowed to modify interfaces but not interface methods -- per complier on my desktop... hmmmm...)
What are the rules of using a variable-argument parameter in a method declaration?
Syntax: type + elipse + space + name of array(no brackets "[]")
i.e. (String... args)

Can only have 1 var-arg in method declaration

Can have many other regular parameters

Var-arg parameter must be last in parameter list.
In class Foo is it legal to have both of these?
void Foo(){}
Yes. Because one has a return type and thus it is not a constructor. It's just a poorly named method.
What are acceptatble modifiers for a constructor?
All the access modifiers and NONE of the non-access modifiers.

This means a constructor CANNOT be marked:
What's the bit depth of a boolean?
It's machine dependent. Java doesn't enforce a representative bit depth for booleans. Java only promises how booleans will act when true or false - not how these values might look or act at the bit level.
Is this legal?
int i1, i2, i3;
int i=0,
for (int i=0, j;;) {}
Yes, yes, and no.
Name all modifiers.
private -> (default) -> protected -> public

How can non-local variables be modified?
(4 access modifiers)

What modifiers can be prepended to local variables?
(no access modifiers)

How can methods be modified?
pubilc, protected, (default), private

How can classes be modified?

Why don't arrays constructed inside of methods get initialized with default values.
They do get initialized. An array is an object and EVERYTIME one is created, it gets filled with default values. The reference variable used to point to the array inside the method is a different story. It will not automatically be filled with null. It must explicitly set to null or set to point to an array object.
int[5] i;
No. You never specify the size when you DECLARE an array. Only when you INSTANTIATE an array object does size get declared!
Where can an enum be declared?
Outside a class or inside a class (much like any other member) but NOT inside a method.
What can an enum contain?
variables, constructors, methods, constant class bodies.

Will the following compile?

int x = 1;
enum Size {SMALL, BIG}
x = 2;
Yes (assuming the enum declaration is at the member variable level vs. the method local variable level)

The semicolon at the end of the enum declaration is optional.
Will the following compile?
enum Size {
SMALL(1), BIG(10);
Size s = new Size(1);
No. You cannot call an enum constructor directly.

A valid usage:
Size s = Size.SMALL;
class A {
private void foo(){System.out.println("A");}
public static void main (String[] args) {
A a1 = new B();;

class B extends A {
public int foo(){System.out.println("B"); return 1;}

What gets printed?
Express the following as an enum:

public class OldGrade {

public static final int A = 1;
public static final int B = 2;
public static final int C = 3;
public static final int D = 4;
public static final int F = 5;
public static final int INCOMPLETE = 6;
public enum Grade {
Where should you generally use enums?
Anywhere you're defining a set of constant values.
When declaring an interface method, will the compiler allow you to modify it with the "abstract" and "public" keywords? Are you allowed to leave both modifiers off?
An interface method is, by definition, abstract and public. As such a programmer need not modify any interface method explicityly with these keywords.

BUT you can add either "abstract" and/or "public" and the compiler will not complain.
Interface variables are static, public, and final. Can you leave off these modifiers when declaring an interface variable? Can you include them?
Yes and yes.
When is a floating point calculation IEEE 754 compliant?
Every compile-time constant expression is FP-strict. If an expression is not a compile-time constant expression, then consider all the class declarations, interface declarations, and method declarations that contain the expression. If any such declaration bears the strictfp modifier, then the expression is FP-strict.
Which is correct?

public enum Grade {

public enum Grade {
class A {
final private void foo() {}

class B extends A {
void foo() {}

Compiles? Runs?
It does compile. Because foo() in class A is private, it is not being overridden in class B. They are 2 unrelated methods that just so happen to have the same name. Therefore modifiers on A's foo() (final, private) don't affect the signature of B's foo().

It will not run because a main() method is needed.
What is the difference between method arguments and local variables?
They are essentially the same. The both can only be modified with the non-access modifier, 'final'.
Is there a case where you might modify a class both abstract and static?
Classes can't be modified static. Classes can only be modified as abstract, final, or strictfp!
Is there a case where you might modify a method as both static and abstract? Abstract and final? Static and final?
No. No. Yes.
What access modifiers can you use with a constructor?
All: public, protected, default, private
What non-access modifiers can you use with a constructor?
final, static, abstract, synchronized, strictfp, and native all cannot be used with a constructor.
Tell me about javabeans...
Java bean classes can not define public instance variables.
Properties of a Java bean are accessed through its corresponding 'get' and 'set' public accessor methods. For e.g., if a Java Bean defines public getName() and setName() methods, it defines a property 'name'. If a Java bean defines just the 'getter' method (getName), but no corresponding 'setter' method (setName), it defines a read-only property 'name'.
It is important to note that the name of the property of a Java bean is not related to the name of the instance variable that is actually used to store the property value.
All beans must support either Serialization or Externalization.
Java bean must define a zero argument constructor. We can do this by explicitly defining a zero argument constructor, or by not defining any constructor. If a class does not defines any constructor, Java defines a no-argument constructor for it.
What are the 6 kinds of constants? Which 2 of the 6 can be used as switch case labels?

42, "abc"

You may use byte, short, char and int literals as switch case labels. However longs and Strings are not supported.
Compile Time Constants
or just plain compile constants, Officially known as “compile-time constant expressions” these are static finals whose value is known at compile time. e.g.

// constants known at compile time
static final int ARMS = 2;
static final int LIMBS = ARMS * 2;

These can be used as switch case labels, subject, of course, to the usual byte, short, char and int-only restriction.
Load-Time Class Constants
or just plain load constants, static finals whose value is not known until class load time . e.g.

static final int SERIALNUMBER = ++generator;

These cannot used in switch case labels. All the "variables" in an interface are implicitly static finals. They may be either comile time constants or load time constants.
Instance Constants
instance finals whose value is not known until object instantiation time . e.g.

final int DAY_CREATED = (int)(System.currentTimeMillis() / ( 24 * 60 * 60 * 1000L ));

These too cannot used as switch case labels. It is sometimes possible for an instance constant to be evaluated at compile time. In that case it is treated like a literal, much like a static compile-time constant. You can use a compile-time local int constant as a case label.
Local Constants
stack finals whose value is not known until the method executes. e.g.

final int bottomLine = getTax();

These too cannot used as switch case labels.

final int LEGS = 2;

As in the example above, it is sometimes possible for a local constant to be evaluated at compile time. In that case it is treated like a literal, much like a static compile-time constant. You can use a compile-time local int constant as a case label.
enum Constants
The names of the possibilities for an enum. These are under-the-hood static finals evaluated at load time, but through the magic of Java, you can use them as if they were known at compile time, e.g. as case labels.
Can you have more than 1 main() method in an application?
Yes. Only the main() method of the class specified to the java interpreter (i.e. >java Dog) will be called to start the application