Java Test 2 (Ch 11, 13, 19, 20, 21)

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Because generic types are erased at runtime, there are certain restrictions on how generic types can be used. List one of those restrictions. A) Exception classes cannot be generic. B) No restrictions C) Type erasure D) The compiler uses the generic-type information to compile the code, but erases it afterward. E) Once the compiler confirms that a generic type is used safely, it converts the generic type to a raw type.

A

Describe difference between java.util.HashSet and java.util.LinkedHashSet A) The HashSet class has no particular order for the elements in the set. The LinkedHashSet class supports an ordering of the elements in the set. B) The HashSet class only allows elements that are Comparable. The LinkedHashSet class allows for duplicates of the elements in the set. C) The LinkedHashSet class has no particular order for the elements in the set. The HashSet class supports an ordering of the elements in the set. D) The LinkedHashSet class only allows elements that are Comparable. The HashSet class allows for duplicates of the elements in the set.

A

Describe the difference between a java.util.Queue and a java.util.PriorityQueue. A) In a Queue, elements are stacked on top of each other and are removed from the top. In a Priority Queue, the element in the middle of the stack is removed first. B) In a Queue, elements are appended to the end of the queue and are removed from the beginning of the queue. In a Priority Queue, the element with the highest priority is removed first. C) In a Priority Queue, elements are stacked on top of each other and are removed from the top. In a Queue, the element in the middle of the stack is removed first. D) In a Priority Queue, elements are appended to the end of the queue and are removed from the beginning of the queue. In a Queue, the element with the highest priority is removed first.

B

Which describes bounded generics. A) A generic type can be part of a generic method. B) A generic type can be specified as a subtype of another type. C) A generic type can be part of a constructor. D) A generic type can be specified as a supertype of another type.

B

Describe the difference between a java.util.ArrayList and java.util.LinkedList A) The LinkedList class is fixed in size. The ArrayList class can grow and shrink dynamically in size. B) The ArrayList class is fixed in size. The LinkedList class can grow and shrink dynamically in size. C) The ArrayList class stores elements in an array. The LinkedList class stores elements in a linked list. D) The LinkedList class stores elements in an array. The ArrayList class stores elements in a linked list.

C

Describe the difference between a java.util.HashMap and java.util.TreeMap A) The TreeMap has a linked-list implementation that supports an ordering of the entries in the map. The HashMap class is efficient for traversing the keys in a sorted order. B) The HashMap has a linked-list implementation that supports an ordering of the entries in the map. The TreeMap class is efficient for traversing the keys in a sorted order. C) The HashMap class is efficient for locating a value, inserting an entry, and deleting an entry. The TreeMap class is efficient for traversing the keys in a sorted order. D) The TreeMap class is efficient for locating a value, inserting an entry, and deleting an entry. The HashMap class is efficient for traversing the keys in a sorted order.

C

What annotation should be used to mark overriding methods in a subclass? A) @Getter B) @Setter C) @Override D) @Method

C

What is polymorphism? A) Polymorphism means that a method can be implemented in several classes along the inheritance chain. B) Polymorphism means that one object reference can be typecast into another object reference. C) Polymorphism means that a variable of a supertype can refer to a subtype object. D) Polymorphism means that every class in Java is descended from the java.lang.Object class.

C

What is the difference between the java.util.Vector and java.util.ArrayList classes? A) Vector is the same as ArrayList, just older. B) Vector is the same as ArrayList, except that it contains asynchrous methods for accessing and modifying the vector. C) Vector is the same as ArrayList, except that it contains synchronized methods for accessing and modifying the vector. D) ArrayLists is more widely used in Java legacy code than Vector.

C

what framework are lists and sets all a part of?

Collection

In a java.util.PriorityQueue, what happens if several elements have the same highest priority? A) Priority Queues insist on unique priorities for each element. Therefore, this scenario is impossible. B) The tie is broken using first in, first out (FIFO). C) An error occurs. D) The tie is broken arbitrarily.

D

Construct a map with a string key and integer value

Map<String, Integer> hashMap = new HashMap<>();

class that cannot create an instances o objects but can contain methods to be implemented by subclasses

