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

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

《迪哥Java教程》#7 Java里的short类型

How do you use the Java short primitive? - 007

接下来我们将学习在Java中 我们如何使用short类型来表示数值
Next we are going to see how to represent values in Java using the short.
short类型的使用频率并不高
This isn’t a commonly used data type. You’ll see it more
我们更多的在应用于嵌入式设备或者音频处理的 Java程序里见到
often in Java programs for embedded devices, or maybe sound processing?
而在一般场景下我们是不会遇见这个类型的
You not going to see it in a typical program.
另一方面 物联网也开始慢慢普及
On the other hand,we’re seeing more and more devices in the internet of things,
所以 short类型可能也会有用处 我就把它加入课程内容里
so maybe the short will make a comeback. I’m including it for completeness.
所有的数据类型都很好理解 如果你看了是如何使用的 你就知道是怎么一回事了
It’s good to understand all the data types, so if you see it used, you know what it is.
这节课的目标是了解short类型 它的大小 如何创建它
The goal for this lesson is to look at the short data type,it’s size, and how we create it in Java.
一个short类型占16个字比特位或者说两个字节
A Java short is a number represented by 16 bits or two bytes.
short类型也和byte类型一样用补码表示
again the short is a two’s complement number.
这就意味着在16位的数字中 有一半是负数
This means half of the representable numbers in 16 bits are negative.
short类型的表示范围是-32768到32767
This gives the short a range between -32,768 and 32,767.
你可以用二进制
And you can create shorts using decimal literals,
十进制 或者十六进制来创建short类型 就像byte类型那样
binary literals, or hexadecimal literals, just like the byte.
如果你要存储的数字不在-32768到32767之间
If you store a number larger than 32767 or smaller than -32768.
编译器就会报incompatible type error 就像我们上节课看到的那样
the compiler will give us the incompatible type error we saw in the last lesson
接下来创建short类型
So to create shorts
我们使用关键字short 并给它命名和赋值
we use the keyword short. Give it a name, and possibly a literal value.
在这个示例中我们赋值10794
In this example, we’re creating the number 10794.
回到我们的程序
so back to our program.
第一个示例是十进制的
The first example is a decimal literal,
第二个是二进制 第三个是十六进制
The second is a binary literal. And the third is a hexadecimal literal.
我们运行
We run it, and again
返回的都是十进制的数值
the values are returned in decimal.
这是因为我们在打印结果时没有规定返回数值的类型
This is because we are not formatting the value when we print it back out.
这就是short类型 我们将在下节课中讲最常用的数据类型
So that’s the short. We’ll cover the most used Java primitive next.
嘿 感谢观看这期视频
Hey! Thanks for watching the video.
如果你想检查这节课学得怎么样 你可以到DeegeU.com上
There’s a quick quiz for this on DeegeU.com if you like to gauge how much
测试
you learned.
如果你喜欢这期视频 请顶这个视频
If you like the videos you are seeing, please let me know by liking the video and hitting
并点击YouTube上DeegeU频道的订阅按钮
the subscribe button for
我将十分感谢
the DeegeU channel on YouTube. I’d really appreciate that! If you have concerns or
如果你有任何疑问 欢迎到下方评论区或者到DeegeU.com留言
questions please leave them in the comments below or DeegeU.com.
在DeegeU.com的首页有个投票活动
There’s a poll on the front page of DeegeU.com
你可以让我知道什么内容最受欢迎
so you can let me know what topic is covered next.
感谢观看 下期再见
Thanks for watching, and see you in the next video!

发表评论

译制信息
视频概述

java迪哥让你零基础学Java,这一期讲了short类型的范围及使用

听录译者

收集自网络

翻译译者

闷蛋(ಥ﹏ಥ)

审核员

知易行难

视频来源

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

相关推荐