Q1. Given the code format:
SimpleDateFormat sdf;
Which code statements will display the full text month name?
A. sdf = new SimpleDateFormat ("mm", Locale.UK); System.out.println("Result:", sdf.format(new date()));
B. sdf = new SimpleDateFormat ("MM", Locale.UK); System.out.println("Result:", sdf.format(new date()));
C. sdf = new SimpleDateFormat ("MMM", Locale.UK); System.out.println("Result:", sdf.format(new date()));
D. sdf = new SimpleDateFormat ("MMMM", Locale.UK); System.out.println("Result:", sdf.format(new date()));
Answer: D
Explanation:
Typical output would be Current Month in M format: 2 Current Month in MM format: 02 Current Month in MMM format: Feb Current Month in MMMM format: February
Q2. Which two compile?
A. interface Compilable {
void compile();
}
B. interface Compilable {
final void compile();
}
C. interface Compilable {
static void compile();
}
D. interface Compilable { abstract void compile(); }
E. interface Compilable { protected abstract void compile (); }
Answer: A,D
Q3. Given: What is the result?
A. doc
B. index.html
C. an IllegalArgumentException is thrown at runtime.
D. An InvalidPthException is thrown at runtime.
E. Compilation fails.
Answer: B
Explanation:
p.getName(int location) = returns path' name element by index/location (starts with 0)
Example:
path = "project//doc//index.html"
p.getName(0) = project
p.getName(1) = doc
p.getName(2) = index.html
Q4. Which two actions can be used in registering a JDBC 3.0 driver?
A. Add the driver class to the META-INF/services folder of the JAR file.
B. Set the driver class name by using the jdbc.drivers system property.
C. Include the JDBC driver class in a jdbcproperties file.
D. Use the java.lang.class.forName method to load the driver class.
E. Use the DriverManager.getDriver method to load the driver class.
Answer: A,D
Explanation:
A: if your JDBC Driver is NOT JDBC 4-compliant then we can update the driver using "jar"-utility by adding the "META-INF /services/java.sql.Driver" inside it. as following: D:Dynamic loading of Java classes at runtime provides tremendous flexibility in the development of enterprisesystems. It provides for the basis of "application servers", and allows even simpler, lighter-weight systems toaccomplish some of the same ends. Within Java, dynamic-loading is typically achieved by calling the forNamemethod on the class java.lang.ClassAn example provided by the standard Java SE API is the ServiceLoader. Amongothers, the JDBC 4.0compatible drivers implement this. This way just dropping the JDBC driver JAR file folder will automatically loadthe driver class during Java application's startup/initialization without the need for any manual Class.forName("com.example.Driver") line in your code.
Q5. Give:
What is the result?
A. There are 27 sports cars and 5 trucks
B. There are 27 convertibles and 5 trucks
C. There are 9 sports cars and 5 trucks
D. There are 9 convertibles and 5 trucks
E. IllegalFormatConversionException is thrown at runtime
Answer: C
Explanation:
Strings are immutable, therefore no change at line: svar.replace(svar,"convertibles");
Format String Syntax:
%[argument_index$][flags][width][.precision]conversion
The optional argument_index is a decimal integer indicating the position of the argument in
the argument list.
The first argument is referenced by "1$", the second by "2$", etc.
The optional flags is a set of characters that modify the output format. The set of valid flags
depends on theconversion.
's', 'S' general
'd' integral The result is formatted as a decimal / integer
Q6. For which three objects must a vendor provide implementations in its JDBC driver?
A. Time
B. Date
C. Statement
D. ResultSet
E. Connection
F. SQLException
G. DriverManager
Answer: C,D,E
Explanation:
All JDBC drivers implement the four important JDBC classes: Driver, Connection, Statement, and ResultSet.
Q7. When using the default file system provider with a JVM running on a DOS-based file system, which statementis true?
A. DOS file attributes can be read as a set in a single method call.
B. DOS file attributes can be changed as a set in a single method call.
C. DOS file attributes can be modified for symbolic links and regular files.
D. DOS file attributes can be modified in the same method that creates the file.
Answer: A
Explanation:
File attributes associated with a file in a file system that supports legacy "DOS" attributes.
Usage Example:
Path file = ...
DosFileAttributes attrs = Files.readAttributes(file, DosFileAttributes.class);
Note:
The methodreadAttributes() reads a file's attributes as a bulk operation.
Q8. Given the code fragment: SimpleDataFormat sdf;
Which code fragment displays the three-character month abbreviation?
A. SimpleDateFormat sdf = new SimpleDateFormat ("mm", Locale.UK); System.out.println
("Result:" +
sdf.format(new Date()));
B. SimpleDateFormat sdf = new SimpleDateFormat ("MM", Locale.UK); System.out.println
("Result:" +
sdf.format(new Date()));
C. SimpleDateFormat sdf = new SimpleDateFormat ("MMM", Locale.UK);
System.out.println ("Result:" +
sdf.format(new Date()));
D. SimpleDateFormat sdf = new SimpleDateFormat ("MMMM", Locale.UK);
System.out.println ("Result:" +
sdf.format(new Date()));
Answer: C
Q9. The default file system includes a logFiles directory that contains the following files:
Log-Jan 2009
log_0l_20l0
log_Feb20l0
log_Feb2011
log_10.2012
log-sum-2012
How many files does the matcher in this fragment match?
PathMatcher matcher = FileSystems.getDefault ().getPathMatcher ("glob: *???_*1?" );
A. One
B. Two
C. Three
D. Four
E. Five
F. Six
Answer: B
Explanation:
The pattern to match is *???_*1? (regex ".*..._.*1.")
This means at least three characters before the symbol _ , followed by any amount of
characters. The next tolast character must be 1. The last character can by any character.
The following file names match this pattern:
log_Feb2011
log_10.2012 Trap !! l is not 1 !!
Q10. Given:
What is the result?
A. Pastel Enamel Fresco Gouache B. Pastel *Enamel Fresco *Gouache
C. Pastel Enamel Fresco Gouache
D. Pastel Enamel, Fresco Gouache
Answer: B
Explanation:
regex explanation:
, = ,
\ = masks the following
\s = A whitespace character: [ \t \n \x0B \f \r ]
* = Greedy Quantifier: zero or more times Delimiter: comma + zero or more whitespace characters