INTRODUCTION TO PRIMITIVE DATA TYPES BUILDING BLOCKS OF
INTRODUCTION TO PRIMITIVE DATA TYPES
BUILDING BLOCKS OF JAVA byte float short double int char long boolean
LITERALS Java Literals are syntactic representations of boolean, character, numeric, or string data. Literals provide a means of expressing specific values in your program.
NUMERIC LITERALS Integers: Most whole number literals are type int by default Any whole number between -2, 147, 483, 648 and 2, 147, 483, 647 Floating-Point Numbers: Any number with a decimal point They are treated as double values unless you add an “F” to make them a float 1. 2345 is a double literal 1. 2345 F is a float (more precise) literal
A single CHARACTER LITERAL character inside single quotation marks Ex. ‘a’, ‘B’
LOGICAL LITERAL Booleans: Only two Boolean literals exist true false
Literal: a fixed value in Java USING PRIMITIVE DATA TYPES • Ex: 3. 14, ‘a’, “pancakes” Named Value: a data field that is given a name • Variable: value that can change (placeholder) • Constant: value can’t change (fixed) • Ex: Math. PI
STRING LITERALS – NOT A PRIMITIVE DATA STYLE "This is a character string. " String literals consist of the double quote character ("), zero or more characters, followed by a terminating double quote character (")
ESCAPE SEQUENCE A character preceded by a backslash; has special meaning to the compiler
EXAMPLE CODE
- Slides: 10