java数据类型

Java is a completely object-oriented programming language which provides a lot of different type of features. Primitive data types are some of them. Java provides basic or primitive data types like integer, string, logical true and false, etc. In this tutorial, we will learn the Java Primitive Datatypes.

Java是一种完全面向对象的编程语言,它提供了许多不同类型的功能。 原始数据类型就是其中一些。 Java提供了基本或原始数据类型,例如整数,字符串,逻辑对与错等。在本教程中,我们将学习Java原始数据类型。

原始数据类型 (Primitive Data Types)

Most of the programming languages provide the primitive data type. Java also provides a primitive data type as a complete and popular programming language. Primitive means basic or non-complex data type simply storing a single type of data. Integers, floating-point numbers, strings, characters are named as primitive because they hold a single type of data. Class, Structs, Objects are referred to as nonprimitive data types.

大多数编程语言都提供原始数据类型。 Java还提供一种原始数据类型,作为一种完整且流行的编程语言。 原始表示简单存储单一数据类型的基本或非复杂数据类型。 整数,浮点数,字符串,字符被称为原始,因为它们保存一种类型的数据。 类,结构,对象称为非原始数据类型。

Primitive Data Types
原始数据类型

复合或非原始类型(Composite or Non-Primitive Types)

Composite or Non-primitive types are used to store complex data which is generally multiple types in a single type like Class, Struct, Objects, etc. For example, a class which has members like name, age, etc is a non-primitive type. But in some cases, non-primitive types can contain other non-primitive types.

复合或非原始类型用于存储复杂数据,这些数据通常是单个类型(例如Class,Struct,Objects等)中的多种类型。例如,具有诸如name,age等成员的类是非原始类型。 但是在某些情况下,非原始类型可以包含其他非原始类型。

号码类型 (Number Types)

Java provides 6 different number types to represent a different type of numbers. As general there is two main number type which is integer and floating-point but there are also derivatives.

Java提供了6种不同的数字类型来表示不同类型的数字。 通常,有两种主要的数字类型,它们是整数和浮点数,但也有导数。

整数类型 (Integer Type)

An integer is used to store integers and requires 4 bytes in memory even the number do not require it. An integer can be between  -2147483648 to 2147483647 which is generally enough for most of the scenarios and cases. int keyword is used to define the integer type in Java. Here are some examples of Java integer data type.

整数用于存储整数,并且在内存中需要4个字节,即使该数字不需要它也是如此。 整数可以在-2147483648至2147483647之间,对于大多数情况和情况而言,通常就足够了。 int关键字用于在Java中定义整数类型。 这是Java整数数据类型的一些示例。

int myNum = 100000;System.out.println(myNum);

字节类型 (Byte Type)

If we want to store very little numbers like 50, 7, we can use the byte data type. The byte data type can store numbers between 128 and -127 . Byte data type uses 1 byte in memory. byte keyword is used to define the byte data type.

如果我们要存储很少的数字(例如50、7),则可以使用字节数据类型。 字节数据类型可以存储128到-127之间的数字。 字节数据类型在内存中使用1个字节。 byte关键字用于定义字节数据类型。

int myByte= 126; System.out.println(myByte);

短型 (Short Type)

As integer can store a range of number but in some cases, we may need to store some little numbers like 598, 15290, etc. Short type can store numbers between -32768 to 32767. In order to define the short type short keyword is used. The short data type can be converted into other number types like integer, long, floating-point, double without a problem.

由于整数可以存储一定范围的数字,但是在某些情况下,我们可能需要存储一些小数字,例如598、15290等。short类型可以存储-32768到32767之间的数字。为了定义short类型,使用了short关键字。 短数据类型可以转换为其他数字类型,例如整数,长整数,浮点数,双精度数而没有问题。

short myNum = 5000;System.out.println(myNum);

长型 (Long Type)

Well, integer type provides a long-range to define numbers. But in some cases, this may not enough for our usage and calculations. Long type can store numbers between -9223372036854775808 to 9223372036854775807. This may be very useful scientific or economy use cases. Long type can be defined with the long keyword. Long type can be converted to integer and short if it is in the range of these types if not we will see some error

好吧,整数类型提供了一个远程定义数字的方法。 但是在某些情况下,这可能不足以用于我们的使用和计算。 长型可以存储在-9223372036854775808至9223372036854775807之间的数字。这可能是非常有用的科学或经济用例。 可以使用long关键字定义long类型。 长整型可以转换为整数,短整型(如果不在这些类型的范围内),我们将看到一些错误

