Java Programming Principles Software Design Coursera Week 4

In this blog you will find the correct answer of the Coursera quiz Java Programming Principles Software Design Coursera Week 4 mixsaver always try to brings best blogs and best coupon codes
 

Week- 4

Java: Tools and Libraries for Everyone

 

 

1.
Question 1
What is the name of the method that starts a Java program?

1 point

firstMethod

_start

main

begin

2.
Question 2
What argument type should the method that starts a Java program take?

1 point

an int and a String

an ArrayList<String>

an array of Strings

no arguments

3.
Question 3
What effect comes from declaring a field “static”?

1 point

The value in the field cannot be changed once it is initialized.

The value in the field can only be changed by code inside the class.

The value in the field can only increase, never decrease.

There is only one copy of that field for the entire class, not one per instance.

4.
Question 4
In Java, how is the keyword “throw” used?

1 point

To make an exception occur when the program detects a problematic circumstance that it cannot directly handle.

To transfer data across a network connection.

To handle an exception that has already occurred.

To open a file for writing.

5.
Question 5
Creating a new socket, as with:

1
Socket s = new Socket(addr,port);
can throw an IOException according to the documentation of the java.net.Socket class.

Which of the following structures is the best way to create a socket while handling the exception?

1 point

try {
Socket s = new Socket(addr, port);
//code that uses s
}
catch(IOException ioe) {
//code to handle the exception
}

6.
Question 6
In Java, how is the keyword “finally” used?

1 point

In exception handling to specify code that should be executed regardless of whether an exception happened or not.

To specify code to run when the program exits.

To specify a piece of code to execute immediately after the end of the current loop.

To indicate that you are finally done debugging a particularly complicated piece of code.

7.
Question 7
If you wanted to read the contents of a file without using the edu.duke package, you might call Files.newBufferedReader.

What would you pass into Files.newBufferedReader?

1 point

a Comparator

an IOException

a Path

a FileResource

8.
Question 8
If you need to read data from a website without using the edu.duke package, you would probably want to use classes found in which package?

1 point

java.internet

java.lolcats

java.net

java.urls

9.
Question 9
You saw that a BufferedReader can be used to read data from a file on the local computer, as well as from a website. You could also use it with other sources of data, as long as you have an appropriate Reader class to access the data.

These capabilities are a great example of the benefits of which programming principles? Select the two best options.

1 point

Open/Closed Principle: the BufferedReader class is designed such that it can have its functionality expanded (to read from new data sources) without having to modify its code

Everything Is A Number: the BufferedReader class can read data of any type, and return it as a Java object of an appropriate class

Abstraction: the BufferedReader class can work with any class that conforms to a specific interface, and does not need to know the details of how/where it reads data

Astrachan’s Law: you can only use the BufferedReader class to solve interesting problems, never for something boring or that you could do by hand

Write Robust Code: the BufferedReader class never throws an exception, instead it deals with every situation

 

 

Important Links: