What is an interface? How is this different from a class? - ANS-an interface is a
description of what software does, a class is a description of how the software does
what it does
How many interfaces can an interface extend? - ANS-one or more, not zero
What can interfaces define? - ANS-instance methods, and public static final variables
(constants)
What can't interfaces define? - ANS-constructors, static methods, instance variables
Interfaces do allow static methods with their implementations, but providing code in an
interface goes against good practice. - ANS-.
What is the core interface for a data type? - ANS-the kernel interface
What does the kernel interface define for a data type? - ANS-the mathematical model
for the data type, contracts for the constructors, contracts for the kernel methods,
contracts for methods inherited from java that do not have their own contract
specifications
What does the enhanced interface define for a data type? - ANS-all methods not
defined in the kernel interface for the data type
Kernel methods should be... - ANS-a minimal set of functions that is functionally
complete (powerful enough to give the type any allowable value, and determine the
value of a variable of that type, and implement equals and toString)
What is type-checking? - ANS-interfaces use type-checking at compile time to make
sure variables are used where they make sense to be used
Once a java program complies, only object-types are kept at run time, declared types
disappear because they have already been type checked - ANS-.
The declared type of a variable may be an interface type, but the object type can
NEVER be an interface type - ANS-.
, Packages - ANS-each osu component family is bundled into a package, or a group of
interfaces and classes that the designer thinks should belong together, you can only
declare at most one package per program
What three methods does object define? - ANS-equals, hashCode, and toString (every
class in java implicitly extends object, all three of these methods should be overwritten
in any abstract class to match the abstract values of the variables for that class)
What does the default implementation of equals do? - ANS-compare the reference
values of the two variables (BAD)
What does the default implementation of hashCode do? - ANS-converts the reference
value into a integer hash value (BAD because two things pointing to the same reference
value would return the same hash number)
What does the default implementation of toString do? - ANS-returns the name of the
class for the object, followed by an @, followed by a hexidecimal representation of of
the hashCode of the object
How should you override the methods defined in the object class within a given abstract
class? - ANS-layer them on top of the kernel methods from the kernel class
Best way to implement equals in an abstract class? - ANS-Step 1: If the reference
values of obj and this are equal, the two objects are equal (repeated arguments are
allowed with equals)
Step 2: If obj is null, then the two object do not equal each other. (this is guaranteed to
be not null since we entered the function call)
Step 3: If the types of obj and this are not the same raw type, then they are not equal, to
check if they are the same raw type, see if their dynamic types both extend the same
abstract class or implement the same interface. (we know the dynamic type of this
implements XYZ because we are in the class for it, but we just need to check if OBJ
also implements XYZ)
NOTE: the checking of the same raw type can be done with generics, but the generic
type of the variables cannot be compared because of type erasure. this means that an
empty Queue<String> and an empty Queue<Integer> would be said to be equal by the
equals method. If they weren't empty however, equals would return the correct boolean
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller denicetho. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $9.53. You're not tied to anything after your purchase.