Data Structure(1)

本文介绍了Java中基本数据类型的使用方法,包括整型、浮点型等,并详细解释了如何声明变量,以及如何选择合适的类型来避免内存浪费或溢出错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

Data Structure

A literal numeric constant contains digits and an optional sign that indicates whether the constant is positive or negative. Floating-point constants also contain a decimal point. In the new Java 7, an int or long can contain underscores to improve readability. For example, you can write the value one million as either 1000000 or 1_000_000.

Java is a strongly typed language, one in which all variables must be declared before they can be used.

 

(1).A variable is a named memory location that you can use to store a value; it can hold only one value at a time, but the value it holds can change.

(2).An item’s data type determines what legal identifiers can be used to describe variables and whether the variables can occupy memory.

(3).A variable declaration is a statement that reservers a named memory location and includes a data type, an identifier, an optional assignment operator and assigned value, and an ending semicolon.

 

In Java, you can use variables of types byte,short,int and long to store(or hold) intergers; an integers is a whole number without decimal places.

The types byte,short, and long are all variations of the integer type. The byte and short types occupy less memory and can hold only smaller values; the long type occupies more memory and can hold larger values.

 

It is important to choose appropriate types for the variables you will use in an application. If you attempt to assign a value that is too large for the data type of the variable, the compiler issues an error message and the application does not execute. If you choose a data type that is larger than you need, you waste memory.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值