Java Reference
In-Depth Information
format codes are more comprehensive than the original C printf , but the basic idea is the
same: you pass a format string and one or more objects to be formatted according to the
format string. For example, you might write:
System.out.printf("Pi is approximately %6.4f\n", Math.PI);
The % is the lead-in to the format code, and the 6.4f is (as it was in printf and in Fortran
before that) the code to print a floating-point value with a field-width of six characters and
four digits after the decimal place. So the program prints:
Pi is approximately 3.1416
There is much more to this, with support for date formatting, localization, and more. See the
documentation for java.util.Formatter for details.
There is also scanf -like functionality, in the Scanning Input with the Scanner Class . This
does not use % format codes, but uses a variety of next() methods, such as next(String) ,
next(Pattern) , nextInteger , nextDouble , and so on, plus all of the corresponding
hasNext() methods. See the documentation for java.util.Scanner . printf , and the scan-
ning utilities are covered in Discussion .
Bibliographic note/full disclosure
Some of the Java 5 material in this section originally appeared in an article I wrote on
O'Reilly Web back in the day.
What Was New in Java 6
By contrast to Java 5, December 2006's Java 6 release was more incremental. Though there
were no radical changes to the language, there were changes to the underlying JVM, includ-
ing performance improvements, upgrades to garbage collection, faster application start-up,
and a handful of new APIs.
Java 6 API Changes
The API changes included:
Search WWH ::




Custom Search