`
DavyJones2010
  • 浏览: 148967 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Java: Primitive Types

阅读更多

Primitive Types:

1) byte:

    size: 8-Bit = 1-Byte

    range: -128~+127

    usage:

        1> The byte data type can be useful for saving memory in large arrays, where memory saving actually matters.

        2> They can also be used in place of int where their limits help to clearify your code. The fact that a variable's range is limited can serve as a form of documentation.

 

2) short:

    size: 16-Bit = 2-Byte

    range: -32768~+32767

    usage:

        1> You can use short to save memory in large arrays, in situation memory where memory savings acutally matters.

 

3) int:

    size: 32-Bit = 4-Byte

    range: -(2^31)~+(2^31-1)

 

 

4) long:

    size: 64-Bit = 8-Byte

    range: -(2^63) ~ +(2^63-1)

 

5) float:

    size: single-precision 32-Bit IEEE 754 floating point

    range: Its range of value is beyond the scope of this discussion.

    usage: Use a float if you need to save memory in large arrays of floating point numbers.

                This data type should never be used for precise values, such as currency.

                For that, you need to use the java.math.BigDecimal class instead.

 

6) double:

    size: double-precision 64-Bit IEEE 754 floating point.

    range: Its range of values is beyond the scope of this discussion.

    usage: For decimal values, this data type is generally the default choice.

                As mentioned above, this data type should never be used for precise values.

 

7) boolean:

    size: represent one-bit of information, but its size isn't precisely defined. 

    range: true/false

    usage: Use this data type for simple flags that track true/false conditions.

 

8) char:

    size: 16-Bit = 2 Byte

    range: '\u0000' or 0 inclusive ~ '\uffff' or 65535 inclusive

 

Default Values:

 

Data TypeDefault Value (for fields)
byte 0
short 0
int 0
long 0L
float 0.0f
double 0.0d
char '\u0000'
String (or any object)   null
boolean false

 

Reference Links:

1) http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

 

分享到:
评论

相关推荐

    《Pearson.Java.How.To.Program.late.objects.version.10th.Edition》 高清完整英文PDF版

    Java How to Program (Late Objects), Tenth Edition is intended for use in the Java programming course. It also serves as a useful reference and...Appendix D: Primitive Types Appendix E: Using the Debugger

    Byte-Short-Int-Long-Java-Primitive-Types:字节短整数长Java原语类型

    字节短整数长Java原始类型

    Android代码-RoboPOJOGenerator

    Supports: primitive types, multiple inner JSONArrays. Download get it and install from plugin repository or simply find it in "Preferences" -> "Plugins" -> "Browse Repositories" -> "RoboPOJOGenerator...

    面向对象编程:C++与Java比较教程 英文版

    Chapter 6 - The Primitive Types and Their Input/Output Chapter 7 - Declarations, Definitions, and Initializations Chapter 8 - Object Reference and Memory Allocation Chapter 9 - Functions and Methods ...

    javat编程基础

    java编程基础,Java primitive data types and related subjects, such as variables, constants, data types, operators, and expressions. Control statements Array String

    JAVA白皮书(英文版)

    2.1.1Primitive Data Types 2.1.2Arithmetic and Relational Operators 2.1.3Arrays 2.1.4Strings 2.1.5Multi-Level Break 2.1.6Memory Management and Garbage Collection 2.1.7The Background ...

    Effective Java 3rd edition(Effective Java第三版英文原版)附第二版

    Item 61: Prefer primitive types to boxed primitives Item 62: Avoid strings where other types are more appropriate Item 63: Beware the performance of string concatenation Item 64: Refer to objects by ...

    面向对象编程:C++与Java比较教程 英文精简版

    Chapter 6 - The Primitive Types and Their Input/Output Chapter 7 - Declarations, Definitions, and Initializations Chapter 8 - Object Reference and Memory Allocation Chapter 9 - Functions and Methods ...

    java程序设计课件

    基本数据类型(primitive types):由程序设计语言系统所定义的,不可再划分;内存大小固定,存放数据本身;与软硬件环境无关。 引用类型(reference types):在内存中存放的是指向该数据的地址,不是数据本身;...

    Practical Java(中文版(繁体+简体))

    實踐38:使用基本型別(primitive types)使代碼更快更小 130 實踐39:不要使用Enumeration或Iterator來遍歷Vector 135 實踐40:使用System.arraycopy()來複製arrays 136 實踐41:優先使用array,然後才考慮Vector和...

    java中堆(heap)和堆栈(stack)有什么区别

    一种是基本类型(primitive types),共有 8 种,即 int, short, long, byte, float, double, boolean, char(注意,并没有 string 的基本类型)。这种类型的定义是通过诸如 int a = 3; long b= 255L; 的形式来定义...

    Java语言程序设计与数据结构11版.ch6.docx

    Java语言中有多种数据类型,包括基本类型(primitive types)和引用类型(reference types)。例如,在给定的代码中,使用了long、int、double等基本类型,以及String和Scanner等引用类型。 五、输入输出(Input/...

    Thinking in JAVA 4th英文版

    Creating new data types: class ..................................... 46 Fields and methods ..................... 47 Methods, arguments, and return values ................. 48 The argument list ..........

    Java基本数据类型(动力节点java学院整理)

    Java数据类型(type)可以分为两大类:基本类型(primitive types)和引用类型(reference types)。下面是动力节点给大家整理java基本数据类型相关知识,感兴趣的朋友一起学习吧

    Addison.Wesley.The.Java.Programming.Language.4th.Edition.Aug.2005.chm

    Chapter 10Control Flowdescribes how control statements direct the order of statement execution. <br>Chapter 11Generic Typesdescribes generic types: how they are written and used, their power, and ...

    jna-4.2.2 官方原版下载

    Automatic mapping from Java to native functions, with simple mappings for all primitive data types Runs on most platforms which support Java Automatic conversion between C and Java strings, with ...

    程序语言设计原理习题解答

    6.2 Primitive Data Types 253 6.3 Character String Types 256 History Note 258 6.4 User-Defined Ordinal Types 261 6.5 Array Types 266 History Note 267 History Note 269 6.6 Associative ...

    JavaScript Data Structures and Algorithms

    the basic JavaScript foundations, such as primitive objects and types. Then, this book covers implementations and algorithms for fundamental data structures such as linked lists, stacks, trees, heaps,...

    Thinking in Java 4th Edition

    Creating new data types: class ..................................... 46 Fields and methods ..................... 47 Methods, arguments, and return values ................. 48 The argument list ..........

    C#语言规范 版本 4.0(English)

    All C# types, including primitive types such as int and double, inherit from a single root object type. Thus, all types share a set of common operations, and values of any type can be stored, ...

Global site tag (gtag.js) - Google Analytics