ADM-201 dump PMP dumps pdf SSCP exam materials CBAP exam sample questions

《迪哥Java教程》#11 Java的布尔类型和字符类型 – 译学馆
未登陆,请登陆后再发表信息
最新评论 (0)
播放视频

《迪哥Java教程》#11 Java的布尔类型和字符类型

Java boolean and char tutorial - 011

目前为止 我们已经看到所有使用Java基本类型表示数字的方法
So far we’ve looked at all the ways represent numbers using
本节课我们来讲Java中如何表示
Java primitives. In this lesson we’re going to look at how to represent
布尔值 布尔值有两种状态
boolean value in Java. Boolean values have two states.
真/假 开/关 是/否
True/false. On/off. Yes/no.
我们还会学习如何表示单个字符
We’ll also get a look at how to represent single characters.
Java字符由单个字母 数字和符号组成
Java characters are single letters, numbers, and symbols.
一旦我们讲完这个 Java的基本类型就学完了
Once we’re done with this, we are done with Java primitives.
让我们开始吧 这是Java基本类型的最后一课
So let’s get started. This is the last lesson on Java primitives.
本节课结束 你会学会布尔类型是什么
By the end of this lesson you should understand what booleans are and how to
以及如何创建
create them.
稍后我们将深入了解字符 它包括所有字母 所有数字 所有符号
We’re then going to close up with characters. These are letters, numbers, and symbols.
这被称为布尔值
This is called a boolean.
布尔值不仅仅用于存储true和false 还可以把它用于
Booleans are not only used to store just true/false, you can use them as
表达式中
expressions.
所以 你可以用直接量true给一个布尔值赋值
So you can set a boolean primitive to the literal value true,
或者 用12>14来赋值
or you can set it to something like 12 is greater than 14.
这个表达式的结果为false
This expression would evaluate to false.
让我们来看看代码 更直观的感受下这点
Let’s take it look at the code to get a better feel for this.
声明一个布尔值 和以前的模式一样
To declare a boolean, it’s the same pattern we’ve seen.
类型 名称 值 唯一两个可能的直接量是关键字true
Type, name, then value. The only possible literal values are the key words true
和false 这里我命名为“bool”
and false. Here I have the name “bool”
值为true 看一下程序运行时会打印出什么
set to true. Let’s see what gets printed when we run this.
输出“true” 你也可以赋值为false
And it prints “true”. You can also set the value to false.
另外要说的是你还可以把表达式当作一个值 所以
The other thing I mentioned was you can treat expressions as a value. So if we
我们说“bool”等于
said “bool” equal
12大于14 意思是希望把 “bool”赋值为
to 12 greater than 14, that means we want “bool” set to
表达式计算的结果 本例中是“false”
whatever that evaluates to. In this case “false”.
运行程序 输出“false”
Run it, and it prints “false”.
下节课我们会介绍表达式和变量
We’ll cover expressions and variables in the next few lessons.
最后一个Java基本类型是16位的
The last Java primitive type is a 16-bit
Unicode字符 Unicode是用以表示所有语言的编码标准
Unicode character. Unicode is the standard for representing characters from
它包含了绝大部分的字母 但更多的是符号
any language. It’s mostly letters, but there’s a lot of symbols too.
只有大约
There are only around
64000个可能的字符被用于这种类型
64,000 possible characters using this type.
幸运的是根本用不到那么多字符 Unicode编码最终扩展至
Fortunately that’s way fewer than it needed to be. Unicode was eventually expanded to 32
32位去容纳不同语言中的字母
bits to accommodate more cultural alphabets.
一开始Java诞生时 并没有将Unicode扩展至32位
When Java was created they hadn’t extended Unicode to 32-bit yet.
他们不能反悔修改类型定义
They can’t retroactively change the type,
因为这会破坏每一个已存在的程序
because that would break everyone’s existing programs.
因此这意味着有许多字符
So that means there are many characters
不能用于Java基本类型 如果你在西欧国家
you can’t use in the Java primitive. If you’re in a Western European country
这不是问题 其他国家
that’s not usually a problem. Other countries
需要其他办法解决字符问题 就不能再用16位来编码了
you going to need to use other solutions for characters that can’t be encoded in 16 bits.
稍后我们会讲解Unicode本地化 这就是Java基本类型
We’ll cover Unicode localization later. This is just a Java primitive type.
做些有趣的事 比如在代码中把值设置为一个笑脸
Still you do some fun things like set a value to a smiley
现在你可以在Unicode列表的特定字符集里找到这个值
face in code. Now you can find the value for particular character in Unicode lists
对简单的ASCII码来说 如A B C 你可以参考ASCII码表
for the simple ASCII characters like A, B, and C. You can use a chart like the one I have here.
让我们来演示一些字符 看看我们能做什么
Let’s go play with some characters and see what we can do.
最后我们到了字符类型变量
Finally we have characters.
和定义字符串有一些不同
They’re a little different to define a character literal.
这里必须用单引号把值包起来
It must be enclosed between two single quotes.
本例中 我把变量“c”赋值为’A’
In this case I’m setting the name “c” to the value ‘A’.
运行程序
We run it.
打印出A
And it prints ‘A’.
我们也可以把数字赋值给字符型变量 这是一个两字节数字
We can also set a character to a number. This is a number that fits into two
只能是正数
bytes. Positive only.
把66赋值给c 运行程序
Setting “c” to 66, and we run it.
打印出B 因为大写字母B
And it prints ‘B’, because capital ‘B’
的字符值是66 也可以把它设置为16进制的字串
has a character value 66. We can also set it to a hex literal.
同样占两个字节 我们把它设置我为43
Again two bytes. We’ll set it to 43.
运行
We run it.
打印出大写的C 就像我刚才说的 我们可以把它的值设置为其他字符
And it prints the letter ‘C’. Like I said earlier we can also set it to other characters,
比如笑脸 运行
like the smiley face. Run it
打印出一个笑脸 字符变量有许多用途
And it prints a smiley face. Characters have some uses,
但是我们通常想把一串字符连到一起成为字符串
but we really want to string a bunch of characters together into
在学习类的时候我们再来了解字符串
a string of characters. We’lll talk about strings after we look at classes.
请注意 我们已经学完了Java所有的基本类型啦!
And on that note We’re done with Java primitives!
接下来我们将学习变量
Next we’re going to talk about variables,
了解它们是如何被赋值 并介绍一些JDK中的关键字
how they’re typed, and introduce a few key words to our toolkit.
下节课见
See you in the next lesson!
嘿!感谢收看
Hey! Thanks for watching the video.
如果你要检测这节课的学习效果 官网上有个
There’s a quick quiz for this on DeegeU.com if you’d like to gauge how much
快速测试
you learned.
如果你喜欢这个系列的视频 请让我知道 可以为我点赞
If you like the videos are seeing, please let me know by liking the video and
或者订阅youtube上的
hitting the subscribe button for
DeegeU频道 我会非常感激的 如果你有任何疑惑
the DeegeU channel on YouTube. I’d really appreciate that. If you have concerns or
或问题 请在下面的评论区
questions please leave them in the comments below
或者官网的评论区留言 官网首页上还有一个投票
or on DeegeU.com. There’s a poll on the front page of DeegeU.com
是关于下节课讲什么的
so you can let me know what topic it’s covered next.
感谢收看 下次再见
Thanks for watching, and see in the next video!

发表评论

译制信息
视频概述

简介Java的布尔类型和字符类型,布尔值与字符的赋值方式 等

听录译者

收集自网络

翻译译者

谷子

审核员

知易行难

视频来源

https://www.youtube.com/watch?v=KmEpUwXA2cQ

相关推荐