
Core Java Assessment

Quiz
•
Computers
•
Professional Development
•
Hard
Ananth Kumar
Used 13+ times
FREE Resource
25 questions
Show all answers
1.
MULTIPLE SELECT QUESTION
3 mins • 1 pt
Given that you are working with a JDBC 4.0 driver, which three are required for this JDBC driver to be compliant?
Must include a META-INF/services/java.sql.Driver file
Must provide implementations of Driver, Connection, Statement, and ResultSet interfaces
Must support scrollable ResultSets
Must support PreparedStatement and CallableStatement
Must support transactions
2.
MULTIPLE SELECT QUESTION
3 mins • 1 pt
Which three are available through an instance of DatabaseMetaData?
The number of rows returned
The name of the JDBC driver
The default transaction isolation level
The last query used
The names of stored procedures in the database
3.
MULTIPLE SELECT QUESTION
3 mins • 1 pt
Given this code fragment:
Statement stmt = conn.createStatement();
ResultSet rs;
String query = "<QUERY HERE>";
stmt.execute(query);
if ((rs = stmt.getResultSet()) != null) {
System.out.println("Results");
}
if (stmt.getUpdateCount() > -1) {
System.out.println("Update");
}
Which query statements entered into <QUERY HERE> produce the output that follows the query string (in the following answer), assuming each query is valid? (Choose all that apply.)
"SELECT * FROM Customer"
Results
. "INSERT INTO Book VALUES ('1023456789', 'One Night in Paris', '1984-10-20',
'Hardcover', 13.95)"
Update
"UPDATE Customer SET Phone = '555-234-1021' WHERE CustomerID = 101"
Update
"SELECT Author.LastName FROM Author"
Results
. "DELETE FROM Book WHERE ISBN = '1023456789'"
Update
4.
MULTIPLE SELECT QUESTION
3 mins • 1 pt
Given:
String call = "{CALL REMOVEBOOKS(?, ?)}";
String titleToRemove = null;
int maxBooks = 0;
CallableStatement cstmt = conn.prepareCall(call);
String titles = "%Hero%";
int numBooksRemoved;
// Code added here
If REMOVEBOOKS is a stored procedure that takes an INOUT integer parameter as its first argument and an IN String parameter as its second argument, which code blocks, when placed at the line
// Code added here, could correctly execute the stored procedure and return a result?
cstmt.setInt(0, maxBooks);
cstmt.setString(1, titleToRemove);
cstmt.registerOutParameter(0, java.sql.Types.INTEGER);
cstmt.execute();
numBooksRemoved = cstmt.getInt(0);
cstmt.setInt(1, maxBooks);
cstmt.setString(2, titleToRemove);
cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
cstmt.executeQuery(query);
numBooksRemoved = cstmt.getInt(1);
cstmt.setInt(1, maxBooks);
cstmt.setString(2, titleToRemove);
cstmt.execute();
cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
numBooksRemoved = cstmt.getInt(1);
cstmt.setInt(1, maxBooks);
cstmt.setString(2, titleToRemove);
cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
ResultSet rs = cstmt.executeQuery();
rs.next();
numbBooks = rs.getInt(1);
cstmt.setInt(1, maxBooks);
cstmt.setString(2, titleToRemove);
cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
cstmt.execute();
numBooksRemoved = cstmt.getInt(1);
5.
MULTIPLE SELECT QUESTION
3 mins • 1 pt
Assume you have a class that holds two private variables: a and b. Which of the following pairs can prevent concurrent access problems in that class? (Choose all that apply.)
public synchronized int read(){return a+b;}
public synchronized void set(int a, int b){this.a=a;this.b=b;}
public int read(){synchronized(a){return a+b;}}
public void set(int a, int b){synchronized(a){this.a=a;this.b=b;}}
public int read(){synchronized(a){return a+b;}}
public void set(int a, int b){synchronized(b){this.a=a;this.b=b;}}
public synchronized(this) int read(){return a+b;}
public synchronized(this) void set(int a, int b){this.a=a;this.b=b;}
public int read(){synchronized(this){return a+b;}}
public void set(int a, int b){synchronized(this){this.a=a;this.b=b;}}
6.
MULTIPLE SELECT QUESTION
3 mins • 1 pt
public class TwoThreads {
static Thread laurel, hardy;
public static void main(String[] args) {
laurel = new Thread() {
public void run() {
System.out.println("A");
try {
hardy.sleep(1000);
} catch (Exception e) {
System.out.println("B");
}
System.out.println("C");
}
};
hardy = new Thread() {
public void run() {
System.out.println("D");
try {
laurel.wait();
} catch (Exception e) {
System.out.println("E");
}
System.out.println("F");
}
};
laurel.start();
hardy.start();
}
}
Which letters will eventually appear somewhere in the output? (Choose all that apply.)
A
C
D
E
F
7.
MULTIPLE SELECT QUESTION
3 mins • 1 pt
This class is intended to allow users to write a series of messages so that
each message is identified with a timestamp and the name of the thread that wrote the message:
public class Logger {
private StringBuilder contents = new StringBuilder();
public void log(String message) {
contents.append(System.currentTimeMillis());
contents.append(": ");
contents.append(Thread.currentThread().getName());
contents.append(message);
contents.append("\n");
}
public String getContents() { return contents.toString(); }
}
How can we ensure that instances of this class can be safely used by multiple threads?
This class is already thread-safe
Replacing StringBuilder with StringBuffer will make this class thread-safe
Synchronize the log() method only
Synchronize the getContents() method only
Synchronize both log() and getContents()
Create a free account and access millions of resources
Similar Resources on Wayground
22 questions
Java Chapter 2 Review Questions

Quiz
•
Professional Development
25 questions
Java Basics

Quiz
•
Professional Development
20 questions
VCE TalentNext-2021 Quiz-2

Quiz
•
Professional Development
25 questions
Quiz Básico de Java

Quiz
•
7th Grade - Professio...
20 questions
Dev Web Java / Angular

Quiz
•
Professional Development
20 questions
Quiz Day 1 - Day 8

Quiz
•
Professional Development
28 questions
Java Fundamentals

Quiz
•
Professional Development
30 questions
Blind Coding Round 1

Quiz
•
Professional Development
Popular Resources on Wayground
10 questions
Video Games

Quiz
•
6th - 12th Grade
20 questions
Brand Labels

Quiz
•
5th - 12th Grade
15 questions
Core 4 of Customer Service - Student Edition

Quiz
•
6th - 8th Grade
15 questions
What is Bullying?- Bullying Lesson Series 6-12

Lesson
•
11th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade