Home : Course Map : Chapter 5 : Java : Tech :
Chapter 5 : Formatting Output
JavaTech
Course Map
Chapter 5
File/Package/Import
  Demo 1
  Demo 2
Access/Visibility
final & Constants
Static Import
Jar Files
  Demo 3
Applet Directories
3rd Party Packages
CLASSPATH
javadoc
CodingConventions
Exercises

    Supplements
Scope
Debug Techniques
Java Runtime
Class Class
JVM Instructions 2
JVM Processing
pack200

     About JavaTech
     Codes List
     Exercises
     Feedback
     References
     Resources
     Tips
     Topic Index
     Course Guide
     What's New

As mentioned before, one of the difficulties with introductory Java is dealing with I/O topics. Java I/O is very powerful but so elaborate that it is awkward to use for basic tasks like output of floating point numbers to the console.

In many of our demonstration programs, for example, you likely noticed that a simple floating point (FP) operation such as a divide can result in a long fraction when we use the default conversion of a double to a String.

In this chapter we will look at tools for formatting of floating point numbers. This includes both decimal format and scientific notation.

  • DecimalFormat class in the java.text package added scientific notation with Java 1.2.
  • System.out.printf() - Java 5.0 added this method, which offers formatted output like the printf() function in C. Internally it uses the Formatter class, which we will discuss in Chapter 9.
  • Format - an opens ource class from the Core Java book series.
  • We then list several other independent classes that provide formatting tools.

 

 

Last update: Oct. 23, 2004

            Tech
DecimalFormat
  Demo 1
  Demo 2

System.out.printf
  Demo 3
CJ Format Class
  Demo 4   Demo 5
Other Format Tools

Immutable Complex
Exercises

           Physics
Interpolation
Integration
  Demo 1
Simpson Rule
  Demo 2
Exercises

  Part I Part II Part III
Java Core 1  2  3  4  5  6  7  8  9  10  11  12 13 14 15 16 17
18 19 20
21
22 23 24
Supplements

1  2  3  4  5  6  7  8  9  10  11  12

Tech 1  2  3  4  5  6  7  8  9  10  11  12
Physics 1  2  3  4  5  6  7  8  9  10  11  12

Java is a trademark of Sun Microsystems, Inc.