This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CMPT 126: Review Tamara Smyth, [email protected] School of Computing Science, Simon Fraser University November 28, 2007 1 Primitive data types • Primitive data types consists of – Integers ( byte , short , int , long ) – Floating Points ( float, double ) – Characters ( char ) – Booleans ( boolean ) • The Java language uses the Unicode character set , which uses 16 bits per character, supporting 65, 536 unique characters. • Numeric primitive data types: Type # bits Min Value Max Value integer: byte 8-128 127 short 16-32,768 32,767 int 32-2,147,483,648 2,147,483,647 long 64-9,223,372,036,854,775,808 9,223,372,036,854,775,807 floating point: float 32 ≈-3.4E+38 (7 s.f.) ≈ 3.4E+38 (7 s.f.) double 64 ≈-1.7E+308 (15 s.f.) ≈ 1.7E+308 (15 s.f.) Table 1: Numeric Primitive Data Types • All numeric types are signed , i.e., they may store both positive and negative values. CMPT 126: Review 2 • Generally, for floating point values, always use double to avoid problems related to round-off errors. • What is a constant, and how would it be declared in Java? CMPT 126: Review 3 Literals • A literal is an explicit data value used in a program. • Java assumes all integer literals are of type int unless an L or l is appended to indicate it should be of type long . long countedStars = 8982723927L; • Java assumes all floating point literals are of type double unless an F or f is appended to indicate it should be of type float . float ratio = 0.2363F; • A character literal is expressed using single quotes: ‘c’. CMPT 126: Review 4 String Literals • String literals are expressed using double quotations: ‘‘The quick brown fox jumped over the lazy dog.’’ ‘‘sos’’ ‘‘’’ • A string literal cannot span multiple lines in a program: the following will not compile: System.out.println(‘‘The only stupid question is the one that’s not asked.’’); • Solution: use string concatenation (the ’+’ operator): System.out.println(‘‘The only stupid question is’’ + ‘‘the one that’s not asked.’’); • Escape sequences: How does one print (using println ) a double quotation character without having the compiler interpret it as the end of a string?...
View Full Document
This note was uploaded on 12/07/2010 for the course CMPT 125 taught by Professor Diana during the Spring '08 term at Simon Fraser.
- Spring '08