13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

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.

54Chapter 3An Experienced Programmer’s Introducti<strong>on</strong> to JavaExample 3.1 Coercing a byte to int as if the byte were unsignedbyte c;int ival;...ival = ((int) c) && 0xFF; // explicit cast needed3.2.1.2 Floating Point TypesJava provides two different precisi<strong>on</strong>s of floating point numbers. They are:• float: 32 bits• double: 64 bitsThe float type is not very useful at that precisi<strong>on</strong>, so double is muchmore comm<strong>on</strong>ly seen. For other situati<strong>on</strong>s where precisi<strong>on</strong> is important, butyou can spare some cycles, c<strong>on</strong>sider the BigDecimal and BigIntegerobject classes.Java floating point numbers are specified to follow the IEEE floating pointstandard, IEEE 754.3.2.1.3 Other TypesJava also has a boolean type, al<strong>on</strong>g with c<strong>on</strong>stants true and false. In Java,unlike C/C++, boolean values are a distinct type, and do not c<strong>on</strong>vert t<strong>on</strong>umeric types. For example, it is comm<strong>on</strong> in C to write:if (strlen(instr)) {strcpy(buffer, instr);}In this case, the integer result of strlen() is used as a boolean, where 0 isfalse and any other value is true. This doesn’t work in Java. The expressi<strong>on</strong>must be of a boolean type.Java also has a char type, which is not the same as a byte. The char is acharacter, and in Java, characters are represented using Unicode (UTF-16).They take two bytes each.For more discussi<strong>on</strong> <strong>on</strong> the differences between bytes and chars andabout Unicode, read the Java tutorial <strong>on</strong> the java.sun.com Web site or visitwww.unicode.org, the internati<strong>on</strong>al standard’s Web site.

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

Saved successfully!

Ooh no, something went wrong!