Java Glossary : printf

CMP home Java glossary home Menu no menu Last updated 2004-06-28 by Roedy Green ©1996-2004 Canadian Mind Products

Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

You are here : home : Java Glossary : P words : printf.

printf
the java.text.DecimalFormat and java.text.NumberFormat classes in JDK 1.1. Unfortunately, Java 1.0.2 has no equivalent to the C printf or sprintf function for formatting numbers for display. You have to roll your own. One such class is available from San Diego State University called sdsu.FormatString. Acme also has one. Eliote Rusty Harold did one. The Lava Rocks tutorials also includes one. Gary Cornell and Cay Horstmann's book Core Java 2 includes one.

Most people don't bother. You use the + concatenation operator instead of printf.

// in idiomatic Java you would say:
System.out.println( "x:" + x + " y:" + y );

// instead of C-style
System.out.printf( "x: %d y: %d", x, y );

book_coverCore Java 2, Volume I: Fundamentals (6th Edition)
0-13-047177-1
Cay Horstmann and Gary Cornell
Covers JDK 1.4 such as regular expressions, New I/O, assertions, Preferences, Swing enhancements and logging. Aimed at someone who already knows C++. This is not a fluffy introductory book.
amazon.com Barnes and Noble
amazon.ca chapters
amazon.co.uk amazon.de


CMP logo
CMP_home
home
Canadian Mind Products CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[24.87.56.253]
Your IP:[80.134.30.163]
You are visitor number 2245.
Please send errors, omissions and suggestions
to improve this page to Roedy Green.
You can get a fresh copy of this page from: or possibly from your local J: drive mirror:
http://mindprod.com/jgloss/printf.html J:\mindprod\jgloss\printf.html