Java中的数据类型和文字有什么区别?

时间:2022-06-05 22:35:01

What is the difference between data types and literals in Java?

Java中的数据类型和文字有什么区别?

11 个解决方案

#1


43  

From Java Data types tutorial

从Java数据类型教程

Data types :

数据类型:

Primitive types are special data types built into the language; they are not objects created from a class

原始类型是语言中内置的特殊数据类型;它们不是从类创建的对象

Literal :

A Literal is the source code representation of a fixed value; literals are represented directly in your code without requiring computation

Literal是固定值的源代码表示;文字直接在代码中表示,无需计算

boolean result = true;

boolean - is data type
true - is literal

#2


18  

 String string = "Hello World";
 <  1 > <  2 >   <     3     >

1 is a data type, 2 a variable name, 3 a (String) literal

1是数据类型,2是变量名,3是(String)文字

From the JLS:

来自JLS:

A literal is the source code representation of a value of a primitive type [like 1, true, 't'or 1.2f], the String type [like "" or Something], or the null type [null]

文字是原始类型值的源代码表示[如1,true,'t'或1.2f],String类型[like“”或Something],或null类型[null]

#3


6  

A literal is a data, where as a data type is the type of container to hold a literal. For example: Orange juice is a literal, a vessel to hold orange juice is a variable and the type of vessel to be used, such as metal vessel for something such as an acid, a glass container for orange juice is the data type. The data type is not the vessel itself, but the type of vessel.

文字是一种数据,其中数据类型是容纳文字的容器类型。例如:橙汁是一种文字,容纳橙汁的容器是一个变量和要使用的容器类型,例如用于诸如酸的物质的金属容器,用于橙汁的玻璃容器是数据类型。数据类型不是容器本身,而是容器的类型。

#4


5  

Values like 1.5, 2, 3.13, “hello” that appear directly in a program are known as literals.

直接出现在程序中的值为1.5,2,3.13,“hello”称为文字。

#5


4  

I don't know that they have enough in common to be able to identify differences, but data types are things like int, float[], Object, and literals are something like 1, { 1.0f, 2.0f}, "abcdef".

我不知道他们有足够的共同点来识别差异,但数据类型是像int,float [],Object和文字这样的东西,如1,{1.0f,2.0f},“abcdef” 。

#6


4  

A literal is a constant value which is compatible to a datatype, a literal is used to assign a value to variable, to compare values or define constants. See JLS 3.10.

文字是一个与数据类型兼容的常量值,文字用于为变量赋值,比较值或定义常量。见JLS 3.10。

e.g:

int varOfDataTypeInt = 123;

String s = "string literal";

#7


4  

Int (Data type) x (Variable) = 100 (Literals) ;

Int(数据类型)x(变量)= 100(文字);

Data type :- Data type means type of data ,it may be byte, short, int , long, float , double ,char boolean and many other user defined type(Class) like Employee, Student etc...

数据类型: - 数据类型表示数据类型,可以是byte,short,int,long,float,double,char boolean和许多其他用户定义类型(Class),如Employee,Student等...

Literals :- The value we assign to variable is called Literal . e.g:- String str= "India"; Here "india" is string Literal .
Literals are fixed value for a variable until they are not assign by other variable.

文字: - 我们赋给变量的值叫做Literal。例如: - String str =“India”;这里“india”是字符串Literal。文字是变量的固定值,直到它们不被其他变量赋值。

true , false and null are reserved word in java. Technically they are literals values and not keywords .However they can not be used as Identifier because they have specific meaning to the java Compiler.

true,false和null是java中的保留字。从技术上讲,它们是文字值而不是关键字。但是它们不能用作标识符,因为它们对java编译器具有特定含义。

#8


2  

Data Type: Are nothing but a reserved memory location to store values. meaning when you create a variable you reserve some space in memory.

数据类型:只是用于存储值的保留内存位置。这意味着当您创建变量时,您在内存中保留了一些空间。

Literal: Is the source code representation of a fixed value, a Given or Constant value. Ex: boolean result = true, String s1 = "Hello World".

Literal:是固定值,Given或Constant值的源代码表示。例如:boolean result = true,String s1 =“Hello World”。

boolean - is data type, result - is variable, true - is literal

