Java Reference
In-Depth Information
since double operations involve more data transfer, but the size of the tradeoff
depends on the JVM and the platform. (In Chapter 12 we discuss techniques for
measuring code performance.)
The representations of the primitives are the same on all machines to ensure
the portability of the code. However, during calculations involving floating-point
values, intermediate values can exceed the standard exponent ranges if allowed
by the particular processor (see Table A.3.1). The strictfp modifier of classes
or methods requires that the values remain within the range allowed by the
Java specifications throughout the calculation to ensure the same results on all
platforms.
2.12 Programming
As seen in Chapter 1, you must code within an object-oriented framework. How-
ever, you can apply the Java elements, structures, and techniques discussed so
farinthis chapter to straightforward procedural programming and ignore object-
oriented issues until later. You can simply insert code into the main() method
of an application or in the init() method of an applet, as shown in the starter
programs of Chapter 1, and not yet deal with the workings of class and object
concepts.
To program something interesting you need the ability to display output in
some way. Since we postpone graphics interface programming until Chapter 6, we
use methods from the core Java library to print to the console in our demonstration
programs through Chapter 5. Below, we use this technique to look at an example
of code that illustrates various aspects of floating-point operations.
2.12.1 Print to console
Java possesses a very extensive set of Input/Output (I/O) tools and capabilities
but Java Input/Output is somewhat complicated and is best introduced after gain-
ing more experience with the objected oriented aspects of the language. So we
introduce Java I/O techniques over several chapters and devote all of Chapter 9
to I/O.
Fornow we give just some simple techniques for printing to the console,
which refers to the command line window where you run applications or the Java
console window in the browser holding an applet. (The Java environment on the
Apple Macintosh also provides a console window for application output.)
Until we discuss graphics and graphical user interfaces in Chapter 6, we rely
heavily on the following methods to see the results of a program:
System.out.print (string) // no line return
System.out.println (string) // includes line return
where string denotes any String object that you create as explained in
Section 2.6.
Search WWH ::




Custom Search