long myNum = 15000000000L;System.out.println(myNum);

浮点数类型 (Floating Number Types)

Integers are useful but some calculations require some floating-point numbers. There are two types of floating-point numbers in the Java programming language. The only difference is the precision of the types.

整数很有用,但某些计算需要一些浮点数。 Java编程语言中有两种类型的浮点数。 唯一的区别是类型的精度。

.u8e463d6e528ecd6b60e65062f5fcc563 , .u8e463d6e528ecd6b60e65062f5fcc563 .postImageUrl , .u8e463d6e528ecd6b60e65062f5fcc563 .centered-text-area { min-height: 80px; position: relative; } .u8e463d6e528ecd6b60e65062f5fcc563 , .u8e463d6e528ecd6b60e65062f5fcc563:hover , .u8e463d6e528ecd6b60e65062f5fcc563:visited , .u8e463d6e528ecd6b60e65062f5fcc563:active { border:0!important; } .u8e463d6e528ecd6b60e65062f5fcc563 .clearfix:after { content: ""; display: table; clear: both; } .u8e463d6e528ecd6b60e65062f5fcc563 { display: block; transition: background-color 250ms; webkit-transition: background-color 250ms; width: 100%; opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #ECF0F1; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -o-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); } .u8e463d6e528ecd6b60e65062f5fcc563:active , .u8e463d6e528ecd6b60e65062f5fcc563:hover { opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #D35400; } .u8e463d6e528ecd6b60e65062f5fcc563 .centered-text-area { width: 100%; position: relative; } .u8e463d6e528ecd6b60e65062f5fcc563 .ctaText { border-bottom: 0 solid #fff; color: #3498DB; font-size: 16px; font-weight: bold; margin: 0; padding: 0; text-decoration: underline; } .u8e463d6e528ecd6b60e65062f5fcc563 .postTitle { color: #27AE60; font-size: 16px; font-weight: 600; margin: 0; padding: 0; width: 100%; } .u8e463d6e528ecd6b60e65062f5fcc563 .ctaButton { background-color: #e6e6e6!important; color: #3498DB; border: none; border-radius: 3px; box-shadow: none; font-size: 14px; font-weight: bold; line-height: 26px; moz-border-radius: 3px; text-align: center; text-decoration: none; text-shadow: none; width: 80px; min-height: 80px; background: url(https://www.poftut.com/wp-content/plugins/intelly-related-posts/assets/images/simple-arrow.png)no-repeat; position: absolute; right: 0; top: 0; } .u8e463d6e528ecd6b60e65062f5fcc563:hover .ctaButton { background-color: #E67E22!important; } .u8e463d6e528ecd6b60e65062f5fcc563 .centered-text { display: table; height: 80px; padding-left: 18px; top: 0; } .u8e463d6e528ecd6b60e65062f5fcc563 .u8e463d6e528ecd6b60e65062f5fcc563-content { display: table-cell; margin: 0; padding: 0; padding-right: 108px; position: relative; vertical-align: middle; width: 100%; } .u8e463d6e528ecd6b60e65062f5fcc563:after { content: ""; display: block; clear: both; }

LEARN MORE  Php - Boolean Variable Types , True, False

.u8e463d6e528ecd6b60e65062f5fcc563 , .u8e463d6e528ecd6b60e65062f5fcc563 .postImageUrl , .u8e463d6e528ecd6b60e65062f5fcc563 .centered-text-area { min-height: 80px; position: relative; } .u8e463d6e528ecd6b60e65062f5fcc563 , .u8e463d6e528ecd6b60e65062f5fcc563:hover , .u8e463d6e528ecd6b60e65062f5fcc563:visited , .u8e463d6e528ecd6b60e65062f5fcc563:active { border:0!important; } .u8e463d6e528ecd6b60e65062f5fcc563 .clearfix:after { content: ""; display: table; clear: both; } .u8e463d6e528ecd6b60e65062f5fcc563 { display: block; transition: background-color 250ms; webkit-transition: background-color 250ms; width: 100%; opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #ECF0F1; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -o-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.17); } .u8e463d6e528ecd6b60e65062f5fcc563:active , .u8e463d6e528ecd6b60e65062f5fcc563:hover { opacity: 1; transition: opacity 250ms; webkit-transition: opacity 250ms; background-color: #D35400; } .u8e463d6e528ecd6b60e65062f5fcc563 .centered-text-area { width: 100%; position: relative; } .u8e463d6e528ecd6b60e65062f5fcc563 .ctaText { border-bottom: 0 solid #fff; color: #3498DB; font-size: 16px; font-weight: bold; margin: 0; padding: 0; text-decoration: underline; } .u8e463d6e528ecd6b60e65062f5fcc563 .postTitle { color: #27AE60; font-size: 16px; font-weight: 600; margin: 0; padding: 0; width: 100%; } .u8e463d6e528ecd6b60e65062f5fcc563 .ctaButton { background-color: #e6e6e6!important; color: #3498DB; border: none; border-radius: 3px; box-shadow: none; font-size: 14px; font-weight: bold; line-height: 26px; moz-border-radius: 3px; text-align: center; text-decoration: none; text-shadow: none; width: 80px; min-height: 80px; background: url(https://www.poftut.com/wp-content/plugins/intelly-related-posts/assets/images/simple-arrow.png)no-repeat; position: absolute; right: 0; top: 0; } .u8e463d6e528ecd6b60e65062f5fcc563:hover .ctaButton { background-color: #E67E22!important; } .u8e463d6e528ecd6b60e65062f5fcc563 .centered-text { display: table; height: 80px; padding-left: 18px; top: 0; } .u8e463d6e528ecd6b60e65062f5fcc563 .u8e463d6e528ecd6b60e65062f5fcc563-content { display: table-cell; margin: 0; padding: 0; padding-right: 108px; position: relative; vertical-align: middle; width: 100%; } .u8e463d6e528ecd6b60e65062f5fcc563:after { content: ""; display: block; clear: both; }

了解更多信息-布尔变量类型,True,False

浮点类型 (Floating Point Type)

Floating point type is the first floating-point type. We can use float in order to define the floating-point type. Floating type store floating numbers between 3.4e−038 to 3.4e+038. We can also use f postfix at the end of the float value in order to specify it is a floating-point number.

浮点类型是第一个浮点类型。 我们可以使用float来定义浮点类型。 浮点类型存储浮点数在3.4e-038到3.4e + 038之间。 我们还可以在浮点值的末尾使用f后缀,以指定它是浮点数。

float myNum = 5.75f;float percentage = 10.8;System.out.println(myNum);

双重型 (Double Type)

In some cases, the floating-point type may not be enough to store given floating-point number. Double can store numbers between 1.7e−308 to 1.7e+308 . We will use double keyword to define a double data type. A double type variable requires 8-byte memory which is expensive and should be used carefully. We can postfix or end d to the end of the floating data to explicitly specify it is double.

在某些情况下,浮点类型可能不足以存储给定的浮点数。 Double可以存储1.7e−308到1.7e + 308之间的数字。 我们将使用double关键字定义double数据类型。 双精度型变量需要8字节的内存,这很昂贵,应谨慎使用。 我们可以将fix或end d附加到浮动数据的末尾,以明确指定其为double。

double myNum = 19.99d;System.out.println(myNum);

布尔型 (Boolean Type)

Java can store logical values false and true. Boolean type is used to store logical values. We will use boolean keyword to define a logical value and true and false keyword to set value.

Java可以存储逻辑值falsetrue 。 布尔类型用于存储逻辑值。 我们将使用boolean关键字定义逻辑值,并使用truefalse关键字设置值。

boolean isPoftutFun = true;boolean isSaladTasty = false;System.out.println(isPoftutFun );     // Outputs trueSystem.out.println(isSaladTasty );   // Outputs false

角色类型(Character Type)

The character type is used to store a single character. char keyword is used to define the character type. Character values generally surrounded by the single quotes but double quotes can be also used. Char variable can be created by providing the character directly like 'A' or with its ASCII value like 65.

字符类型用于存储单个字符。 char关键字用于定义字符类型。 字符值通常用单引号引起来,但也可以使用双引号。 可以通过直接提供字符(例如'A'或提供其ASCII值(例如65来创建Char变量。

char grade = 'A';System.out.println(myGrade);char d = 68, e = 69, f = 70;System.out.println(d);System.out.println(e);System.out.println(f);

非原始类型字符串 (Non-Primitive Type String)

The string is not a primitive type and one of the examples to non-primitive data types. The string data type is used to store multiple characters or a text in a single variable. We can also define a single array of characters. The string variable data can be defined inside double quotes or single quotes.

该字符串不是原始类型,并且是非原始数据类型的示例之一。 字符串数据类型用于在单个变量中存储多个字符或文本。 我们还可以定义单个字符数组。 可以在双引号或单引号内定义字符串变量数据。

String greeting = "Hello Poftut";System.out.println(greeting);

翻译自: https://www.poftut.com/java-data-types/

java数据类型

java数据类型_Java数据类型相关推荐

  1. java 高级数据类型_java 数据类型(上):分类

    java 数据类型有两种,一是基本数据类型,二是引用数据类型 一:基本数据类型 基本数据类型 有8种   布尔型(boolean),字节型(byte),字符型(char),短整型(short),整型( ...

  2. java怎么判断数据类型_Java 数据类型及其判断

    一.Java中的数据类型,可分为两类: 1.基本数据类型,也称原始数据类型: byte.short.char.int.long.float.double.boolean它们之间的比较,应该用双等号(= ...

  3. java数据类型_java 数据类型

    什么是数据类型 百度上说 数据类型是:数据类型在数据结构中的定义是一个值的集合以及定义在这个值集上的一组操作. 简单理解 : Java对数据进行了分类,存在不同的类型,这些类型就被称为数据类型. 数据 ...

  4. java怎么改变数据类型_java数据类型之间的转换,是怎么回事啊? - 收获啦

    1.数据类型的分类 2.比较数据类型之间的字节大小 1字节=8位 . 3.转换中的知识点 *java中整数类型默认的int类型:小数类型默认的double: *String的字符串转化为char类型时 ...

  5. java 扩展数据类型_java数据类型及其拓展

    Java 数据类型及其拓展 数据类型 1. 整数 int num1 = 10; //最常用的整数数据类型 byte nmu2 = 20; short num3 = 30; long num4 = 30 ...

  6. java 分析数据类型_Java数据类型分析

    Java的简单数据讲解列表以下:编程 int:int为整数类型,存储的时候,用4个字节存储,范围为-2,147,483,648到2,147,483,647,在变量初始化的时候,int类型的默认值为0. ...

  7. java 字长_java数据类型及其字长 | 学步园

    数据类型 大小 范围 默认值 byte(字节) 8 -128 - 127 0 shot(短整型) 16 -32768 - 32768 0 int(整型) 32 -2147483648-21474836 ...

  8. java p代表哪种数据类型_java数据类型(八种基本数据类型+三种引用类型)

    1.整型 类型           占用字节                                        取值范围 byte                  1           ...

  9. java 接口数据类型_Java 数据类型(中): 抽象类与接口

    抽象类和接口都是java对事物对象抽象的机制,是多态性的表现.在某些时候它们还可以互换,其实它们还是有区别的. 1,抽象类(abstract class):对某些对象的抽象描述的类(对事物对象行为方法 ...

最新文章

  1. 【MATLAB】三维图形的绘制mesh
  2. 研究生:我们的任务是把导师培养成院士
  3. dbus-launch(转)
  4. InnoDB的MVCC如何解决幻读
  5. 因知足常乐,30以后迷惑
  6. linux java javac版本_linux下java 和 javac version 不一致问题
  7. Winform中使用mysqldump实现选择部分表定期备份mysql数据库
  8. lightning接口_苹果手机接口未来将和安卓手机统一——欧盟通过正式决议
  9. CentOS服务器上部署 oracle10gr2
  10. NB-IoT(7)---开发环境搭建及模组驱动开发
  11. Android Studio for Experts(Android Dev Summit2015)
  12. python有趣的代码-python有趣的一行代码
  13. vue 调用移动录像_vue调用摄像头拍照 (移动)2020-11-18
  14. Lintcode14 First Position of Target Solution 题解
  15. 小强的HTML5移动开发之路(20)——HTML5 Web SQL Database
  16. Oracle 临时表详解(temporary table)
  17. 盘点前端开发常用的几款编辑器
  18. 2019年那些成年人的崩溃瞬间,看着看着就哭了
  19. 【XSS漏洞-06】XSS漏洞利用案例(浏览器劫持、会话劫持、GetShell)—基于神器beEF
  20. matlab 为双y轴加标签,[转载]matlab双y轴添加误差棒(转载)

热门文章

  1. 端点检测(VAD)技术
  2. 【计算机网络】虚拟IP原理
  3. Hbase数据库与传统数据库的比较
  4. python——赋值
  5. 【Axure基础教程】第17张 设置不透明度
  6. C语言strstr()函数用法-字符串查找
  7. 中山大学新华学院计算机,中山大学新华学院信息科学学院电子信息科学与技术、计算机科学与技术、软件...
  8. react学习—ref Hook
  9. 【C语言--斐波拉契数列】
  10. Mac下的spotlight无法搜索本地资源的解决办法