日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java basic data type,java基本数据类型--Basic Datatypes

發(fā)布時間:2025/3/12 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java basic data type,java基本数据类型--Basic Datatypes 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in the memory.---說的好有道理

Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory. Therefore,

There are two data types available in Java

Primitive Data Types--8種

Reference/Object Data Types

Primitive Data Types

There are eight primitive datatypes supported by Java. Primitive datatypes are predefined by the language and named by a keyword.

bit

range

default value

example

usage

byte

8-bit

-128~127(inclusive)(2^7 -1)

0

byte a = 100

short

16-bit

-32,768~32,767 (inclusive) (2^15 -1)

0

short r = -20000

int

32-bit

-2,147,483,648~(inclusive) (2^31 -1)

0

int a = 100000

Integer is generally used as the default data type for integral values unless there is a concern about memory.

long

64-bit

-2^63~(inclusive)(2^63 -1)

0L

long a = 100000L

This type is used when a wider range than int is needed

float

single-precision 32-bit

0.0f

float f1 = 234.5f

Float is mainly used to save memory in large arrays of floating point numbers

double

double-precision 64-bit

0.0d

double d1 = 123.4

This data type is generally used as the default data type for decimal values, generally the default choice.

Double data type should never be used for precise values such as currency

boolean

one bit

false or true

false

boolean flag = true

There are only two possible values: true and false

This data type is used for simple flags that track true/false conditions

char

single 16-bit Unicode character

'\u0000' (or 0)~'\uffff' (or 65,535 inclusive)

char letterA = 'A'

Char data type is used to store any character

Reference Datatypes

Reference variables are created using defined constructors of the classes. They are used to access objects. These variables are declared to be of a specific type that cannot be changed. For example, Employee, Puppy, etc.

Class objects and various type of array variables come under reference datatype.

Default value of any reference variable is null.

A reference variable can be used to refer any object of the declared type or any compatible type.

Example: Animal animal = new Animal("giraffe");

Difference between Primitive and Reference

1.?primitive variables: store primitive values

reference variables: store addresses

2.Assignment-賦值操作,看圖

primitives: the primitive value is copied

eferences: the address is copied

3.Comparisons (e.g. ==)--比較

primitives: the primitive values are compared

references: the addresses are compared

4.Passing Parameters--參數(shù)傳遞

copies the contents of actual parameter(實參) into the formal parameter(形參) (i.e.,?pass-by-value)

primitives: the primitive value is copied

references: the address is copied

primitives: changing the formal parameter's value doesn't affect the actual parameter's value

references: changing the formal parameter's address doesn't affect the actual parameter's address?but?changing the formal parameter's object does change the actual parameter's object since they refer to the same object

5. Store--存儲

primitives:存儲在棧內存中(stack memory)

references:存儲在棧內存中(stack memory),其引用的對象存儲在堆內存中(heap memory)

【引文】https://www.tutorialspoint.com/java/java_basic_datatypes.htm

【引文】https://www.tuicool.com/articles/NBvUFrY

【引文】http://pages.cs.wisc.edu/~bahls/cs302/PrimitiveVsReference.html

標簽:used,java,data,數(shù)據(jù)類型,memory,Datatypes,parameter,type,bit

來源: https://www.cnblogs.com/live-for-learning/p/12254133.html

總結

以上是生活随笔為你收集整理的java basic data type,java基本数据类型--Basic Datatypes的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。