In: Computer Science
OBJECT-ORIENTED JAVA
The catch-or-declare requirement states that
you have two choices:
You can either catch the exception or you can provide a throws
clause.
To which exceptions does the catch-or-declare
requirement apply?
Errors
All Exceptions except RuntimeExceptions
RuntimeExceptions
All Throwable except Errors
Flag this Question
Question 21 pts
Assume you have an array called numbers.
It's elements are of type int and it was declared like this:
int[] numbers = { 3, 6, 9, 12 };
Assume that you also have a method called
printArray. It was declared with the following
method header:
private static void printArray(T[]
inputArray)
Based on the information above answer the following question:
What happens when you call the method printArray and you pass the
array numbers as an argument - like this:
printArray(numbers);
No elements are printed
The array elements are printed in rectangular brackets as specified in the toString method
The array elements are printed as specified in method printArray
Flag this Question
Question 32 pts
Complete the sentences below.
Generic method declarations have a type parameter section that is delimited by [ Select ] ["{ }", "( )", "<>", "[ ]"] .
When we instantiate a generic class or interface without any type arguments it is said to have a [ Select ] ["wild type", "diamond", "raw type", "generic type"] .
Such types should be [ Select ] ["used whenever possible", "avoided", "encouraged"] in new code.
In order to be able to use the interface method compareTo in my generic method I need to restrict the types that can be substituted for the type parameter. I can do this like this: [ Select ] [">", "< implements Comparable>", ">", "< extends Comparable>"]
Flag this Question
Question 42 pts
Match each problem on the left to the Java API class that is best suited to help solve the problem
I need to read in test results from a csv file
[ Choose ] File Scanner ObjectOutputStream PrintWriter
I need to list all files of a given directory
[ Choose ] File Scanner ObjectOutputStream PrintWriter
I need to serialize a prodcut list ( List )
[ Choose ] File Scanner ObjectOutputStream PrintWriter
I need to save the names and sNumbers of all CS1410 students in a text file.
[ Choose ] File Scanner ObjectOutputStream PrintWriter
Flag this Question
Question 52 pts
Complete the sentences below.
In order to serialize an object from the heap and store it to a file we need 2 Java API classes to work together: [ Select ] ["ObjectInputStream and ObjectOutputStream", "FileOutputStream and FileOutputStream", "ObjectInputStream and FileInputStream", "ObjectOutputStream and FileOutputStream"]
[ Select ]
["FileInputStream",
"ObjectOutputStream", "ObjectInputStream", "FileOutputStream"]
takes the object from the
heap and turns it into a stream of bytes and
[ Select ]
["FileOutputStream", "ObjectInputStream",
"ObjectOutputStream", "FileInputStream"]
takes the stream of bytes and stores it in a
file.
Flag this Question
Question 61 pts
Which of the following best describes the relationship between ClassX and ClassY?
Association
Aggregation
Composition
Inheritance
Flag this Question
Question 72 pts
Match each description on the left to the corresponding term.
A sequence of bytes, which can be accessed in sequential order
[ Choose ] Serialization Stream File
Data or information that has a name and is stored on a secondary storage device
[ Choose ] Serialization Stream File
The process of converting an object into a stream
[ Choose ] Serialization Stream File
Flag this Question
Question 81 pts
Complete the sentence below:
Classes that implement the interface
................................ can be used as a
resource in a try-with-resource statement
AutoClosable
AutoResource
Serializable
Collection
Flag this Question
Question 91 pts
When the compiler translates generic methods into byte-code it uses _____________ to replace the type parameter with actual types
Generic type replacement
Compile-time type safety
Eraser
Erasure
Flag this Question
(Q21) public static <T> void printArray(T[] array)
we can't take parameterized type as T if we take it should return same type what is parameterized
the method you provides shows compile time error
Q32)
(Q)Generic method declarations have a type parameter section that is delimited by
Ans :- <>
(Q) When we instantiate a generic class or interface without any type arguments it is said to have a
Ans : raw type
(Q) In order to be able to use the interface method compareTo in my generic method I need to restrict the types that can be substituted for the type parameter. I can do this like this:
Ans : < implements Comparable>
Q42)
(Q)the Java API class that is best suited to help solve the problemI need to read in test results from a csv file
Ans : File
(Q) I need to list all files of a given directory
Ans :File
(Q) I need to serialize a prodcut list ( List )
Ans : ObjectOutputStream
(Q) I need to save the names and sNumbers of all CS1410 students in a text file.
Ans:File
Q52)
(Q) In order to serialize an object from the heap and store it to a file we need 2 Java API classes to work together:
Ans: ObjectInputStream and ObjectOutputStream
(Q) takes the object from the heap and turns it into a stream of bytes
Ans : FileInputStream
(Q) takes the stream of bytes and stores it in a file.
Ans : ObjectOutputStream
Q61)Which of the following best describes the relationship between ClassX and ClassY?
Ans : Association
Q72)
(Q) A sequence of bytes, which can be accessed in sequential order
Ans : Stream
(Q) Data or information that has a name and is stored on a secondary storage device
Ans :File
(Q) The process of converting an object into a stream
Ans :Serialization
Q81) Classes that implement the interface ................................ can be used as a resource in a try-with-resource statement
Ans : AutoClosable
Q91) When the compiler translates generic methods into byte-code it uses _____________ to replace the type parameter with actual types
Ans : Erasure