keywords:
Bookmark and Share



Front Back
Legal Identifiers
unicode... -letters -numbers -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) -setProperty GETTERS -getProperty -isProperty (only boolean can use either) camelCased
what is the format of a JavaBean Listener?
add + ListenerType(ListenerType x) i.e. public void addMyListener (MyListener m); remove + ListenerType(ListenerType x) i.e. public void removeMyListener(MyListener m);
Name the 2 groupings of modifiers.
-Access -Non-Access
Name the class access modifiers.
-public -default -NOT protected or private
Package Naming Strategy
lowercase -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?
-public -abstract 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. i.e. 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?
No.
What are the implicit modifiers of all interface variables?
-static -public -final
Can interface methods be static?
No.
When declaring an interface method can it be modified with ""strictfp""? final? native?
No no and no.
Can interfaces implement interfaces?
No.
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?
Yes. -public -default
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(){}
Yes.
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 i.e. 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? Foo(){} 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: static final abstract synchronized strictfp native volitile transient
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; this? int i=0 j; this? for (int i=0 j;;) {}
Yes yes and no.
Name all modifiers.
Access: private -> (default) -> protected -> public Non-Access: static final abstract synchronized native strictfp transient volatile
How can non-local variables be modified?
(4 access modifiers) static final transient volatile
What modifiers can be prepended to local variables?
(no access modifiers) final
How can methods be modified?
pubilc protected (default) private static final abstract synchronized native strictfp
How can classes be modified?
public (default) final abstract strictfp
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.
Legal? 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. i.e. public enum Rank {TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE TEN JACK QUEEN KING ACE}
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(); a1.foo(); } } class B extends A { public int foo(){System.out.println(""B""); return 1;} } What gets printed?
A.
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 { A B C D F INCOMPLETE };
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 { A B C D F INCOMPLETE }; public enum Grade { A B C D F INCOMPLETE; };
Both.
x of y cards Next >|