lec3 - CSE 8A Lecture 3 More about Java primitive types...

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

View Full Document Right Arrow Icon
Page 1 of 34 CSE 8A, UCSD LEC 3 CSE 8A: Lecture 3 More about Java primitive types Literal constants Numeric operators and the String concatenation operator The assignment operator and assignment statements Type conversions (Reading: Savitch, parts of Ch. 2)
Background image of page 1

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

View Full DocumentRight Arrow Icon
Page 2 of 34 CSE 8A, UCSD LEC 3 Primitive types and literal constants Every variable exists as a pattern of bits in computer memory How many bits are contained in a variable, and how that pattern of 1’s and 0’s is interpreted by the computer, depends on the type of the variable Last time, we saw how to read in a value from the keyboard into a primitive type variable, for example using a Scanner : Scanner keybd = new Scanner(System.in); int n; n = keybd.nextInt(); If when writing your program you know the value you want a primitive type variable to have, you can give it that value in an assignment statement by writing a literal constant of an appropriate type, for example: float pi; pi = 3.14159; Now we will look in more detail at the Java primitive types, and their corresponding literal constants
Background image of page 2
Page 3 of 34 CSE 8A, UCSD LEC 3 Review: Primitive data types in Java Numeric types: for representing numbers integral types: byte short int long for representing whole integer numbers floating-point types: float double for representing fractional numbers, or very large numbers character type (often considered to be an integral type): char for representing letters and symbols boolean type: boolean for representing boolean (true or false) values
Background image of page 3

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

View Full DocumentRight Arrow Icon
Page 4 of 34 CSE 8A, UCSD LEC 3 Integral types byte 8 bits of memory each can represent integers in the range -128 through 127 short 16 bits of memory each can represent integers in the range -32768 through 32767 int 32 bits of memory each can represent integers in the range -2 31 through 2 31 - 1 long 64 bits of memory each can represent integers in the range -2 63 through 2 63 - 1 In CSE 8A, we’ll mainly use int
Background image of page 4
Page 5 of 34 CSE 8A, UCSD LEC 3 Integer literal constants Integer literals are used to specify particular integer values in your programs Specify an integer value as a string of base-10 digits. .. preceded by a ‘-’ sign if you want it to be negative End with the letter “L” if you want it to be of type long ... otherwise, it will be int 43 // Okay! 12345 -22 3000000000L 3,456,789 // Nope! 3.14159
Background image of page 5

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

View Full DocumentRight Arrow Icon
Page 6 of 34 CSE 8A, UCSD LEC 3 Base-8 and base-16 integer literals Usually you write integer literals in good old familiar base-10 (decimal) notation But Java also permits base-8 (octal) or base-16 (hexadecimal) integer literals: Base 10 uses 10 digits 0-9, and place values are powers of 10: 1, 10, 100, 1000,. .. Base 8 uses 8 digits 0-7, and place values are powers of 8: 1, 8, 64, 512,. ..
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/12/2008 for the course CSE 8 taught by Professor Marx during the Fall '08 term at UCSD.

Page1 / 34

lec3 - CSE 8A Lecture 3 More about Java primitive types...

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

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