Question

In: Computer Science

OBJECT-ORIENTED JAVA The catch-or-declare requirement states that you have two choices: You can either catch the...

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

Solutions

Expert Solution

(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


Related Solutions

*OBJECT ORIENTED PROGRAMMING* JAVA PROGRAMMING GOAL: will be able to throw and catch exceptions and create...
*OBJECT ORIENTED PROGRAMMING* JAVA PROGRAMMING GOAL: will be able to throw and catch exceptions and create multi-threaded programs. Part I Create a class called Animal that implements the Runnable interface. In the main method create 2 instances of the Animal class, one called rabbit and one called turtle. Make them "user" threads, as opposed to daemon threads. Some detail about the Animal class. It has instance variables, name, position, speed, and restMax. It has a static boolean winner. It starts...
object oriented programming java Create a Student class that have two data members id (assign to...
object oriented programming java Create a Student class that have two data members id (assign to your ID) and name (assign to your name). Create the object of the Student class by new keyword and printing the objects value. You may name your object as Student1. The output should be like this: 20170500 Asma Zubaida
*OBJECT ORIENTED PROGRAMMING* GOAL: will be able to throw and catch exceptions and create multi-threaded programs....
*OBJECT ORIENTED PROGRAMMING* GOAL: will be able to throw and catch exceptions and create multi-threaded programs. Part I Create a class called Animal that implements the Runnable interface. In the main method create 2 instances of the Animal class, one called rabbit and one called turtle. Make them "user" threads, as opposed to daemon threads. Some detail about the Animal class. It has instance variables, name, position, speed, and restMax. It has a static boolean winner. It starts a false....
Describe how you would develop object-oriented features of Java for the Quiz program developed in the...
Describe how you would develop object-oriented features of Java for the Quiz program developed in the Programming Assignments. In particular, describe how the program could use each of the following: class variables, instance variables, inheritance, polymorphism, abstract classes, "this", "super", interfaces, and event listeners.
Describe how you would develop object-oriented features of Java for the Quiz program developed in the...
Describe how you would develop object-oriented features of Java for the Quiz program developed in the Programming Assignments. In particular, describe how the program could use each of the following: class variables, instance variables, inheritance, polymorphism, abstract classes, "this", "super", interfaces, and event listeners. Your Discussion should be at least 250 words in length, but not more than 750 words. Once you’ve completed your initial post, be sure to respond to the posts of at least 3 of your classmates.
What advantages does object-oriented exception handling provide? When a program contains multiple catch blocks, how are...
What advantages does object-oriented exception handling provide? When a program contains multiple catch blocks, how are they handled? Write the statement to declare a three-by-four array of integers with the elements initialized to zero. Name the array myArray. What is the difference between volatile and nonvolatile storage in Java programming? Give examples of different storage situations. What are some of the advantages of the ArrayList class over the Arrays class? How can you use the enhanced for loop? What does...
Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a...
Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, several methods to access and update the instance variables’ values, along with other methods to perform calculations. Also, write a test class that instantiates the first class and tests the class’s constructor and methods. Details: Create a class called Rectangle containing the following: Two instance variables, An instance variable of type double used to hold the rectangle’s width....
1. In Object Oriented Programming The private object fields can be directly manipulated by outside entities....
1. In Object Oriented Programming The private object fields can be directly manipulated by outside entities. Group of answer choices A. True B. False 2. __________ programming is centered on the procedures or actions that take place in a program. Group of answer choices A. Class B. Object-oriented C. Menu-driven D. Procedural/ Structural 3. __________ programming encapsulates data and functions in an object. Group of answer choices A. Object-oriented B. Class C. Menu-driven D. Procedural 4. The data in an...
catch me if you can (2002) write a report about catch me if you can (2002)...
catch me if you can (2002) write a report about catch me if you can (2002) must be 900 words that fully describes the movie including describing the main characters, the fraud situation in the movie, and how the situation plays out. The second part of the paper should discuss the actual persons and/or companies on which the movie focuses: Identify these actual persons / company; identify the type(s) of fraud(s) are alleged in the film; discuss your personal feelings...
Object-Oriented Design and Patterns in Java (the 3rd Edition Chapter 5) - Create a directory named...
Object-Oriented Design and Patterns in Java (the 3rd Edition Chapter 5) - Create a directory named as the question number and save the required solutions in the directory. - Each problem comes with an expected tester name. In the directory for a given problem, including the tester and all java classes successfully run this tester. Exercise 5.2 ObserverTester.java - Improve Exercise 1 by making the graph view editable. Attach a mouse listener to the panel that paints the graph. When...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT