Java Reference
In-Depth Information
Notice how each value is located. Since each double value is 8 bytes long, each value starts
on an 8-byte boundary. Thus, the first value is located at zero, the second begins at byte 8,
the third starts at byte 16, and so on. Thus, to read the fourth value, the program seeks to
location 24.
Ask the Expert
Q :
In looking through the documentation provided by the JDK, I noticed a class
called Console. Is this a class that I can use to perform console-based I/O?
A : The short answer is Yes. The Console class was added by JDK 6, and it is used to
read from and write to the console. Console is primarily a convenience class because
most of its functionality is available through System.in and System.out . However,
its use can simplify some types of console interactions, especially when reading
strings from the console.
Console supplies no constructors. Instead, a Console object is obtained by calling Sys-
tem.console( ) . It is shown here.
static Console console( )
If a console is available, then a reference to it is returned. Otherwise, null is returned. A
console may not be available in all cases, such as when a program runs as a background
task. Therefore, if null is returned, no console I/O is possible.
Console defines several methods that perform I/O, such as readLine( ) and printf( ) . It
also defines a method called readPassword( ) , which can be used to obtain a password. It
lets your application read a password without echoing what is typed. You can also obtain a
reference to the Reader and the Writer that are attached to the console. In general, Con-
sole is a class that you may find useful for some types of applications.
Search WWH ::




Custom Search