{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lect15review_4up

# lect15review_4up - Primitive data types CMPT 126 Review...

This preview shows pages 1–3. Sign up to view the full content.

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

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

View Full Document
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?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern