#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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容