lOMoARcPSD|9936472
Graded Quiz Unit 6 Attempt review
Programming 2 (University of the People)
StuDocu is not sponsored or endorsed by any college or university
Downloaded by asdfw welk lsadkfj wq (
[email protected])
lOMoARcPSD|9936472
Ko Danso Amakye
Home My courses CS 1103 - AY2021-T1 8 October - 14 October Graded Quiz Unit 6
Started on Tuesday, 13 October 2020, 3:43 PM
State Finished
Completed on Tuesday, 13 October 2020, 3:53 PM
Time taken 9 mins 39 secs
Marks 21.65/24.00
Grade 90.21 out of 100.00
Question 1 Correct Mark 1.00 out of 1.00
Which of the following statements are true?
Select one or more:
a. A socket is a kind of opening.
b. A socket represents one endpoint of a network connection.
c. A program uses a socket to communicate with another program over the network.
d. Data written by a program to the socket at one end of the connection is transmitted
to the socket on the other end of the connection, where it can be read by the program
at that end.
The correct answers are: A socket is a kind of opening., A socket represents one endpoint
of a network connection., A program uses a socket to communicate with another program
over the network., Data written by a program to the socket at one end of the connection is
transmitted to the socket on the other end of the connection, where it can be read by the
program at that end.
/
Downloaded by asdfw welk lsadkfj wq ([email protected])
lOMoARcPSD|9936472
Question 2 Correct Mark 1.00 out of 1.00
The Collection interface is the base interface for …
Select one or more:
a. Set
b. List
c. ArrayList
d. LinkedList
e. Map
The correct answers are: Set, List, ArrayList, LinkedList
/
Downloaded by asdfw welk lsadkfj wq ([email protected])
lOMoARcPSD|9936472
Question 3 Correct Mark 1.00 out of 1.00
Given the following code:
public class Test {
public static void main(String[] args) {
Map map = new HashMap();
map.put("123", "John Smith");
map.put("111", "George Smith");
map.put("123", "Steve Yao");
map.put("222", "Steve Yao");
}
}
Which statement is correct?
Select one:
a. After all the four entries are added to the map, "123" is a key that corresponds to the
value "John Smith".
b. After all the four entries are added to the map, "123" is a key that corresponds to
the value "Steve Yao".
c. After all the four entries are added to the map, "Steve Yao" is a key that corresponds
to the value "222".
d. After all the four entries are added to the map, "John Smith" is a key that
corresponds to the value "123".
e. A runtime error occurs because two entries with the same key "123" are added to
the map.
The correct answer is: After all the four entries are added to the map, "123" is a key that
corresponds to the value "Steve Yao".
/
Downloaded by asdfw welk lsadkfj wq ([email protected])
lOMoARcPSD|9936472
Question 4 Correct Mark 1.00 out of 1.00
Consider the following code:
Bu eredImage OSC = new Bu eredImage(32,32,Bu eredImage.TYPE_INT_RGB);
Select one or more:
a. A Bu eredImage is a region in memory that can be used as a drawing surface.
b. In this statement, the image that is created is 32 pixels wide and 32 pixels high, and
the color of each pixel is an RGB color that has red, green, and blue components in the
range 0 to 255.
c. The picture in a Bu eredImage can easily be copied into a graphics context g by
calling one of the g.drawImage methods.
d. The image drawn here is so small, it seems likely that is going to be used to de ne
an ImageIcon.
The correct answers are: A Bu eredImage is a region in memory that can be used as a
drawing surface., In this statement, the image that is created is 32 pixels wide and 32 pixels
high, and the color of each pixel is an RGB color that has red, green, and blue components
in the range 0 to 255., The picture in a Bu eredImage can easily be copied into a graphics
context g by calling one of the g.drawImage methods., The image drawn here is so small, it
seems likely that is going to be used to de ne an ImageIcon.
Question 5 Correct Mark 1.00 out of 1.00
Suppose List<String> list = new ArrayList<String>. Which of the following operations
are correct?
Select one:
a. list.add("Red");
b. list.add(new Integer(100));
c. list.add(new java.util.Date());
d. list.add(new ArrayList());
The correct answer is: list.add("Red");
/
Downloaded by asdfw welk lsadkfj wq ([email protected])
lOMoARcPSD|9936472
Question 6 Partially correct Mark 0.25 out of 1.00
Suppose List list = new ArrayList(). Which of the following operations are correct?
Select one or more:
a. list.add("Red");
b. list.add(new Integer(100));
c. list.add(new java.util.Date());
d. list.add(new ArrayList());
The correct answers are: list.add("Red");, list.add(new Integer(100));, list.add(new
java.util.Date());, list.add(new ArrayList());
Question 7 Incorrect Mark 0.00 out of 1.00
Which of the data type below could be used to store elements in their natural order
based on the compareTo method?
Select one:
a. HashSet
b. TreeSet
c. LinkedHashSet
d. Collection
e. Set
The correct answer is: TreeSet
/
Downloaded by asdfw welk lsadkfj wq ([email protected])
lOMoARcPSD|9936472
Question 8 Partially correct Mark 0.40 out of 1.00
You can use the methods in the Collections class to:
Select one or more:
a. nd the maximum object in a collection based on the compareTo method.
b. nd the maximum object in a collection using a Comparator object.
c. sort a collection.
d. shu e a collection.
e. do a binary search on a collection.
The correct answers are: nd the maximum object in a collection based on the compareTo
method., nd the maximum object in a collection using a Comparator object., sort a
collection., shu e a collection., do a binary search on a collection.
Question 9 Correct Mark 1.00 out of 1.00
To declare a class named A with two generic types, use
a. public class A<E> { ... }
b. public class A<E, F> { ... }
c. public class A(E) { ... }
d. public class A(E, F) { ... }
Select one:
a.
b.
c.
d.
The correct answer is: b.
/
Downloaded by asdfw welk lsadkfj wq ([email protected])
lOMoARcPSD|9936472
Question 10 Correct Mark 1.00 out of 1.00
Which of the following statements is correct?
Select one or more:
a. Generics can help detect type errors at compile time, thus make programs more
robust.
b. Generics can make programs easy to read.
c. Generics can avoid cumbersome castings.
d. Generics can make programs run faster.
The correct answers are: Generics can help detect type errors at compile time, thus make
programs more robust., Generics can make programs easy to read., Generics can avoid
cumbersome castings.
Question 11 Correct Mark 1.00 out of 1.00
Which of these statements describe the FontMetrics class?
Select one or more:
a. FontMetrics resides in the java.io package.
b. The FontMetrics(Font font)constructor creates a new FontMetrics object for nding
out sizes of characters and strings that are drawn in a speci c font.
c. The font is speci ed when the FontMetrics object is created.
d. If fm is a variable of type FontMetrics, then, for example, fm.stringWidth(str) gives
the width of the string str and fm.getHeight() is the usual amount of vertical space
allowed for one line of text.
The correct answers are: The FontMetrics(Font font)constructor creates a new FontMetrics
object for nding out sizes of characters and strings that are drawn in a speci c font., The
font is speci ed when the FontMetrics object is created., If fm is a variable of type
FontMetrics, then, for example, fm.stringWidth(str) gives the width of the string str and
fm.getHeight() is the usual amount of vertical space allowed for one line of text.
/
Downloaded by asdfw welk lsadkfj wq ([email protected])
lOMoARcPSD|9936472
Question 12 Correct Mark 1.00 out of 1.00
Which of the following statements describe a client/server model ?
Select one or more:
a. Computer transactions using the client/server model are very common.
b. Client/server describes the relationship between two computer programs in which
one program, the server, makes a service request from another program, the client,
which ful lls the request.
c. Although the client/server idea can be used by programs within a single computer, it
is a more important idea in a network.
d. In a network, the client/server model provides a convenient way to interconnect
programs that are distributed e ciently across di erent locations.
e. Client/server computing or networking is a distributed application architecture that
partitions tasks or work loads between service providers (servers) and service
requesters, called clients.
The correct answers are: Computer transactions using the client/server model are very
common., Although the client/server idea can be used by programs within a single
computer, it is a more important idea in a network., In a network, the client/server model
provides a convenient way to interconnect programs that are distributed e ciently across
di erent locations., Client/server computing or networking is a distributed application
architecture that partitions tasks or work loads between service providers (servers) and
service requesters, called clients.
Question 13 Correct Mark 1.00 out of 1.00
Which of the following are correct methods in Map?
Select one or more:
a. put(Object key, Object value)
b. put(Object value, Object key)
c. get(Object key)
d. get(int index)
The correct answers are: put(Object key, Object value), get(Object key)
/
Downloaded by asdfw welk lsadkfj wq ([email protected])
lOMoARcPSD|9936472
Question 14 Correct Mark 1.00 out of 1.00
Which of the following statements are true?
Select one or more:
a. The Comparable interface contains the compareTo method with the signature
"public int compareTo(Object)".
b. The Comparator interface contains the compare method with the signature "public
int compare(Object, Object)".
c. A Comparable object can compare this object with the other object.
d. A Comparator object contains the compare method that compares two objects.
The correct answers are: The Comparable interface contains the compareTo method with
the signature "public int compareTo(Object)"., The Comparator interface contains the
compare method with the signature "public int compare(Object, Object)"., A Comparable
object can compare this object with the other object., A Comparator object contains the
compare method that compares two objects.
Question 15 Correct Mark 1.00 out of 1.00
The server listens for a connection request from a client using the following
statement:
Select one:
a. Socket s = new Socket(ServerName, port);
b. Socket s = serverSocket.accept()
c. Socket s = serverSocket.getSocket()
d. Socket s = new Socket(ServerName);
The correct answer is: Socket s = serverSocket.accept()
/
Downloaded by asdfw welk lsadkfj wq ([email protected])
lOMoARcPSD|9936472
Question 16 Correct Mark 1.00 out of 1.00
Which of these statements is true?
a. The hash code of an object is an integer that tells where that object should be
stored in a hash table.
b. A hash table is an array of linked lists. When an object is stored in a hash table, it
is added to one of these linked lists.
c. The object's hash code is the index of the position in the array where the object
is stored.
d. All objects with the same hash code go into the same linked list.
e. In Java, every object obj has a method obj.hashCode() that is used to compute
hash codes for the object.
f. If the object is to be stored in a hash table of size N, then the hash code that is
used for the object is Math.abs(obj.hashCode())%N.
Select one or more:
a.
b.
c.
d.
e.
f.
The correct answers are: a., b., c., d., e., f.
/
Downloaded by asdfw welk lsadkfj wq ([email protected])
lOMoARcPSD|9936472
Question 17 Correct Mark 1.00 out of 1.00
To store non-duplicated objects in the order in which they are inserted, use ….
Select one:
a. HashSet
b. LinkedHashSet
c. TreeSet
d. ArrayList
e. LinkedList
The correct answer is: LinkedHashSet
Question 18 Correct Mark 1.00 out of 1.00
To declare an interface named A with two generic types, use
a. public interface A<E> { ... }
b. public interface A<E, F> { ... }
c. public interface A(E) { ... }
d. public interface A(E, F) { ... }
Select one:
a.
b.
c.
d.
The correct answer is: b.
/
Downloaded by asdfw welk lsadkfj wq ([email protected])
lOMoARcPSD|9936472
Question 19 Correct Mark 1.00 out of 1.00
Which of the following statements are true?
Select one or more:
a. An ArrayList can grow automatically.
b. An ArrayList can shrink automatically.
c. You can reduce the capacity of an ArrayList by invoking the trimToSize() method on
the list.
d. You can reduce the capacity of a LinkedList by invoking the trimToSize() method on
the list.
The correct answers are: An ArrayList can grow automatically., You can reduce the capacity
of an ArrayList by invoking the trimToSize() method on the list.
Question 20 Correct Mark 1.00 out of 1.00
Java’s generic programming does not apply to the primitive types. True or False?
Select one:
True
False
The correct answer is 'True'.
/
Downloaded by asdfw welk lsadkfj wq ([email protected])
lOMoARcPSD|9936472
Question 21 Correct Mark 1.00 out of 1.00
The Map is the base interface for …
Select one or more:
a. TreeMap
b. HashMap
c. LinkedHashMap
d. ArrayList
e. LinkedList
The correct answers are: TreeMap, HashMap, LinkedHashMap
Question 22 Correct Mark 1.00 out of 1.00
Interaliasing ….
Select one or more:
a. Is intended to make an image look fuzzier.
b. Is the smoothing of the image roughness caused by aliasing
c. Is achieved by adjusting pixel positions or setting pixel intensities so that there is a
more gradual transition between the color of a line and the background color.
d. Makes images look perfect.
The correct answers are: Is the smoothing of the image roughness caused by aliasing, Is
achieved by adjusting pixel positions or setting pixel intensities so that there is a more
gradual transition between the color of a line and the background color.
/
Downloaded by asdfw welk lsadkfj wq ([email protected])
lOMoARcPSD|9936472
Question 23 Correct Mark 1.00 out of 1.00
Fill in the code in Comparable______ c = new Date();
a. <String>
b. <?>
c. <Date>
d. <E>
Select one:
a.
b.
c.
d.
The correct answer is: c.
Question 24 Correct Mark 1.00 out of 1.00
The class named URL resides in the java.io package. Which of the following
statements describe URL?
Select one or more:
a. A URL is an address for a web page (or other information) on the Internet.
b. A URL constructor creates an Address eld in a Web browser.
c. A URL object represents a Universal Resource Locator.
d. Once you have a URL object, you can call its openConnection() method to access the
information at the url address that it represents.
The correct answers are: A URL is an address for a web page (or other information) on the
Internet., A URL object represents a Universal Resource Locator., Once you have a URL
object, you can call its openConnection() method to access the information at the url
address that it represents.
◄ Self-Quiz Unit 6
Jump to...
/
Downloaded by asdfw welk lsadkfj wq ([email protected])
lOMoARcPSD|9936472
Code Unit 6 ►
/
Downloaded by asdfw welk lsadkfj wq ([email protected])