Java语言是强类型语言,对于每一种数据都定义了明确的具体数据类型,在内存总分配了不同大小的内存空间

图片1.png

        Java中主要有8中基本数据类型,六种数字类型(四个整数型,两个浮点型),一种字符类型,还有一种布尔型。分别是:byte  short  int  long  float  double  char  boolean.

      Java中所有的基本数据类型都有固定的存储范围和所占内存空间的大小,而不受具体操作系统的影响,来保证Java程序的可移植性。整形数据默认为int数据类型,浮点型默认为double数据类型,如果要表示long型数据或float型数据,要在相应的数值后面加上l、L或f、F,否则会出现编译问题。

类型 占用存储空间 表述范围
byte 1字节 -128至127
short 2字节 -2^15 至 2^15 – 1
int 4字节 -2^31 至 2^31 – 1
long 5字节 -2^63 至 2^63 -1
float 4字节 -3.403E38 至 3.403E38
double 8字节 -1.78E308 1.798E308

       boolean:数据值只有true或false,适用于逻辑计算。

       char:char型(字符型)数据在内存中占用2个字节。char型数据用来表示通常意义上的字符,每个字符占2个字节,Java字符采用Unicode编码,它的前128字节编码与ASCII兼容字符的存储范围在\u0000~\uFFFF,在定义字符型的数据时候要注意加' ',比如 '1'表示字符'1'而不是数值1。

基本数据类型间的转换

    1、boolean类型不能转换成任何其他数据类型。

      2、自动类型转换:容量小的数据类型可以自动转换成容量大的数据类型

             byte,short,char—int—long—float—double 

            byte,short,char相互之间补转换,他们参与运算首先转换为int类型

      3、强制类型转换:容量大的数据类型转换成容量小的数据类型时,要加上强制转换符,但这样有可能会造成精度降低或者数据溢出,要小心。

        转换公式:目标类型 变量名=(目标类型)(被转换的数据)

