美文网首页
#Primitive Data Types

#Primitive Data Types

作者: 有栖川蛍 | 来源:发表于2016-10-04 10:28 被阅读0次

#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

      本文链接:https://www.haomeiwen.com/subject/uawjyttx.html