boolean - 是数据类型,result - 是变量,true - 是文字

String - is Object data type, s1 - is variable, "Hello World" - is literal

String - 是Object数据类型,s1 - 是变量,“Hello World” - 是文字

#9


2  

A literal is a fixed value that is assigned to a variable (of a specific data type) directly without using a constructor

文字是直接分配给变量(特定数据类型)的固定值,而不使用构造函数

For eg:

String var1 = "Java"; -- here "Java" is a literal

String var1 =“Java”; - 这里“Java”是一个文字

String var2 = new String("Java"); -- here "Java" is not a literal

String var2 = new String(“Java”); - 这里“Java”不是文字

#10


0  

Data types are just, well, different types of data, like Strings or floats or ArrayLists. In Java, most data types are classes. Edit although according to one of the other answers, I think maybe the term "data type" might be used more for primitives, i.e. types that are not classes.

数据类型恰好是不同类型的数据,如字符串或浮点数或ArrayLists。在Java中,大多数数据类型都是类。编辑虽然根据其他答案之一,我认为可能更多地使用术语“数据类型”用于基元,即不是类的类型。

A literal is a way of expressing a value without having to create it using a constructor. For example, if you just put 3 in your code, it means the int 3. You don't have to say new Integer(3) or anything like that.

文字是表达值的一种方式,无需使用构造函数创建它。例如,如果你只在代码中加3,那就意味着int 3.你不必说新的Integer(3)或类似的东西。

By the way, may I recommend the official Java Tutorials.

顺便说一句,我可以推荐官方Java教程。

#11


0  

Data Type : it defines the memory assignment for different "types" available in java.

数据类型:它定义了java中可用的不同“类型”的内存分配。

source http://javawebtutorial.blogspot.in/2013/10/data-types-in-java-as-you-all-know-that.html

Literals : Literals in java define the actual value we can using for variables, constants or to perform any operation.

文字:java中的文字定义了我们可以用于变量,常量或执行任何操作的实际值。

source : http://javawebtutorial.blogspot.in/2013/10/literals-in-java-literals-in-java.html

来源:http://javawebtutorial.blogspot.in/2013/10/literals-in-java-literals-in-java.html

#1


43  

From Java Data types tutorial

从Java数据类型教程

Data types :

数据类型:

Primitive types are special data types built into the language; they are not objects created from a class

原始类型是语言中内置的特殊数据类型;它们不是从类创建的对象

Literal :

A Literal is the source code representation of a fixed value; literals are represented directly in your code without requiring computation

Literal是固定值的源代码表示;文字直接在代码中表示,无需计算

boolean result = true;

boolean - is data type
true - is literal

#2


18  

 String string = "Hello World";
 <  1 > <  2 >   <     3     >

1 is a data type, 2 a variable name, 3 a (String) literal

1是数据类型,2是变量名,3是(String)文字

From the JLS:

来自JLS:

A literal is the source code representation of a value of a primitive type [like 1, true, 't'or 1.2f], the String type [like "" or Something], or the null type [null]

文字是原始类型值的源代码表示[如1,true,'t'或1.2f],String类型[like“”或Something],或null类型[null]

#3


6  

A literal is a data, where as a data type is the type of container to hold a literal. For example: Orange juice is a literal, a vessel to hold orange juice is a variable and the type of vessel to be used, such as metal vessel for something such as an acid, a glass container for orange juice is the data type. The data type is not the vessel itself, but the type of vessel.

文字是一种数据,其中数据类型是容纳文字的容器类型。例如:橙汁是一种文字,容纳橙汁的容器是一个变量和要使用的容器类型,例如用于诸如酸的物质的金属容器,用于橙汁的玻璃容器是数据类型。数据类型不是容器本身,而是容器的类型。

#4


5  

Values like 1.5, 2, 3.13, “hello” that appear directly in a program are known as literals.

直接出现在程序中的值为1.5,2,3.13,“hello”称为文字。

#5


4  

I don't know that they have enough in common to be able to identify differences, but data types are things like int, float[], Object, and literals are something like 1, { 1.0f, 2.0f}, "abcdef".

我不知道他们有足够的共同点来识别差异,但数据类型是像int,float [],Object和文字这样的东西,如1,{1.0f,2.0f},“abcdef” 。

