java的原生数据类型_Java中的8种原生数据类型(Primitive Data Types)分析

八种数据类型

类型 int short long byte float double char boolean

字节数 4 2 8 1 4 8 4 JVM相关

大小 -2147483648~2147483647 -32768~32767 -9223372036854775808~9223372036854775807 -128~127 ±3.40282347E+38F ±1.79769313486231570E+308

tip:八种类型我是这样记忆的:boolean,char是我们常用的,double是双精度浮点小数,有双就有单 : float是单精度浮点小数,int是一个坐标,short比int短,long比int长,byte是整数的最小单位.

byte: The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. They can also be used in place of int where their limits help to clarify your code; the fact that a variable's range is limited can serve as a form of documentation.

byte数据类型是一个8-bit有符号的二进制补码整数。取值范围:【-128,127】,当内存比较重要的时候:比如超大数组的情况。

short: The short data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As with byte, the same guidelines apply: you can use a short to save memory in large arrays, in situations where the memory savings actually matters.

short是一个16-bit 的二进制补码整数,取值范围:[-32768,32767]。同上文byte.

int: By default, the int data type is a 32-bit signed two's complement integer, which has a minimum value of -231 and a maximum value of 231-1. In Java SE 8 and later, you can use the int data type to represent an unsigned 32-bit integer, which has a minimum value of 0 and a maximum value of 232-1. Use the Integer class to use int data type as an unsigned integer. See the section The Number Classes for more information. Static methods like compareUnsigned, divideUnsigned etc have been added to the Integer class to support the arithmetic operations for unsigned integers.

默认情况下,int是32-bit的二进制补码整数,取值范围是:[-2^31,2^31-1],在JavaSE8以后,你可以使用int数据类型去展现一个无符号为的32-bit的值(取值范围:[0,2^32 - 1]),使用Integer类去操作无符号为的Integer,具体情况请参考Number类。包含compareUnsigned, divideUnsigned等静态方法.

long: The long data type is a 64-bit two's complement integer. The signed long has a minimum value of -263 and a maximum value of 263-1. In Java SE 8 and later, you can use the long data type to represent an unsigned 64-bit long, which has a minimum value of 0 and a maximum value of 264-1. Use this data type when you need a range of values wider than those provided by int. The Long class also contains methods like compareUnsigned, divideUnsigned etc to support arithmetic operations for unsigned long.

几乎同int,除了不包含compareUnsigned, divideUnsigned等静态方法。

float: The float data type is a single-precision 32-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in the Floating-Point Types, Formats, and Values section of the Java Language Specification. As with the recommendations for byte and short, use a float (instead of double) 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 will need to use the java.math.BigDecimal class instead. Numbers and Strings covers BigDecimal and other useful classes provided by the Java platform.

float是单精度的浮点小数.存在的意义类似于short,省内存.

double: The double data type is a double-precision 64-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in the Floating-Point Types, Formats, and Values section of the Java Language Specification. For decimal values, this data type is generally the default choice. As mentioned above, this data type should never be used for precise values, such as currency.

double是我们在十进制小数情况下的默认选择,但是注意,不要把他当做通用的类.

boolean: The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its "size" isn't something that's precisely defined.

注意:boolean的内存大小是和JVM有关的。

char: The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).,四个字节.

char四个字节.

最后:Java没有任何无符号(unsigned)形式的int,long,short或byte类型.

来源:51CTO

作者:wx5b9bb6400376a

链接:https://blog.51cto.com/13971202/2175643

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/356850.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

史上最全的SpringMVC学习笔记

SpringMVC学习笔记---- 一、SpringMVC基础入门&#xff0c;创建一个HelloWorld程序 1.首先&#xff0c;导入SpringMVC需要的jar包。 2.添加Web.xml配置文件中关于SpringMVC的配置<!--configure the setting of springmvcDispatcherServlet and configure the mapping-->&…

python 进程池 等待数量_【2020Python修炼记】python并发编程(六)补充—进程池和线程池...

1、2、 为啥要有 进程池和线程池进程池来控制进程数目&#xff0c;比如httpd的进程模式&#xff0c;规定最小进程数和最大进程数3、创建进程池的类pool如果指定numprocess为3&#xff0c;则进程池会从无到有创建三个进程&#xff0c;然后自始至终使用这三个进程去执行所有任务&…

shader weaver_Oracle通过邀请Weaver和Chin推动JavaFX向前发展

shader weaver昨天&#xff0c;我发布了愚人节帖子&#xff0c;内容涉及加入NASA协助探索红色大行星。 那篇文章与事实相距不远……美国宇航局开发的技术的所有细节都是100&#xff05;准确的。 哎呀&#xff0c;即使我辞职也是事实&#xff01; 唯一不正确的部分是我将加入的公…

mysql快速上手3

上一章给大家说的是数据库的视图&#xff0c;存储过程等等操作&#xff0c;这章主要讲索引&#xff0c;以及索引注意事项&#xff0c;如果想看前面的文章&#xff0c;url如下&#xff1a; mysql快速上手1mysql快速上手2索引简介 索引是对数据库表中一个或多个列&#xff08;例如…

python图像锐化_Python图像处理介绍--图像模糊与锐化

欢迎关注 “小白玩转Python”&#xff0c;发现更多 “有趣”引言在之前的文章中&#xff0c;我们讨论了边缘检测内核。在本文我们将讨论如何在图像上应用模糊与锐化内核&#xff0c;将这些内核应用到彩色图像上&#xff0c;同时保留核心图像。一如既往&#xff0c;我们从导入所…

