printf : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

printf
Java version 1.5 or later, java.io.PrintWriter. printf, java.io.PrintStream. printf and the java.util. Formatter class give you abilities similar to C’s printf. You can also use String. format to build a String using the formatting scheme. It was added in response to C++ programmers coming to Java who wanted their familiar formatting tools. Don’t confuse printf and print/ println.

It is particularly useful for making listings line up by assigning fixed widths to your fields or for displaying in hex.

G format gives you an ability like the G format in FØRTRAN, which will display in F format or E format as appropriate.

The java.text.DecimalFormat and java.text. NumberFormat classes in Java version 1.1 or later give you similar ability a bit more verbosely. 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. Gary Cornell and Cay Horstmann’s book Core Java 2 includes one.

Most people don’t bother with printf. They use the + concatenation operator instead of printf.

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

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

Books

book cover recommend book⇒Core Java Volume I-Fundamentals (10th Edition) (Core Series)to book home
by Cay S. Horstmann 978-0-13-417730-4 paperback
birth 1959-06-16 age:58 978-0-13-417735-9 eBook
publisher Prentice Hall B019PFBM0M kindle
published 2016-01-01
Aimed at someone who already knows C++. This is not a fluffy introductory book.
Australian flag abe books anz abe books.ca Canadian flag
German flag abe books.de amazon.ca Canadian flag
German flag amazon.de Chapters Indigo Canadian flag
Spanish flag amazon.es Chapters Indigo eBooks Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Nook at Barnes & Noble American flag
Italian flag amazon.it Kobo American flag
India flag junglee.com Google play American flag
UK flag abe books.co.uk O’Reilly Safari American flag
UK flag amazon.co.uk Powells American flag
UN flag other stores
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.

Learning More

Oracle’s Javadoc on PrintWriter.printf : available:
Oracle’s Javadoc on PrintStream.printf : available:
Oracle’s Javadoc on Formatter class : available:
Oracle’s Javadoc on String.format : available:

This page is posted
on the web at:

http://mindprod.com/jgloss/printf.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\printf.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[44.199.225.221]
You are visitor number