Introduction to Programming (CPSC 124)
—Hobart & William Smith Colleges, Spring 2015
Class Notes—January 30, 2015
Home | Syllabus | Calendar | Class Notes | Labs and Projects | General Notes |

# Built-in (primitive) data types

### double

 values approximations of real numbers literals -43.234,   3.2e14,   0.0,   3.1415928,   1e-9 operator + - * / meaning addition subtraction multiplication division See also float (less precise approximation of real numbers)

### int

 values Integer values between -231 and 231 -1 literals -435623,   -32,   -1,   0,   1,   2,   42,   90000 operators + - * / % meaning addition subtraction multiplication integer division remainder See also long (-263 ... 263 -1),   short (-215 ... 215 -1),   byte (-27 ... 27 -1)

NOTE: Remember that division on all integer types truncates any fractional part, rather than rounding. For example, 9/4 == 2, and 99/100 == 0.

# Other Data Types

Here are some of the other data types built in to Java. We'll cover these over the next week or so.

### boolean

 values "yes" / "no" literals true,    false operators && || ! meaning and or (inclusive) not
 comparisons (between numeric types), yielding boolean result operator meaning true false == is equal to? 1 == 1 1 == 2 != is not equal to? 1 != 2 1 != 1 < is less than? 1 < 2 1 < 1 <= is less than or equal to? 1 <= 1 2 <= 1 > is greater than? 2 > 1 1 > 1 >= is greater than or equal to? 1 >= 1 1 >= 2

### char

 values Integer values between 0 and 255, used to represent characters literals 0, 1, 2, 93, 'a', 'A', '2', '[', '\$', '.', '\"', '\t', '\n' operators (see int) See also int ,   long ,   short ,   byte

# (Sort of) built-in data types

### String

 values sequences of characters literals "Hey there!",  "23",  "" operators + meaning string concatenation note Note: String is a "mostly built-in" type, and we can think of it as such for the first few weeks of the class (until we get to Objects). As we will see, there is actually a great deal more to String values than what is described here

### Arrays

 values sequences of values, all of the same type (including other arrays) literals None. However, there is a literal initialization form, usable in declaration of an array variable (and not otherwise): int[] A = {2,3,5,7,11,13} operators A[i] A.length meaning access the ith element of A number of elements in A note An array with n has indices 0 ... (n-1). Arrays, like String values, are really objects. They, too, have some features of primitive types.

John Lasseter