Java is a strongly typed language, that means all the variables must first be declared before we can use it. Declaring a variable in java includes type and name with optional value assignment. If no value is assigned, the variable holds the default value. For primitive types, there are different default values but it’s always NULL for Object data types.
Java是一种强类型语言,这意味着在使用它之前必须先声明所有变量。 在Java中声明变量包括类型和名称以及可选的值分配。 如果未分配任何值,则该变量将保留默认值。 对于基本类型,有不同的默认值,但对于Object数据类型,它始终为NULL。
Java原始数据类型
(
Java Primitive Data Types
)
Java programming language contains eight primitive data types. Four primitive data types are for integer values – byte, short, int and long. Two primitive data types are for floating type decimal values – float and double. One is for characters – char and one is for the condition – boolean. Java programming language also comes with
Wrapper classes
for all these primitive data types.
Java编程语言包含八种原始数据类型。 四种原始数据类型用于整数值–字节,短,整数和长整数。 浮点型十进制值有两种原始数据类型-浮点和双精度。 一种是字符(char),另一种是条件(boolean)。
包装器类还
为所有这些原始数据类型提供了Java编程语言。
Below table shows all these primitive data types with size, range, default value and different ways to assign them.
下表显示了所有这些原始数据类型,包括大小,范围,默认值和不同的分配方式。
Type
|
Size
|
Range
|
Default Value
|
Examples
|
boolean
|
1 bit
|
NA
|
false
|
boolean bool = true;
|
char
|
16 bits
|
Unicode Characters
|
‘\u0000’ or 0, which
is nothing but a
white space
|
char c = ‘A’;
char c = ‘\u0041’;
char c = 65;
char c = ‘\t’;
|
byte
|
8 bits
|
[-128,127] or
[-2^7 to 2^7-1]
|
0
|
byte b = 10;
byte b = 0b010;
|
short
|
16 bits
|
[-32768,32767]
|
0
|
short s = 32;
short s = ‘A’;
|
int
|
32 bits
|
[-2147483648,2147483647]
|
0
|
int i = 10;
int i = ‘A’;
|
long
|
64 bits
|
[-2^63,2^63-1]
|
0
|
long l = 3200L;
long l = 3200;
|
float
|
32 bits
|
[-3.4E38, 3.4E38]
|
0.0f
|
float f = (float) 12.34;
float f = 12.34f;
|
double
|
64 bits
|
[-1.7E308, 1.7E308]
|
0.0
|
double d = 12.34;
|
类型
|
尺寸
|
范围
|
默认值
|
例子
|
布尔值
|
1位
|
不适用
|
假
|
布尔布尔= true;
|
烧焦
|
16位
|
Unicode字符
|
'\ u0000'或0,即
只是一个
空格
|
char c ='A';
char c ='\ u0041';
字符c = 65;
char c ='\ t';
|
字节
|
8位
|
[-128,127]或
[-2 ^ 7至2 ^ 7-1]
|
0
|
字节b = 10;
字节b = 0b010;
|
短
|
16位
|
[-32768,32767]
|
0
|
短s = 32;
short s ='A';
|
整型
|
32位
|
[-2147483648,2147483647]
|
0
|
整数i = 10;
int i ='A';
|
长
|
64位
|
[-2 ^ 63,2 ^ 63-1]
|
0
|
长l = 3200L;
长l = 3200;
|
浮动
|
32位
|
[-3.4E38、3.4E38]
|
0.0分
|
浮点数f =(float)12.34;
浮点f = 12.34f;
|
双
|
64位
|
[-1.7E308、1.7E308]
|
0.0
|
双d = 12.34;
|
Below is a simple java program showing different ways to declare primitive data types – look closely for char and what happens when an int is converted to byte through explicit casting.
下面是一个简单的Java程序,显示了声明原始数据类型的不同方法-仔细查看char以及将int通过显式转换转换为字节时发生的情况。
byte b1 = (byte) 200;
System.out.println(b1); // prints -56
//<0...>_11001000 (int), converted to 11001000 (byte) by stripping leading 24 bits
// since left most bit is 1, we need to find the value
// Ones complement 11001000 -1 = 11000111
//invert digits 00111000 i.e 56, hence printing -56
b1 = (byte) 0b11001000;
System.out.println(b1); //prints -56
byte b2 = (byte) 320; //256+64 i.e 00000000_00000000_00000001_01000000, byte 01000000
//since leading bit is 0, nothing is required to determine value
System.out.println(b2); //prints 64
short s = 32;
short s1 = 'A'; //implicit char to short conversion
System.out.println(s1); //prints 65
int i = 'A';
System.out.println(i); //prints 65
long l = 3200L;
long l1 = 3200;
float f = 12.34f;
//Examples
byte x, y = 1, z = 2;
x = (byte) (y + z);
在数字文字中使用下划线
(
Using Underscore in Numeric Literals
)
From Java 7 onwards, we can use underscore in numeric literals such as
long ccNum = 1234_5678_9101_1121L;
. You can read more about them at
Underscores in Numeric Literals
.
从Java 7开始,我们可以在数字文字中使用下划线,例如
long ccNum = 1234_5678_9101_1121L;
。 您可以
在“数字文字”
中的“
下划线”中
阅读有关它们的更多信息。
二进制文字
(
Binary Literals
)
From Java 7 onwards, the integral types (byte, short, int, and long) can also be expressed using the binary number system. We need to prefix the number with
0b
or
0B
. Some of the examples are;
从Java 7开始,整数类型(字节,短型,整型和长型)也可以使用二进制数字系统表示。 我们需要给数字加上
0b
或
0B
前缀。 一些例子是;
// A 16-bit 'short' value:
short aShort = (short)0b1010000101000101;
That’s all for primitive data types in java. Please look into the program carefully to understand what happens when we perform casting.
这就是Java中原始数据类型的全部内容。 请仔细查看程序,以了解执行铸造时会发生什么。
翻译自:
https://www.journaldev.com/6431/java-data-types-primitives-and-binary-literals
非基元类型数据结构
非基元类型数据结构Java is a strongly typed language, that means all the variables must first be declared before we can use it. Declaring a variable in java includes type and name with optional value assignment...
在C#2.0之前,对于
值
类型
来讲,我们是没法把一个null
值
赋给一个
值
变量的,那时,null只专属于引用
类型
,猜想Null当时的设计就是针对引用
类型
的,把null赋给引用
类型
变量时,表明变量不引用任何堆上的对象。即指针为空指针。
由于这种设计,在C#2.0之前,程序员往往面对一个很尴尬的问题,在实际中,我们需要
值
类型
能够为null的情况,最常见的问题体现在数据库设计中,例如一个物料表
Avoid using non-primitive value as key, use string/number value instead.
避免使用
非
基元
值
作为键,而是使用字符串/数字
值
。
<tr v-for="goodsitem in goodsList" :key="goodsitem">
//v-for(item,index)中item是数组或对象,而key的
值
不能是对象
//循环时将index作为key的
值
<tr v-for="(goodsite
5.1.
基元
类型
和FCL
类型
编译器直接支持的
类型
是
基元
类型
,int ,long,string等
FCL:内置
类型
一个
基元
类型
必然映射一个FCL
类型
,不然你的代码怎么执行。
int->int32, long->int64 错误认识: int 在32位机器上是32位整数,64位置机器代表64位整数,这是错误的认识。
还有还多东西感觉用不上就不用记了,实际生产几乎用不到
定义:表示一系列数据“有序排列”的集合。
下标:在PHP中,数组的下标可以使用整数或字符串(整数下标叫做“索引号”,字符串下标叫做“键名”),在php的报错系统中被叫做“index”或“offset”。(利用下标可获得相应数据包括数组(在多维数组中))
数组遍历:
foreach(数组名 as 下标标量$k =>
值
变量$v){ /...
当源
类型
与目标
类型
不是
基元
类型
时CLR便不能自己进行编译转换。
下例为Rational(有理数
类型
)与string,int的转化。
转换操作符是将对象从一个
类型
转化成另一个
类型
的方法。可以使用特殊语法来定义装换操作符方法。
CLR要求转换操作符的重载方法必须是public 和static方法。c#要求参数
类型
和返回
类型
二者必有其一与定义转换方法的
类型
相同。
//定义只有一个参数的公共构...
1. 第一章课后题第11题 (第四版13题 )
What is the principal difference betweenconnectionless communication and connection-oriented communication?
Connection-orientedcommunication has three phases. In the