看一下CDI 2.0 EDR1

CDI是最近对Java EE最好的补充之一。 该观点在用户和集成商之间广泛共享。 当前版本的CDI 1.2于2014年4月发布。现在&#xff0c;在2015年中期&#xff0c;我们将面对CDI 2.0规范的早期草案。 CDI 2.0将在Java 8和更高版本上运行。 最终版本计划于2016年发布&#xff0c;该路线…

redis key设计技巧

1: 把表名转换为key前缀 如, user: 2: 第2段放置用于区分区key的字段--对应mysql中的主键的列名,如userid 3: 第3段放置主键值,如2,3,4...., a , b ,c 4: 第4段,写要存储的列名 用户表 user , 转换为key-value存储 userid username passworde email 9 Lisi 1111111 li…

python编程游戏代码 游戏人物如何升级_如何玩游戏提高python编程技能?

笔者公众号&#xff1a;技术杂学铺Python Challenge是首个谜语编程网站。挑战者需要连续挑战33个需要编程才能解开的谜题以锻炼自己的编程能力。该网站建立于2005年&#xff0c;至今已经有三百多万位访客浏览并尝试解决该网站的谜题。python challenge 官网虽然网站建立的年代比…

Eclipse配置初始化(自用)

以上都是性能调优的配置&#xff0c;下面是其他常用的配置和优化 设置utf-8编码 window -> preferences -> General -> workplace中text file encoding改为utf-8 设置properties文件编码window -> preferences -> General -> Content Types —> Text —&g…

java bits_一段关于JAVA程序升级的问题(Changing bits)

展开全部import java.awt.Color;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.BorderFactory;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JTextField;import javax.…

hibernate脏数据_Hibernate性能提示:脏收集效果

hibernate脏数据在使用Hibernate作为ORM开发服务器和嵌入式应用程序8年后&#xff0c;我全力以赴地寻求提高Hibernate性能的解决方案&#xff0c;阅读博客和参加会议&#xff0c;我决定与您分享在这些年中获得的知识。 这是更多新帖子中的第一篇&#xff1a; 去年&#xff0c;…

有关struts2中用到 js 总结

1.js中取Struts2中的栈里的值 var current "${currentPage}"; 2.js 如何提交执行提交url连接 &#xff0c;以及 Struts中的url如何如何写 var current "${currentPage}"; location.href"showSeparatePageGoods.action?currentPage"current&q…

java合并两个有序链表_JS实现的合并两个有序链表算法示例

本文实例讲述了JS实现的合并两个有序链表算法。分享给大家供大家参考&#xff0c;具体如下&#xff1a;将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。示例&#xff1a;输入&#xff1a;1->2->4, 1->3->4输出&…

外墙设计模式示例

本文是我们名为“ Java设计模式 ”的学院课程的一部分。 在本课程中&#xff0c;您将深入研究大量的设计模式&#xff0c;并了解如何在Java中实现和利用它们。 您将了解模式如此重要的原因&#xff0c;并了解何时以及如何应用模式中的每一个。 在这里查看 &#xff01; 目录 …

8.25小结

1.导出csv文件 后台导出&#xff1a;CSVUtils工具类&#xff1a; /*** * CSV文件导出工具类* * author* reviewer*/ public class CSVUtils {public static File createCSVFile(List<Object> head, List<List<Object>>dataList, String outPutPath, String f…

java 监控 native 内存_JVM NativeMemoryTracking 分析堆外内存泄露

Native Memory Tracking (NMT) 是Hotspot VM用来分析VM内部内存使用情况的一个功能。我们可以利用jcmd(jdk自带)这个工具来访问NMT的数据。NMT介绍工欲善其事必先利其器&#xff0c;我们先把相关需要的配置和工具介绍清楚&#xff0c;再通过例子来看看具体如何使用NMT。打开NMT…

Charles 从入门到精通

目录与版权 转载请保留顶部的 Charles 中国特惠内容&#xff0c;本文的内容主要包括&#xff1a; Charles 的简介如何安装 Charles将 Charles 设置成系统代理Charles 主界面介绍过滤网络请求截取 iPhone 上的网络封包截取 Https 通讯信息模拟慢速网络修改网络请求内容给服务器做…

javafx11 最佳实践_JavaFX移动应用程序最佳实践,第1部分

javafx11 最佳实践到现在为止&#xff0c;所有对JavaFX感兴趣的人都会知道&#xff0c;JavaFX Mobile发行了不久 前。 可以肯定的是&#xff0c;这真是令人难以置信。 我感到非常筋疲力尽&#xff0c;在发行期间我什至没有精力去写博客…… 但是到目前为止&#xff0c;我感到很…

java 批量验证_正则表达式批量验证函数

正则表达式批量验证函数function checkData(){//判断数据的正确性var idSpans new Array();idSpans[0] new Array("item_4","^[\\s\\S]{1,16}$","productName","商机名称应在1-16字以内","",true); idSpans[1] new Array(…

css3制作炫酷导航栏效果 转

今天主要利用hover选择器。鼠标滑过查看效果。 一。普通导航栏 HomeContentServiceTeamContact对于这种普通的导航栏&#xff0c;只是鼠标滑过的时候颜色会变&#xff0c;所以思路变得很简单。 &#xff08;1&#xff09;使用ul标签布局 &#xff08;2&#xff09;鼠标经过事件…