최신Oracle Upgrade to Java SE 7 Programmer - 1Z1-805무료샘플문제
Given:
public class DataCache {
private static final DataCache instance = new DataCache ();
public static DataCache getInstance () {
return instance;
}
}
Which design pattern best describes the class?
Given the code fragment:
try {
String query = "SELECT * FROM Employee WHERE ID=110";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query); // Line 13
System.out.println("Employee ID: " + rs.getInt("ID")); // Line 14
} catch (Exception se) {
System.out.println("Error");
}
Assume that the SQL query matches one record. What is the result of compiling and executing this code?
Given the code fragment:
private static void copyContents (File source, File target) {
try {inputStream fis = new FileInputStream(source);
outputStream fos = new FileOutputStream (target);
byte [] buf = new byte [8192]; int i;
while ((i = fis.read(buf)) != -1) {
fos.write (buf, 0, i);
}
//insert code fragment here. Line **
System.out.println ("Successfully copied");
}
Which code fragments, when inserted independently at line **, enable the code to compile?
You are using a database from XY/Data. What is a prerequisite for connecting to the database using a JDBC 4.0 driver from XY/Data?
Given the following incorrect program:
class MyTask extends RecursiveTask<Integer> {
final int low;
final int high;
static final int THRESHOLD = /* . . . */
MyTask (int low, int high) { this.low = low; this.high = high; }
Integer computeDirectly()/* . . . */
protected void compute() {
if (high - low <= THRESHOLD)
return computeDirectly();
int mid = (low + high) / 2;
invokeAll(new MyTask(low, mid), new MyTask(mid, high));
Which two changes make the program work correctly?
Given:
public class SampleClass {
public static void main(String[] args) {
SampleClass sc = new SampleClass();
sc.processCD();
}
private void processCD() {
try (CDStream cd = new CDStream()) {
cd.open();
cd.read();
cd.write("lullaby");
cd.close();
} catch (Exception e) {
System.out.println("Exception thrown");
}
}
class CDStream {
String cdContents = null;
public void open() {
cdContents = "CD Contents";
System.out.println("Opened CD stream");
}
public String read() throws Exception {
throw new Exception("read error");
}
public void write(String str) {
System.out.println("CD str is: " + str);
}
public void close() {
cdContents = null;
}
What is the result?
Given:
ConcurrentMap<String, String> partList = new ConcurrentHashMap<> (); Which fragment puts a key/value pair in partList without the possibility of overwriting an existing key?
Given the code fragment:
static void addContent () throws Exception {
Path path = Paths.get("D:\\company\\report.txt");
UserPrincipal owner = path.getFileSystem().getUserPrincipalLookupService().lookupPrincipalByName("Bob");
Files.setOwner(path, owner);
// insert code here - Line **
br.write("this is a text message ");
}
System.out.println("success");
}
Assume that the report.txt file exists.
Which try statement, when inserted at line **, enables appending the file content without writing the metadata to the underlying disk?
Which statement is true about the take method defined in the WatchService interface?