04 - 01/28/09 03:52:43 CS 61B: Lecture 4 Wednesday, January...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
01/28/09 03:52:43 1 04 CS 61B: Lecture 4 Wednesday, January 28, 2009 Today’s reading: PRIMITIVE TYPES =============== Not all variables are references to objects. Some variables are primitive types, which store values like "3", "7.2", "h", and "false". They are: byte: A 8-bit integer in the range -128. ..127. (One bit is the sign.) short: A 16-bit integer in the range -32768. ..32767. int: A 32-bit integer in the range -2147483648. ..2147483647. long: A 64-bit integer, range -9223372036854775808. ..9223372036854775807. double: A 64-bit floating-point number like 18.355625430920409. float: A 32-bit floating-point number; has fewer digits of precision. boolean: "true" or "false". char: A single character. long values are written with an L on the end: long x = 43L; This tells the compiler to internally write out "43" in a 64-bit format. double and float values must have a decimal point: double y = 18.0; float values are written with an f at the end: float f = 43.9f; Object types Primitive types -------------------------------------------------------------------------- Variable contains a reference value How defined? class definition built into Java How created? "new" "6", "3.4", "true" How initialized? constructor default (usually zero) How used? methods operators ("+", "*", etc.) Operations on int, long, short, and byte types. -x x * y x + y x / y <-- rounds toward zero (drops the remainder). x - y x % y <-- calculates the remainder of x / y. Except for "%", these operations are also available for doubles and floats.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/21/2010 for the course CS 61B taught by Professor Canny during the Spring '01 term at University of California, Berkeley.

Page1 / 2

04 - 01/28/09 03:52:43 CS 61B: Lecture 4 Wednesday, January...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online