#Primitive Data Types

#Primitive Data Types

##What is a primitive data type?

- Numbers, characters and booleans

- Stored in fastest available memory

- Primitive data type names are all lowercase

- String is not a primitive, its an object

##Declaring Primitive Variables

- Java is a statically typed language

- All variables must have their types declared.

⬇️identifier

-  int myVar = 5;

^data type

##Equivalent Helper Class

- Java class library includes helper classes for each primitive

- Helper classes support conversion and formatting tools

(img)

##Helper Class Example

- java.lang.Double supports __double__ values

e.g.

''double doubleValue = 156.5d;

''Double doubleObj = new Double(doubleValue);

''byte byteValue = doubleObj.byteValue();

''int intValue = doubleObj.floatValue();

''String stringValue = doubleObj.toString();

##Primitive Numeric Defaults

- Primitive numeric variables default to 0.

e.g.

''int myInt;

''System.out.println("The value of myInt is "+myInt);

%%The value of myInt is 0

你可能感兴趣的:(#Primitive Data Types)