abstract

to use inheritance, what keyword do you need (subclass ____ superclass)?

extends

T/F A programmer defined class has no superclass unless the class is defined explicitly to extend a superclass

false

T/F An abstract class can be implemented but not extended.

false

T/F Any object can be explicitly cast into another object without error.

false

T/F For general purpose usage, java.util.LinkedList perform better than java.util.ArrayList

false

T/F HashSet is ordered

false

T/F Java supports multiple inheritance for classes but only single inheritance for interfaces

false

T/F The class java.util.List can be instantiated like List<String> myList = new List<String>();

false

T/F java.util.ArrayList is synchronized, which means only one thread at a time can access the code.

false

T/F java.util.Map inherits from java.util.Collection

false

T/F java.util.Queue is a LIFO (last in first out) data structure

false

T/F java.util.Set allows for duplicated elements.

false

T/F java.util.Stack is a FIFO (first in first out) data structure

false

T/F maps can be constructed with primitives (ie. int) instead of generics

false

to use an interface, use this keyword (class ____ interface)

implements

java pillar that defines new classes from existing classes

inheritance

class-like construct for defining common operations for objects. Extends to unrelated objects

interface

do treeMaps sort by key or value?

key

When is it more beneficial to use a linked list over array list?

linked lists are more efficient at adding/removing at beginning/end

data structure that stores ordered collections of items

list

data structure allowing you to retrieve a value using a key

map

java pillar in which the variable of a supertype can refer to a subtype

polymorphism

data structure that processes objects FIFO

queue

data structure that stores + processes nonduplicate elements

set

What is the con of a set over list?

sets cannot contain duplicates

What is the pro of a set over list?

sets find elements and remove elements more efficiently

data structure that processes objects LIFO

stack

T/F A collections framework is a unified architecture for representing and manipulating collections, enabling collections to be manipulated independently of implementation details.

true

T/F A final method cannot be overridden by a subclass.

true

T/F A java.util.Map cannot contain duplicate keys and each key can map at most one value.

true

T/F An interface can extend another interface

true

T/F An interface is for defining common behavior for classes (including unrelated classes).

true

T/F Assuming class Alpha extends Beta and we instantiate Alpha alpha = new Alpha(); then alpha can be passed into a method with signature public void doSomething(Beta beta).

true

T/F Collection<?> is a collection whose element type matches anything

true

T/F Collections that do not support modification operations (such as add, remove, and clear) are referred to as unmodifiable.

true

T/F If a class is defined as final, the class cannot be extended.

true

T/F In Java, every class is part of an inheritance hierarchy, because java.lang.Object is automatically a base class to every Java class.

true

T/F Java classes may only inherit directly from only one superclass.

true

T/F Neither an abstract class nor an interface can be instantiated as an object.

true

T/F The compiler erases all type parameters at compile time.

true

T/F The forEach method requires the class to be Iterable.

true

T/F a class can implement multiple interfaces but only extend 1 superclass

true

T/F java.util.Comparator provides an ordering for collections of objects that don't have a natural ordering.

true

T/F java.util.Vector can use both java.util.Enumeration and java.util.Iterator for traversig over elements of vector while java.util.ArrayList can only use java.util.Iterator for traversing.

true


Ensembles d'études connexes

Consumer Behavior Final (Chapters 8-11, 14-16, and 18) (quiz 5-12)

View Set

UNIT: PYTHAGOREAN THEOREM AND IRRATIONAL NUMBERS

View Set

Linear Algebra - Chapter 2 "Matrix Operations"

View Set

Microeconomics Test 1 (ch 1, 2, 3)

View Set

Week 9: The Tea Industry Around the World- Todays Consumer (lecture)

View Set

Ch 10: The Sharing Economy, Collaborative Consumption, and Efficient Markets through Tech

View Set

Chapter 7 Business- Government Relations

View Set

Microbiology Lecture Practical 1 Part 4; Chap 1, 4, 5, & 6

View Set

professional practice lecture 1-10

View Set

Sim Lab 11.1: Module 11 Harden PC with Group Policy Editor

View Set