`
oojdon
  • 浏览: 39578 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

Java Primitive Types

 
阅读更多

Introduction

 

Not everything in Java is an object. There is a special group of data types (also known as primitive types) that will be used quite often in your programming. For performance reasons, the designers of the Java language decided to include these primitive types.

Creating an object using new isn't very efficient because new will place objects on the heap. This approach would be very costly for small and simple variables. Instead of create variables usingnew, Java can use primitive types to create automatic variables that are not references. The variables hold the value, and it's place on the stack so its much more efficient.

Java determines the size of each primitive type. These sizes do not change from one machine architecture to another (as do in most other languages). This is one of the key features of the language that makes Java so portable.

Take note that all numeric types are signed. (No unsigned types).

Finally, notice that each primitive data type also has a "wrapper" class defined for it. This means that you can create a "nonprimitive object" (using the wrapper class) on the heap (just like any other object) to represent the particular primitive type.

For example:
int i = 5;
Integer I = new Integer(i);
OR
Integer I = new Integer(5);

Data Types and Data Structures

 

Primitive Type Size Minimum Value Maximum Value Wrapper Type
char   16-bit     Unicode 0   Unicode 216-1   Character
byte   8-bit     -128   +127   Byte
short   16-bit     -215
(-32,768)
  +215-1
(32,767)
  Short
int   32-bit     -231
(-2,147,483,648)
  +231-1
(2,147,483,647)
  Integer
long   64-bit     -263
(-9,223,372,036,854,775,808)
  +263-1
(9,223,372,036,854,775,807)
  Long
float   32-bit     32-bit IEEE 754 floating-point numbers   Float
double   64-bit     64-bit IEEE 754 floating-point numbers   Double
boolean   1-bit     true or false   Boolean
void   -----     -----     -----     Void

分享到:
评论

相关推荐

    javat编程基础

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

    面向对象编程: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白皮书(英文版)

    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 ...

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

    字节短整数长Java原始类型

    面向对象编程: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):在内存中存放的是指向该数据的地址,不是数据本身;...

    《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

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

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

    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 ...

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

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

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

    Chapter 8Primitives as Typesexplores the relationship between the primitive types and objects of their corresponding wrapper classes, and how boxing and unboxing can transparently convert between ...

    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 ...

    Thinking in JAVA 4th英文版

    Special case: primitive types ....... 43 Arrays in Java .............................. 44 You never need to destroy an object .................. 45 Scoping ........................................ 45 ...

    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,...

    使用 AbstractTableModel 构建Table 在表格中添加JButton按钮

    DefaultTableCellRenderer recognizes a few primitive types, rendering them as strings, and can even display Boolean types as checkboxes. But it defaults to displaying the value returned by toString() ...

    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#语言规范 版本 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, ...

    JavaLearning

    2. Primitive Types (int, boolean) 3. Conditionals (if, else if, else) 任务 Create three seperate if, else if, and else Conditionals with each having a different System.out.println Statement in them...

    Thinking in Java 4th Edition

    Special case: primitive types ....... 43 Arrays in Java .............................. 44 You never need to destroy an object .................. 45 Scoping ........................................ 45 ...

    Scala for the Impatient 2nd (完整英文第二版 带书签)

    15.6.4 Specialization for Primitive Types 225 15.7 Annotations for Errors and Warnings 226 Exercises 227 16 XML PROCESSING A2 229 16.1 XML Literals 230 16.2 XML Nodes 230 16.3 Element Attributes 232 ...

Global site tag (gtag.js) - Google Analytics