Java: Tools and Libraries for Everyone

Ace your homework & exams now with Quizwiz!

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?

a Path

In Java, how is the keyword "finally" used?

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

What effect comes from declaring a field "static"?

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

In Java, how is the keyword "throw" used?

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

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

an array of Strings

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?

java.net

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

main

Creating a new socket, as with: 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?

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

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.

✅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 ✅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


Related study sets

Thomas Hobbes (Political Theory)

View Set

Collocations in Use tous les exercices

View Set

Chapter 13: Fluid and Electrolytes: Balance and Disturbance (2)

View Set

PRIMITIVE GOV'T, ANCIENT GREECE AND ANCIENT ROME

View Set

Nicholls > Business Law (BSAD 221) > Gene Gouaux > Test 2

View Set

AP Language & Composition - Rhetorical Modes/Devices/Strategies

View Set

CHEM 1035 - SmartBook Chapter 9 Part I

View Set

Chapter 7 Rutgers Business Logistics

View Set