, 1. Multiple Choice: What does the expression `Map<String,
Integer> map = new HashMap<>();` instantiate?
a) A HashMap with keys of type String and values of type
Integer
b) A HashMap with keys and values of type String
c) A HashMap with keys and values of type Integer
d) A Map with keys of type String and values of type Integer
ANS: a) A HashMap with keys of type String and values of type
Integer
Rationale: The diamond operator `<>` infers the type
parameters from the context, in this case, String for keys and
Integer for values.
2. Fill-in-the-Blank: The _______ method must be implemented
by a class that implements the interface Comparable.
ANS: compareTo
Rationale: The compareTo method is defined in the Comparable
interface and is used for comparing "this" object with the
specified object for order.
,3. True/False: In Java, the '==' operator can be used to compare
two strings for equality.
ANS: False
Rationale: The '==' operator compares references, not values,
and thus, it is not reliable for string content comparison. The
`equals()` method should be used instead.
4. Multiple Response: Which of the following are valid Java
identifiers? (Choose all that apply)
a) _identifier
b) 2ndName
c) $alary
d) void
e) Java2Share
ANSs: a) _identifier, c) $alary, e) Java2Share
Rationale: Java identifiers can start with a letter, currency
character, or connecting character like an underscore. '2ndName'
starts with a digit, and 'void' is a reserved keyword.
, c) public
d) All of the above
ANS: c) public
Rationale: Interfaces can only be declared with public or default
(package-private) access, but not with private or protected access.
6. True/False: The hashCode() method of an object is guaranteed
to be unique for each instance.
ANS: False
Rationale: The hashCode() method is not required to produce a
unique integer for each distinct object. Two different objects can
have the same hash code.
7. Fill-in-the-Blank: A class that is declared with the abstract
keyword is known as an _______.
ANS: abstract class
Rationale: An abstract class cannot be instantiated on its own
and can include abstract methods that must be implemented by
subclasses.
8. Multiple Choice: Which collection class allows you to grow or
shrink its size and provides indexed access to its elements?
a) Array
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 ClemAcademia. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $17.49. You're not tied to anything after your purchase.