未登录,请登录后再发表信息
最新评论 (0)
播放视频

《迪哥Java教程》#9 Java里的long类型

Java long tutorial - 009

这节课我们将学习在Java中如何使用long类型-最后一个整型类型
Last of the integers. We’re going to look at how to represent values in Java using the long.
long类型可能是除了int类型之外 用的最频繁的类型了
The long is probably the second most used primitive in Java,
long类型一般用于数据库的ID
second only to the int. This type is used for database ids,
或者需要超过20亿的数值
or things where you’ll have more than 2 billion.
这节课的目标是
The goal for this lesson is to understand
理解什么是long类型 它的数值范围
what is a long in Java, how big is a long,
以及在Java语言中怎样创建它
and how we create it in Java.
其实比尔盖茨的40亿并不是一个很大的数
So if for some reason 4 billion isn’t large enough, say you’re trying to represent
long类型可以表示比这更大
how much money Bill Gates has, there’s one bigger. It’s called the long,
long类型占8个字节 64比特 你可以用long类型代表
and it is 8 bytes, or 64 bits. You can represent a number larger than nine
十的十八次方到十的二十四次方之间的数
quintillion plus or minus a few quadrillion.
毫无疑问这是一个很大的数字 得花五十亿年的时间
Needless to say it’s a big number. It would take five billion years to count
才能数的完
that high.
现在开始正式学习 我们可以用十进制
Better get started. We can give the value as a decimal value,
二进制 十六进制来表示
binary value, or hexadecimal value.
第一个示例是十进制 第二个
The first examples is a decimal literal, the second
是二进制 第三个是十六进制
a binary literal, and third a hexadecimal literal.
编译运行 同样返回的是十进制的数字
Run it and again the values returned are decimal.
看到这你应该非常熟悉了 我们只是改变了数据的类型和值
By now this should look really familiar. We’re just changing the data types and values,
但代码和bytes shorts ints类型中看到的代码大同小异
but the code is pretty much the same as it was for bytes, shorts, and ints.
你可能想知道 到底是用int类型好 还是long类型好呢
You’re probably wondering, should I use a int or a long?
如果在犹豫这个 你应该用int类型
If there’s a doubt, you probably want to use an int.
是的 long类型能够表示你计算机上64个比特位的大小
Yes, the long matches the word size on your computer,
但long类型也会占用你大量的内存
64 bits, but it will also take a ton of room in memory.
所以最好还是用int类型
You’re better off using an int.
long类型适用于对象ID
Longs are good for object identifiers.
那么这就是所有的整数类型了
So that concludes the integer types.
当你想存储小数 比如26.4时会发生什么呢
What happens when you want store real numbers, Like 26.4?
我们将在下集了解到
That’s up next,
什么是浮点类型
when we cover the floating point number types.
嘿 感谢观看这期视频
Hey! Thanks for watching the video.
如果你想看看学的怎么样 你可以到DeegeU.com进行小测试
There’s a quick quiz for this on DeegeU.com ,if you’d like to gauge how much you’ve learned.
如果你喜欢我们的视频 可以通过点击YouTube上DeegeU订阅我们的频道
If you like the video you’re seeing, please let me know by liking the video by hitting the subscribe button
我将感激不尽
for the DeegeU channel on YouTube. I’d really appreciate that!
如果你有任何意见或者疑问 请在下方留言区或者移步DeegeU.com留下建议或疑问
If you have concerns or questions please leave them in the comments below or on 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 in the next video!

发表评论

译制信息
视频概述

迪哥Java让您零基础学Java 这期介绍了long整型

听录译者

收集自网络

翻译译者

闷蛋(ಥ﹏ಥ)

审核员

知易行难

视频来源

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

相关推荐