当前位置:网站首页>How many constants and data types do you remember?
How many constants and data types do you remember?
2022-08-10 11:56:00 【51CTO】
前言
In our last post we were talking aboutjavaNotes in the base,关键字,和标识符,这篇我们讲一下javaBasic constants and data types,This series is in strict accordance with thejava学习大纲,A series of step-by-step updates,Brothers who are beginners can pay attention,本系列持续更新.

1.介绍
java中,有许多,All kinds of data need us to represent,有的是可变的,some can't be changed,所以javadeclares two types to describe our data,一个是常量(不可改变的量,如常见的:1,2,1.5,2.7等),一个是变量(可以改变的量).
“常量”的广义概念是:‘不变化的量’(利如:在计算机程序运行时,不会被程序修改的量;数学函数中的某一个量,例如每一个具体的圆的半径、直径数值;物理学中的靠近地面的重力加速度;真空中的光速数值;不同的微粒的各自的质量)换言之,常量,在计算机技术方面虽然是为了硬件、软件、编程语言服务,但是它并不是专门为硬件、软件、编程语言而引入的概念.常量可区分为不同的类型,如:25、0、-8为整型常量,6.8、-7.89为实型常量,‘a’、‘b’为字符常量.常量一般从其字面形式即可判断.这种常量称为字面常量或直接常量.
2.常量
2.1、常量概念
常量是不能改变的量,That is, each constant is a value.
3、数据类型
Just like in mathematics, there are two types of numbers: decimals and integers,在JavaIt needs to represent the diverse content in life and production,Its data types are richer than decimals and integers in mathematics.
Javais a strongly typed language that strictly distinguishes data types,That is, each data must have a data type.
3.1、整数
(1)十进制表示方式:正常数字,如 13、25等
(2)二进制表示方式:以0b(0B)开头,如0b1011 、0B1001
(3)十六进制表示方式:以0x(0X)开头,数字以0-9及A-F组成,如0x23A2、0xa、0x10
(4)八进制表示方式:以0开头,如01、07、0721
代码演示:

3.2、小数
如2.13、1.0,0.5.
代码演示:

3.3、布尔型
Used to indicate whether,布尔类型只有两个值 trueRepresents true that the condition is satisfied, false代表假,即不满足条件.
代码演示:

3.4、字符
3.4.1、普通字符
(1)表示单个字符,The keys of the keyboard can enter a character.A Chinese character can represent a character.
(2)characters need to be used’’将内容包裹
(3)Character content cannot be empty
如 ‘1’、 ‘a’、 ‘ ’(空格)、 ‘中’、 ‘$’
代码演示:

语法错误:
出现语法错误,IDEA会报红,Alerts you to grammatical errors

如果报错,我们没注意到,Is forced to perform,The code will not compile,and will give us more obvious hints

3.4.2、转义字符
Sometimes we cannot give a character directly,Need to use escape character for escape action.转义字符也为一个字符,The escape symbol is composed of the escape symbol and the escaped character:\
如:
\t 制表符,print out the least1个,最多8个空格
\' 单引号,打印出‘
\" 双引号,打印出"
\\ 反斜杠,打印出 \

代码演示:

3.4.3、字符串
(1)字符串String是一种特殊的数据类型
(2)字符串必须使用“”包裹
如 “我爱Java”、 “0”、 “a”、 “”、 “null”
代码演示:

3.5、null常量
used in object-oriented,He means that the value isnull,并不是没有,只有一个值,Is mainly used to fight for the reference data type.【null】
3.6、符号常量
用finalModified variables are symbolic constants
格式:final 变量类型 变量名(大写)=初始化值;
比如:Our name,We basically won't change the name after we've chosen it.,but the name is often used,all we can define as symbolic constants.
代码演示:
展示:

What if we want to change the name later??能改吗?Let's take a look:

我们能看到,不符合java语法,编译不通过.
4.Three types of constants
常量有三种类型:静态常量、成员常量和局部常量.
静态常量:
使用在 final 之前 public static 修饰.public static 修饰的常量作用域是全局的,不需要创建对象就可以访问它,在类外部访问形式为 HelloWorld. PI.这种常量在编程中使用很多.
成员常量:
作用域类似于成员变量,不能修改.
局部常量:
作用域类似于局部变量,不能修改.
在定义常量时就需要对该常量进行初始化.
final 关键字不仅可以用来修饰基本数据类型的常量,还可以用来修饰对象的引用或者方法.
为了与变量区别,常量取名一般都用大写字符.
代码演示:

代码总结
You can try typing the following code,Advice for beginners,切勿直接复制粘贴,This is fake learning,It takes time to gain,Don't waste your study time,Since time and experience,Then you must gain,Get it done, brothers!!!.
结语
This article introduces you to constants and data types,beginner brothers,Can be practical,In the middle of the case,try to do it yourself,The code must be typed by yourself to be rewarded.

有什么问题,You can leave a message in the comment section below,I will reply you as soon as I see it!
Thank you very much for your continued attention!
边栏推荐
- 石墨文档打开文档时快速定位到上次写的位置
- 如何使用工程仪器设备在线监测管理系统
- 机器学习之暴力调参案例
- Buckle exercise - rectangular area does not exceed the maximum value of K and (hard)
- 即时零售业态下如何实现自动做账?
- 力扣练习——58 验证二叉搜索树
- LeetCode 86. 分隔链表
- Interviewer: How are Dao, Service, Controller, Util, and Model divided in the project?
- HDU 4372:Count the Buildings (Stirling数)
- 面试官:项目中 Dao、Service、Controller、Util、Model 怎么划分的?
猜你喜欢

中小规模网站架构

From the product dimension, why can't we fully trust Layer2?

Since the media hot style title how to write?Taught you how to write the title

2022年裁员潮,失业程序员何去何从?

怎么加入自媒体,了解这5种变现模式,让账号快速变现

MLX90640 红外热成像仪测温传感器 手机 APP 软件 RedEye 连接详细

建校仅11年就入选“双一流” ,这所高校是凭什么做到的?

从源码角度分析UUID的实现原理
![[Go WebSocket] 多房间的聊天室(一)思考篇](/img/c9/4374a57c6a4ae02f606253a4c299e4.png)
[Go WebSocket] 多房间的聊天室(一)思考篇

Some tips for using Unsafe
随机推荐
电脑怎么设置屏幕息屏时间(日常使用分享)
LCD驱动端与设备端名称匹配过程分析(Tiny4412)
即时零售业态下如何实现自动做账?
不止跑路,拯救误操作rm -rf /*的小伙儿
什么是幂等性?四种接口幂等性方案详解!
The brave rice rice, does not fear the brush list of 】 list has a ring
[Brave food, not afraid to write the linked list] The problem of the penultimate node of the linked list
POJ 2891 Strange Way to Express Integers (Extended Euclidean)
Licking Exercise - 63 Find all anagrams in a string
基于UiAutomator2+PageObject模式开展APP自动化测试实战
LeetCode 86. 分隔链表
单目操作符(含原码反码补码转换)
L2 applications from a product perspective: why is it a playground?
Weilai-software development engineer side record
Network sockets (UDP and TCP programming)
软件架构简介
Interviewer: How are Dao, Service, Controller, Util, and Model divided in the project?
Analysis of the name matching process between the LCD driver and the device (Tiny4412)
【勇敢饭饭,不怕刷题之链表】链表中有环的问题
VSCode remote connection server error: Could not establish connection to "xxxxxx" possible error reasons and solutions