85 Thoughts on “Java基础语法(二)–数据类型

  1. You actually make it appear so easy together with your presentation however I to find this matter to
    be really one thing that I feel I’d never understand.
    It kind of feels too complicated and extremely huge for me.
    I’m looking ahead for your next put up, I’ll attempt to get the hang
    of it! Najlepsze escape roomy

  2. I like this site very much, Its a rattling nice situation to read and
    incur info..

  3. You made some good points there. I looked on the web for additional information about the issue and found most people will go along with your views on this web site.

  4. Having read this I thought it was extremely enlightening. I appreciate you spending some time and energy to put this information together. I once again find myself personally spending a significant amount of time both reading and leaving comments. But so what, it was still worthwhile!

  5. Right here is the perfect website for anybody who wants to understand this topic. You realize a whole lot its almost tough to argue with you (not that I personally will need to…HaHa). You certainly put a brand new spin on a topic that’s been discussed for decades. Excellent stuff, just excellent.

  6. An interesting discussion is worth comment. I think that you ought to publish more about this topic, it may not be a taboo subject but usually people do not discuss such issues. To the next! Many thanks!

  7. There is certainly a great deal to learn about this issue. I really like all of the points you’ve made.

  8. Nice post. I learn something totally new and challenging on blogs I stumbleupon on a daily basis. It will always be useful to read through content from other writers and use something from other websites.

  9. Howdy! I simply would like to offer you a huge thumbs up for the great info you’ve got right here on this post. I am returning to your website for more soon.

  10. Very good article. I’m facing a few of these issues as well..

  11. Howdy! This article could not be written much better! Going through this article reminds me of my previous roommate! He constantly kept preaching about this. I will send this information to him. Fairly certain he will have a very good read. Thanks for sharing!

  12. I need to to thank you for this fantastic read!! I certainly enjoyed every bit of it. I have got you book marked to look at new things you post…

  13. Howdy! This post couldn’t be written any better! Reading through this post reminds me of my previous roommate! He continually kept talking about this. I’ll send this post to him. Fairly certain he will have a good read. Thank you for sharing!

  14. An impressive share! I’ve just forwarded this onto a friend who has been conducting a little research on this. And he in fact ordered me lunch simply because I discovered it for him… lol. So allow me to reword this…. Thanks for the meal!! But yeah, thanx for spending some time to talk about this issue here on your internet site.

  15. Hi there, There’s no doubt that your web site might be having web browser compatibility issues. When I look at your blog in Safari, it looks fine but when opening in IE, it has some overlapping issues. I merely wanted to give you a quick heads up! Besides that, excellent blog.

  16. You are so awesome! I do not believe I have read a single thing like that before. So nice to find another person with a few unique thoughts on this subject. Seriously.. thanks for starting this up. This web site is something that is required on the web, someone with a little originality.

  17. An impressive share! I’ve just forwarded this onto a coworker who has been doing a little research on this. And he actually bought me lunch because I discovered it for him… lol. So let me reword this…. Thank YOU for the meal!! But yeah, thanx for spending the time to discuss this matter here on your site.

  18. Good post! We will be linking to this great article on our site. Keep up the good writing.

  19. There’s certainly a great deal to know about this topic. I really like all the points you’ve made.

  20. Hi! I could have sworn I’ve been to this blog before but after browsing through many of the articles I realized it’s new to me. Nonetheless, I’m certainly pleased I stumbled upon it and I’ll be book-marking it and checking back often.

  21. Everything is very open with a clear explanation of the issues. It was really informative. Your site is useful. Thanks for sharing!

  22. You ought to take part in a contest for one of the best websites on the internet. I will recommend this blog!

  23. I truly love your site.. Excellent colors & theme. Did you create this web site yourself? Please reply back as I’m attempting to create my own blog and would like to know where you got this from or what the theme is named. Cheers.

  24. I was able to find good info from your content.

  25. I was able to find good info from your blog posts.

  26. I seriously love your site.. Excellent colors & theme. Did you create this web site yourself? Please reply back as I’m attempting to create my very own blog and would love to know where you got this from or exactly what the theme is named. Appreciate it.

  27. An outstanding share! I’ve just forwarded this onto a friend who had been doing a little research on this. And he in fact ordered me dinner because I stumbled upon it for him… lol. So allow me to reword this…. Thanks for the meal!! But yeah, thanx for spending the time to talk about this matter here on your web page.

  28. You have made some decent points there. I looked on the net to find out more about the issue and found most individuals will go along with your views on this site.

  29. Next time I read a blog, I hope that it won’t fail me as much as this one. After all, Yes, it was my choice to read, however I actually believed you’d have something useful to talk about. All I hear is a bunch of crying about something that you could fix if you were not too busy seeking attention.

  30. Hello there! I could have sworn I’ve visited this blog before but after browsing through a few of the articles I realized it’s new to me. Anyways, I’m definitely pleased I stumbled upon it and I’ll be book-marking it and checking back regularly!

  31. Good info. Lucky me I recently found your website by chance (stumbleupon). I have bookmarked it for later!

  32. I was extremely pleased to discover this web site. I want to to thank you for ones time due to this fantastic read!! I definitely enjoyed every little bit of it and I have you saved to fav to see new information on your website.

  33. Hello! I simply want to give you a huge thumbs up for your great info you have here on this post. I’ll be coming back to your website for more soon.

  34. After looking into a number of the articles on your blog, I truly like your way of writing a blog. I saved it to my bookmark webpage list and will be checking back soon. Please check out my web site too and tell me how you feel.

  35. Great information. Lucky me I ran across your site by accident (stumbleupon). I have book marked it for later.

  36. A fascinating discussion is worth comment. I believe that you ought to publish more on this issue, it might not be a taboo matter but usually people don’t talk about these issues. To the next! All the best.

  37. I need to to thank you for this great read!! I absolutely enjoyed every little bit of it. I have got you book-marked to look at new things you post…

  38. Hi, I do think this is an excellent web site. I stumbledupon it 😉 I am going to revisit yet again since i have book marked it. Money and freedom is the best way to change, may you be rich and continue to help other people.

  39. May I simply say what a relief to discover someone that truly knows what they’re talking about on the internet. You actually know how to bring an issue to light and make it important. More people should read this and understand this side of the story. I was surprised you’re not more popular given that you certainly have the gift.

  40. Pretty! This has been a really wonderful post. Thank you for providing this information.

  41. Hi, I do believe this is an excellent website. I stumbledupon it 😉 I am going to return yet again since i have saved as a favorite it. Money and freedom is the greatest way to change, may you be rich and continue to guide other people.

  42. An impressive share! I have just forwarded this onto a coworker who was doing a little research on this. And he in fact bought me lunch simply because I stumbled upon it for him… lol. So let me reword this…. Thanks for the meal!! But yeah, thanks for spending time to discuss this issue here on your website.

  43. This is the perfect site for anybody who hopes to find out about this topic. You know a whole lot its almost hard to argue with you (not that I personally will need to…HaHa). You definitely put a fresh spin on a topic that’s been written about for many years. Wonderful stuff, just great.

  44. Way cool! Some extremely valid points! I appreciate you writing this article plus the rest of the website is also really good.

  45. You’re so interesting! I don’t suppose I’ve truly read something like this before. So nice to find somebody with genuine thoughts on this subject matter. Really.. many thanks for starting this up. This web site is something that is required on the web, someone with a bit of originality.

  46. Right here is the perfect website for anybody who really wants to find out about this topic. You understand a whole lot its almost hard to argue with you (not that I really would want to…HaHa). You definitely put a new spin on a subject which has been written about for ages. Excellent stuff, just great.

  47. I needed to thank you for this wonderful read!! I absolutely enjoyed every bit of it. I have you saved as a favorite to look at new things you post…

  48. This website definitely has all the info I needed concerning this subject and didn’t know who to ask.

  49. Good post. I will be experiencing some of these issues as well..

  50. I could not refrain from commenting. Perfectly written!

  51. Greetings! Very helpful advice within this post! It’s the little changes that produce the biggest changes. Many thanks for sharing!

  52. You’re so interesting! I do not suppose I’ve truly read through a single thing like that before. So great to discover someone with a few genuine thoughts on this subject. Seriously.. many thanks for starting this up. This site is something that is required on the web, someone with a bit of originality.

  53. Greetings! Very useful advice in this particular article! It’s the little changes that produce the most important changes. Thanks for sharing!

  54. Aw, this was an incredibly good post. Spending some time and actual effort to create a good article… but what can I say… I procrastinate a lot and don’t manage to get nearly anything done.

  55. Having read this I believed it was really informative. I appreciate you spending some time and effort to put this informative article together. I once again find myself spending a lot of time both reading and commenting. But so what, it was still worthwhile.

  56. I would like to thank you for the efforts you have put in penning this site. I’m hoping to view the same high-grade blog posts from you in the future as well. In truth, your creative writing abilities has inspired me to get my own blog now 😉

  57. May I just say what a comfort to find a person that genuinely understands what they’re talking about over the internet. You certainly realize how to bring an issue to light and make it important. More and more people must look at this and understand this side of the story. I was surprised you’re not more popular because you most certainly possess the gift.

  58. I blog frequently and I truly appreciate your information. This article has really peaked my interest. I will take a note of your site and keep checking for new details about once per week. I opted in for your Feed too.

  59. Good day! Do you know if they make any plugins to help
    with SEO? I’m trying to get my blog to rank for
    some targeted keywords but I’m not seeing very good gains.
    If you know of any please share. Cheers! I saw similar article here:
    Warm blankets

  60. Howdy! I could have sworn I’ve visited this website before but after browsing through a few of the articles I realized it’s new to me. Anyhow, I’m definitely delighted I found it and I’ll be bookmarking it and checking back frequently!

  61. You’re so awesome! I do not believe I have read something like this before. So great to discover another person with a few genuine thoughts on this topic. Seriously.. many thanks for starting this up. This website is something that is required on the web, someone with a bit of originality.

  62. Very nice post. I absolutely love this site. Continue the good work!

  63. May I simply say what a relief to find somebody who actually knows what they’re discussing on the internet. You actually realize how to bring a problem to light and make it important. A lot more people should check this out and understand this side of your story. I can’t believe you’re not more popular since you definitely have the gift.

  64. I really love your blog.. Very nice colors & theme. Did you build this website yourself? Please reply back as I’m looking to create my own website and would like to learn where you got this from or exactly what the theme is called. Many thanks.

  65. When I initially left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and now whenever a comment is added I recieve 4 emails with the same comment. Perhaps there is an easy method you can remove me from that service? Many thanks.

  66. You’re so interesting! I don’t suppose I’ve read through a single thing like that before. So good to find somebody with some genuine thoughts on this subject. Seriously.. thanks for starting this up. This website is something that is needed on the internet, someone with some originality.

  67. I’m excited to discover this website. I wanted to thank you for your time due to this wonderful read!! I definitely loved every little bit of it and I have you book marked to see new things in your blog.

  68. Good site you have here.. It’s hard to find excellent writing like yours nowadays. I seriously appreciate people like you! Take care!!

  69. I blog quite often and I seriously thank you for your content. This article has truly peaked my interest. I’m going to book mark your blog and keep checking for new details about once a week. I opted in for your RSS feed as well.

  70. Hello there! This article couldn’t be written any better! Looking through this article reminds me of my previous roommate! He continually kept talking about this. I will send this post to him. Fairly certain he’ll have a good read. Thank you for sharing!

  71. This is the perfect website for anybody who wants to understand this topic. You understand a whole lot its almost hard to argue with you (not that I really would want to…HaHa). You certainly put a brand new spin on a subject which has been written about for many years. Wonderful stuff, just excellent.

  72. I quite like reading through an article that will make men and women think. Also, many thanks for allowing me to comment.

  73. Howdy! I could have sworn I’ve visited this website before but after going through many of the articles I realized it’s new to me. Nonetheless, I’m definitely pleased I stumbled upon it and I’ll be book-marking it and checking back frequently!

  74. I truly love your blog.. Great colors & theme. Did you create this site yourself? Please reply back as I’m trying to create my very own blog and want to find out where you got this from or what the theme is named. Appreciate it!

  75. I really love your website.. Excellent colors & theme. Did you create this amazing site yourself? Please reply back as I’m trying to create my own personal blog and would like to know where you got this from or just what the theme is named. Kudos.

  76. Way cool! Some very valid points! I appreciate you penning this write-up and the rest of the site is also really good.

  77. Very nice post. I definitely appreciate this site. Stick with it!

  78. Clearly, infants were on Hollywood’s mind in 1987.

  79. Pretty! This was a really wonderful post. Many thanks for supplying these details.

  80. Oh my goodness! Incredible article dude! Thank you, However I am having difficulties with your RSS. I don’t understand the reason why I can’t subscribe to it. Is there anyone else getting identical RSS issues? Anyone who knows the solution will you kindly respond? Thanks!

  81. You have made some decent points there. I looked on the internet for additional information about the issue and found most individuals will go along with your views on this website.

  82. Way cool! Some extremely valid points! I appreciate you penning this write-up plus the rest of the site is extremely good.

  83. Spot on with this write-up, I absolutely feel this website needs a great deal more attention. I’ll probably be back again to read more, thanks for the information!

Post Navigation