Archive

Posts Tagged ‘scjp’

Java – Console

August 17th, 2009 CertPal 14 comments

To get sensitive user input without echoing it to the console/terminal, the Java SDK has introduced the java.io.Console class. The Console class is quite unique in the way it handles its data. It uses the native encoding of the system instead of the using the JVM’s default encoding.

The Console class provides methods to access the console/terminal, if any is associated with the JVM.

Using the Console class:
So how do you use the Console class ? Its pretty simple really. First get a reference to the Console class from the System class

1
Console con = System.console();

It is not always possible to get a reference to the console. Some scenarios prevent the developer from gaining access to the console. This method may return null in these cases. For example a batch process running on a server will not expect user input and usually does have a console. Your code must be capable of handling such situations.

Categories: Java certifications Tags: , ,

Java – Navigable Set

August 15th, 2009 CertPal 19 comments

Sets:

A Set is a collection that contains no duplicate elements. Sets are collections where no two elements are the same, which means that element1.equals(element2) should never return true. Also at most one element in a set can be null and no more.

A Set. Duplicates are not allowed and at most one null element is allowed

Sorted Sets:

A SortedSet is a set which sorts and maintains the ordering of its elements. Elements will be ordered by their natural ordering or by the use of a Comparator (if the developer provides one). A Comparable interface can help define the ordering for elements. For example a String’s natural ordering will dictate that elements be ordered this way “a”, “b”, “c” etc. The way in which elements are ordered in a Sorted data structure can be redefined by using the Comparator interface.