14.07.2013 Views

Contents - Cultural View

Contents - Cultural View

Contents - Cultural View

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

strictfp 281<br />

Behaviors and restrictions<br />

Strictfp is sometimes viewed as a problem of Java [3] [4] .<br />

References<br />

• http:/ / java. sun. com/ docs/ books/ vmspec/ 2nd-edition/ html/ Concepts. doc. html#24465<br />

[1] Flanagan, David (March 2005). Java in a Nutshell (http:/ / oreilly. com/ catalog/ 9780596007737) (Fifth ed.). O'Reilly Media.<br />

ISBN 978-0-596-00773-7. . Retrieved 2010-03-03.<br />

[2] Schildt, Herbert (2007). Java: A Beginner's Guide (4 ed.). McGraw-Hill Companies. ISBN 978-0-07-226384-8.<br />

[3] Kahan, W.; Joseph D. Darcy (1998-03-01). "How Java's Floating-Point Hurts Everyone Everywhere" (http:/ / www. cs. berkeley. edu/<br />

~wkahan/ JAVAhurt. pdf) (PDF). . Retrieved 2006-12-09.<br />

[4] "Types, Values, and Variables" (http:/ / java. sun. com/ docs/ books/ jls/ third_edition/ html/ typesValues. html#4. 2. 3). Sun Microsystems. .<br />

Retrieved 2006-12-09.<br />

String Buffer<br />

In object-oriented programming, a String Buffer is an alternative to a String. It has the ability to be altered through<br />

adding or appending, whereas a String is normally fixed or unchangeable.<br />

In Java<br />

Theory<br />

Java's standard way to handle text is to use its String class. Any given String in Java is an immutable object, which<br />

means its state cannot be changed. A String has an array of characters. Whenever a String must be manipulated, any<br />

changes require the creation of a new String (which, turn, involves the creation of a new array of characters, and<br />

copying of the original array). This happens even if the original String's value or intermediate Strings used for the<br />

manipulation are not kept.<br />

Java provides an alternate class for string manipulation, called a StringBuffer [1] . A StringBuffer, like a String, has<br />

an array to hold characters. It, however, is mutable (its state can be altered). Its array of characters is not necessarily<br />

completely filled (as oppose to a String, whose array is always the exact required length for its contents). Thus, it has<br />

the capability to add, remove, or change its state without creating a new object (and without the creation of a new<br />

array, and array copying). The exception to this is when its array is no longer of suitable length to hold its content. In<br />

this case, it is required to create a new array, and copy contents.<br />

For these reasons, Java would handle an expression like<br />

String newString = aString + anInt + aChar + aDouble;<br />

like this:<br />

String newString = (new StringBuffer(aString)).append(anInt).append(aChar).append(aDouble)).toString();<br />

Implications<br />

Generally, a StringBuffer is more efficient than a String in string handling. However, this is not necessarily the case,<br />

since a StringBuffer will be required to recreate its character array when it runs out of space. Theoretically, this is<br />

possible to happen the same number of times as a new String would be required, although this is unlikely (and the<br />

programmer can provide length hints to prevent this). Either way, the effect is not noticeable in modern desktop<br />

computers.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!