Friday, January 04, 2008

Java 6 Quiz

1. What group makes decisions on which functionality will be present in the final release of Java SE 6?
A. JSR 145
B. JSR 270
C. JSR 10
D. Top corporate executives and politicians in a smoke-filled room

Answer: B is correct. The JSR 270 Expert Group includes experts from such companies as Apache, IBM, Oracle, Intel, BEA, Hewlett-Packard, and JBoss. This group defines the feature set for the next major release of Java SE. All the features discussed in this quiz are subject to the group's review and approval.

2. Sun's implementation of Java SE 6 introduces which of the following new features:
A. An embedded Mozilla Rhino JavaScript interpreter
B. New system-tray functionality
C. New splash-page functionality
D. All of the above

Answer: D is correct. The Mozilla Rhino JavaScript interpreter (which is specific to Sun's implementation and is not part of the draft Java SE 6 specification) is available through the ScriptEngineFactory class in the javax.script package, which includes the Rhino interpreter by default. Here is a short snippet of source code that invokes the JavaScript interpreter:

import javax.script.*;

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine rhinoEngine = manager.getEngineByName("javascript");

try {
Object o1 = rhinoEngine.eval("new Date().getMonth()");
System.out.println(o1);
} catch (ScriptException e) {
System.err.println(e);
}

The system-tray functionality is available through the SystemTray and TrayIcon classes in the java.awt package. Finally, the splash-screen functionality is available through the SplashScreen class in java.awt, as well as the -splash command-line option at JVM* startup.

3. What important addition to the JTabbedPane was added in Java SE 6?

A. The ability to add a tooltip to the tab
B. The ability to add an icon to the tab
C. The ability to substitute a Component as a tab's identifier
D. The ability to add and remove tabs

Answer: C is correct. You can now use subclasses of Component for tab identifiers in a JTabbedPane, instead of just Strings and Icons. For example, you can use a JPanel that contains not only a JLabel that displays the title of the tab but also a JButton X that allows you to close or remove the tab from the JTabbedPane. Don't forget to setOpaque(false) on those components! See Alexander Potochkin's blog for more information.

4.With Java SE 6, what functionality can you now perform with java.io.File?
A. Set permissions and check free and usable disk space.
B. Check whether a file is marked as hidden.
C. Check whether a file is in fact a directory and determine its parent directory.
D. Nothing was added to java.io.File.

Answer: A is correct. Starting with build 31 in Java SE, several new methods have been added to java.io.File. You can now set the owner and universal readable, writable, and executable flag of a file residing on a local or network file system that supports that operation.

public boolean setReadable(boolean readable, boolean ownerOnly)
public boolean setReadable(boolean readable)

public boolean setWritable(boolean writable, boolean ownerOnly)
public boolean setWritable(boolean writable)

public boolean setExecutable(boolean executable, boolean ownerOnly)
public boolean setExecutable(boolean executable)In addition to file system permissions, Java SE 6 gives you three new methods to determine the amount of space available on the partition represented by a File object.
public long getTotalSpace();
public long getFreeSpace();

public long getUsableSpace();What's the difference between getFreeSpace() and getUsableSpace()? The getFreeSpace() method returns an instantaneous count of the amount of free space on the partition. The getUsableSpace()method, on the other hand, contains extra functionality to check for write permissions and other operating system restrictions, which therefore returns a more accurate estimate of how much space will be available. If you want to determine whether you have enough disk space before writing to a file, getUsableSpace() will give you a more accurate estimate. Note that both of these methods can throw a SecurityException if a security manager has been installed and it denies a call to RuntimePermission("getFileSystemAttributes").

5. JSR 105 calls for support for XML encryption and digital signatures in Java SE 6. In what package can you find this functionality?
A. java.xml.security
B. javax.xml.crypto
C. java.security
D. javax.xml.validation

Answer: B is correct. JSR 105 defines a standard API for XML digital signature services and is a key component for web services security. This functionality was delivered in build 39, and although you will use many of the classes through the java.xml packages to work with XML, the primary encryption and digital signature functionality is located in the javax.xml.crypto package. (The javax.xml.validation package helps to perform XML validation against a schema. The java.security package deals with Java class security.) See JSR 105 to learn more about these new classes.

6. What new functionality was added to JTable in Java SE 6?
A. The ability to resize columns in a JTable
B. The ability to move columns in a JTable
C. The ability to define custom cell table views
D. The ability to sort and filter data in a JTable

Answer: D is correct. Starting with build 39, JTable now has methods to sort, highlight, and filter the contents of tables. The other three options were already supported by JTable. Portions of this work come from the Java Desktop Network Components (JDNC). A recent java.sun.com tech tip provides more information.

7. Java SE 6 now incorporates an advanced version of SwingWorker into the core. What is the purpose of SwingWorker?
A. It helps to move lengthy GUI-interacting tasks into a dedicated thread, so as
not to block the event-dispatch thread.
B. It coordinates interthread communication between an executing thread and the
event-dispatch thread.
C. It can aggregate several intermediate parameters generated by the worker thread
into a single, generic "return" object.
D. All of the above.

Answer: D is correct. Since the 1998 publication of SwingWorker in the article "Threads and Swing," developers have continuously requested that the SwingWorker class be moved into core. At the 2004 JavaOne conference, the Desktop team presented a new version of SwingWorker that included generification, use of the concurrency package, and PropertyChangeListener support. Much of this functionality assists with interthread communication. Java SE 6 incorporates a similar version of SwingWorker that greatly assists developers in processing GUI-driven functionality off the event-dispatching thread, indicating status and progress, and aggregating the results.

8. What new functionality does the JTextComponent class include?
A. Additional printing support, including headers, footers, and layout
B. Bidirectional text
C. Embedded scrolling
D. HTML support

Answer: A is correct. Starting in build 39, printing support for JTextComponent has been added, including the ability to specify a customer header or footer and have the text laid out to the printed page size. By using overloaded versions of the print() method, programmers can define more flexible options when formatting data within a JTextComponent to a printer.

9. What additional calendar does Java SE 6 now support?
A. Thai Buddhist
B. Islamic lunar
C. Mayan
D. Japanese imperial

Answer: D is correct. A new Calendar implementation has been added to support numbering for the Japanese imperial era, such as Heisei 17 for 2005 (Gregorian). An instance of this Japanese imperial calendar can be created through the Calendar.getInstance() factory by specifying Locale("ja", "JP", "JP").

10. What is the purpose of the new java.text.Normalizer class?
A. It provides a spell-checking service provider interface.
B. It sorts text quickly and efficiently.
C. It transforms text into an equivalent composed or decomposed form.
D. It provides online, real-time language translation.

Answer: C is correct. The new java.text.Normalizer class transforms text into an equivalent composed or decomposed form. This class supports Unicode text normalization as defined by the Unicode Standard Annex #15. Normalization helps standardize Unicode text representations when multiple character combinations exist for creating the same text.

11. JSR 221 is defining the Java DataBase Connectivity (JDBC) 4.0 software specification. Which of the following are significant additions in JDBC 4.0 software, which will be included in Java SE 6?
A. SQL:2003 XML support
B. National character-set support
C. Large object (LOB) enhancements
D. All of the above

Answer: D is correct. All of these features are included in JDBC 4.0 software. You can find out more on the JSR 221 page.

12. Java SE 6 includes a new modality model for dialog boxes. What previous JDK issue(s) does this address?
A. The user was unable to access a modal dialog box if its parent window was displayed above it.
B. JavaHelp windows could sometimes be inadvertently affected by modal dialog boxes.
C. There was only one blocking strategy for AWT and JFC/Swing modal dialog boxes.
D. All of the above.

Answer: D is correct. Starting with build 39, a new modality mode in Java SE 6 eliminates all of these problems. From the Desktop Java SE 6 features article: "Problems with modality have been plaguing developers for years.... In Java SE 6, we ... solve most of the modality problems by introducing several new modality modes (such as application modality, toolkit modality, and document modality) as well as exclusion from modality, which is useful for the applications like JavaHelp.

3 comments:

Unknown said...

Hi,

It's a good collection of Quiz for Java 6. It covers all the advanced topics. I've got the interest to upgrade myself into Java 6.

Thanks for your effort.

Robert William.

Unknown said...

you have nice site. thanks for sharing this site. various kinds of ebooks are available here

http://feboook.blogspot.com

Natalia said...

Good collection of questions. This questionnaire covers all the important topics. I do have bookmarked this article and will also share it with my friends too. Thanks for sharing it.
electronic signature FAQ