#6


4  

A literal is a constant value which is compatible to a datatype, a literal is used to assign a value to variable, to compare values or define constants. See JLS 3.10.

文字是一个与数据类型兼容的常量值,文字用于为变量赋值,比较值或定义常量。见JLS 3.10。

e.g:

int varOfDataTypeInt = 123;

String s = "string literal";

#7


4  

Int (Data type) x (Variable) = 100 (Literals) ;

Int(数据类型)x(变量)= 100(文字);

Data type :- Data type means type of data ,it may be byte, short, int , long, float , double ,char boolean and many other user defined type(Class) like Employee, Student etc...

数据类型: - 数据类型表示数据类型,可以是byte,short,int,long,float,double,char boolean和许多其他用户定义类型(Class),如Employee,Student等...

Literals :- The value we assign to variable is called Literal . e.g:- String str= "India"; Here "india" is string Literal .
Literals are fixed value for a variable until they are not assign by other variable.

文字: - 我们赋给变量的值叫做Literal。例如: - String str =“India”;这里“india”是字符串Literal。文字是变量的固定值,直到它们不被其他变量赋值。

true , false and null are reserved word in java. Technically they are literals values and not keywords .However they can not be used as Identifier because they have specific meaning to the java Compiler.

true,false和null是java中的保留字。从技术上讲,它们是文字值而不是关键字。但是它们不能用作标识符,因为它们对java编译器具有特定含义。

#8


2  

Data Type: Are nothing but a reserved memory location to store values. meaning when you create a variable you reserve some space in memory.

数据类型:只是用于存储值的保留内存位置。这意味着当您创建变量时,您在内存中保留了一些空间。

Literal: Is the source code representation of a fixed value, a Given or Constant value. Ex: boolean result = true, String s1 = "Hello World".

Literal:是固定值,Given或Constant值的源代码表示。例如:boolean result = true,String s1 =“Hello World”。

boolean - is data type, result - is variable, true - is literal

boolean - 是数据类型,result - 是变量,true - 是文字

String - is Object data type, s1 - is variable, "Hello World" - is literal

String - 是Object数据类型,s1 - 是变量,“Hello World” - 是文字

#9


2  

A literal is a fixed value that is assigned to a variable (of a specific data type) directly without using a constructor

文字是直接分配给变量(特定数据类型)的固定值,而不使用构造函数

For eg:

String var1 = "Java"; -- here "Java" is a literal

String var1 =“Java”; - 这里“Java”是一个文字

String var2 = new String("Java"); -- here "Java" is not a literal

String var2 = new String(“Java”); - 这里“Java”不是文字

#10


0  

Data types are just, well, different types of data, like Strings or floats or ArrayLists. In Java, most data types are classes. Edit although according to one of the other answers, I think maybe the term "data type" might be used more for primitives, i.e. types that are not classes.

数据类型恰好是不同类型的数据,如字符串或浮点数或ArrayLists。在Java中,大多数数据类型都是类。编辑虽然根据其他答案之一,我认为可能更多地使用术语“数据类型”用于基元,即不是类的类型。

A literal is a way of expressing a value without having to create it using a constructor. For example, if you just put 3 in your code, it means the int 3. You don't have to say new Integer(3) or anything like that.

文字是表达值的一种方式,无需使用构造函数创建它。例如,如果你只在代码中加3,那就意味着int 3.你不必说新的Integer(3)或类似的东西。

By the way, may I recommend the official Java Tutorials.

顺便说一句,我可以推荐官方Java教程。

#11


0  

Data Type : it defines the memory assignment for different "types" available in java.

数据类型:它定义了java中可用的不同“类型”的内存分配。

source http://javawebtutorial.blogspot.in/2013/10/data-types-in-java-as-you-all-know-that.html

Literals : Literals in java define the actual value we can using for variables, constants or to perform any operation.

文字:java中的文字定义了我们可以用于变量,常量或执行任何操作的实际值。

source : http://javawebtutorial.blogspot.in/2013/10/literals-in-java-literals-in-java.html

来源:http://javawebtutorial.blogspot.in/2013/10/literals-in-java-literals-in-java.html