The Department of Computer Science & Engineering
cse@buffalo
STUART C. SHAPIRO: CSE 115 C

CSE 115
Introduction To Computer Science for Majors I
Lecture C
Lecture Notes #21
Stuart C. Shapiro
Spring, 2007


Primitives Types & Related Issues 1: int

Values of Java primitive types are not objects, but for each primitive type there is a wrapper (or "boxed") class that is a subclass of java.lang.Object.

The primitive types we will discuss, and their corresponding wrapper classes are:

PrimitiveWrapper
intjava.lang.Integer
booleanjava.lang.Boolean
doublejava.lang.Double

Integers
Integers are numbers used for counting.
The primitive integer type is int, and its wrapper class is java.lang.Integer.
Write an integer constant literal as a sequence of digits without a comma.
The integer operators are:
OperatorMeaning
+addition or unary plus
-subtraction or unary minus
*multiplication
/integer division
%modulus (remainder)

Their precedence order is:

unary +, unary -
*, /, %
+, -

Shortcuts, e.g. += and ++

Autoboxing makes the difference between ints and Integers almost invisible.

See java.lang.Math for some functions provided by the Java library.

First Previous Next

Copyright © 2007 by Stuart C. Shapiro. All rights reserved.

Last modified: Wed Nov 7 10:44:46 EST 2007
Stuart C. Shapiro <shapiro@cse.buffalo.edu>