28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 3 ■ A <strong>Java</strong> 8 Primer: An Introduction to <strong>Java</strong> 8 Concepts and Principles<br />

values of different sizes and resolutions. Integer values hold whole numbers, whereas a floating point value holds<br />

fractional (decimal point value) numbers. It is important to use the right numeric data type for a variable’s scope, or<br />

range, of use, because, as you can see in Binary Size column in Table 3-1, large numeric data types can use up to eight<br />

times more memory than the smaller ones.<br />

Table 3-1. <strong>Java</strong> Primitive Data Types, Along with Their Default Values, Size in Memory, Definition, and Numeric Range<br />

Data Type Default Binary Size Definition Range<br />

boolean false 1 bit True or false value 0 to 1 (false or true)<br />

char \u0000 16 bit Unicode character \u0000 to \uFFFF<br />

byte 0 8 bit Signed integer value –128 to 127 (256 total values)<br />

short 0 16 bit Signed integer value –-32768 to 32767 (65,536 total values)<br />

int 0 32 bit Signed integer value –2147483648 to 2147483647<br />

long 0 64 bit Signed integer value –9223372036854775808 to<br />

9223372036854775807<br />

float 0.0 32 bit IEEE 754 floating point value ±1.4E-45 to ±3.4028235E+38<br />

double 0.0 64 bit IEEE 754 floating point value ±4.9E-324 to<br />

±1.7976931348623157E+308<br />

Reference Data Types: Objects and Arrays<br />

(OOP languages also have reference data types, which provide a reference in memory to another structure<br />

containing a more complex data structure, such as an object or an array. These more complex data structures are<br />

created using code; in the case of <strong>Java</strong>, this is a class. There are <strong>Java</strong> Array classes of various types that create arrays of<br />

data (such as simple databases) as well as the constructor method in a <strong>Java</strong> class, which can create the object structure<br />

in memory, containing both <strong>Java</strong> code (methods) and data (fields).<br />

<strong>Java</strong> Operators: Manipulating Data in the Application<br />

In this section, you will learn about some of the most commonly used operators in the <strong>Java</strong> programming language,<br />

especially those that are the most useful for programming games. These include arithmetic operators, used for<br />

mathematical expressions; relational operators, used to ascertain relationships (equal, not equal, greater than, less<br />

than, and so on) between data values; logical operators, used for boolean logic; assignment operators, which do<br />

the arithmetic operations and assign the value to another variable in one compact operation (operator); and the<br />

conditional operator, also called a ternary operator, which assigns a value to a variable, based on the outcome of a<br />

true or false (boolean) evaluation.<br />

There are also the conceptually more advanced bitwise operators, used to perform operations at the binary data<br />

(zeroes and ones) level, the logic of which is beyond the beginner scope of this book and the use of which is not as<br />

common in <strong>Java</strong> game programming as these other, more mainstream types of operators, each of which you will be<br />

using over the course of this book to accomplish various programming objectives in your game play logic.<br />

61<br />

www.it-ebooks.info<br />

5

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

Saved successfully!

Ooh no, something went wrong!