当前位置:网站首页>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!
边栏推荐
- Licking Exercise - 58 Verifying Binary Search Trees
- 常量及数据类型你还记得多少?
- How to join We Media, learn about these 5 monetization modes, and make your account quickly monetize
- Chapter 22 Source Code File REST API Reference (4)
- Open Office XML 格式里如何描述多段具有不同字体设置的段落
- 自媒体爆款标题怎么写?手把手教你写热门标题
- 2022年裁员潮,失业程序员何去何从?
- 使用JMeter进行MySQL的压力测试
- LeetCode 82. 删除排序链表中的重复元素 II
- Flutter气泡框实现
猜你喜欢
From the product dimension, why can't we fully trust Layer2?
Open Office XML 格式里如何描述多段具有不同字体设置的段落
项目部署、
Network sockets (UDP and TCP programming)
从源码角度分析UUID的实现原理
VSCode remote connection server error: Could not establish connection to "xxxxxx" possible error reasons and solutions
做自媒体月入几万?博主们都在用的几个自媒体工具
Alibaba最新神作!耗时182天肝出来1015页分布式全栈手册太香了
模块九 - 设计电商秒杀系统
自媒体爆款标题怎么写?手把手教你写热门标题
随机推荐
Article take you understand interrupt the key driver of polling mechanism
有哪些好用的性能测试工具推荐?性能测试报告收费标准
再有人问你分布式事务,把这篇扔给他
从源码角度分析UUID的实现原理
中小规模网站架构
VSCode remote connection server error: Could not establish connection to "xxxxxx" possible error reasons and solutions
The brave rice rice, does not fear the brush list of 】 list has a ring
基于UiAutomator2+PageObject模式开展APP自动化测试实战
Since the media hot style title how to write?Taught you how to write the title
Not just running away, but saving the guy who mishandled rm -rf /*
How to join We Media, learn about these 5 monetization modes, and make your account quickly monetize
不止跑路,拯救误操作rm -rf /*的小伙儿
3款不同类型的自媒体免费工具,有效提高创作、运营效率
学长告诉我,大厂MySQL都是通过SSH连接的
使用哈工大LTP测试分词并且增加自定义字典
Flutter气泡框实现
越折腾越好用的 3 款开源 APP
什么是幂等性?四种接口幂等性方案详解!
LeetCode 369. Plus One Linked List(链表加1)
Some tips for using Unsafe