Java Programming Tutorial 11 - Numeric Data Types and Properties (Infinity, NaN)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone congratulations on making it this far in the series I am going to challenge you to get through the rest of it are you gonna accept that challenge or you're gonna let me down yeah you better accept it well we're gonna be doing in this video is we're gonna be talking about the numeric data types in more depth and just some cool things you can do with them and like what's the point of learning all this junk if you're never gonna be able to get a job anyways because you're terrible at interviewing right so in order to get better at interviewing here I am introducing my sponsor pram p-- you can sign up for pram for free and what happens is you get paired with other developers and you get asked questions as if it was a real job interview and then what happens is you solve that problem and it switches and you interview that other person so not only do you get interviewed but you also get to interview other people and these people rate you on how well you did on your interviews so you can figure out what you need to work on people are using pram to get offers at Amazon Google Twitter and more you definitely want to check it out if you want any chance of success at an interview so check that out link in the description all right let's get started so we talked about how to create a primitive int something like this so this is known as a primitive because it's not an object you can also create an object version by doing integer Y and setting that equal to something so this is going to be stored as an integer object and I mentioned this in previous videos most of the time you're going to want to use this there are some rare occasions when you need to use the object version but the majority of cases you're going just use the primitive once we get into generic list this might come up but until then we're not gonna have to worry about it but the reason I bring this up is that I want to call out this integer class this actually is very valuable to us because it's a it's a class just like the class we're making here and it has members inside of it just like in this my sweet program class we have this static method called main well inside of the integer class there are some static methods we can use so for example we could say integer dot and see all of the members inside of this class so the first ones up here these are properties properties are just another name for variables that are attached to a class and one of these important properties is min value and Max value so if you ever need to reference the absolute minimum value of an integer you can use that min value here let's try it out just like this and there you go there's the minimum value for an integer we talked in an earlier video how different data types are different sizes so you can see that here if you do dot and then click size this is going to return an integer here which will be printed out and you can see the size is 32 and that is 32 bits or 4 bytes so that's pretty cool and there are also a lot of methods attached to this class so you can look through these and see which ones might be useful for you we're not gonna get into these quite yet because I want to talk about how the different data types have the same properties so for example I can go to double and then I could put max value right here let's see what the max double size is all right so we have some exponential notation pretty huge number basically with a double though only a certain number of digits are considered trustworthy so like up here it's more trustworthy and then at some point you can no longer trust it a double is a 64-bit number and typically it has 15 digits of precision so after you have 15 numbers in you can't really trust it anymore there's also something very interesting with the double that you should know about and this is across all programming languages it's not just a Java thing there's going to be a few special values the first one is going to be infinity and there's actually two infinities there's a positive infinity and a negative infinity so for example if we wanted to print positive infinity it just says infinity so those are two properties you might want to know about there is also n a n which stands for not a number and this is a special value of double that literally just means it's not a number there are occasions when certain expressions evaluate to something that's not a number for example inside of the math class there is the square root and we could take the square root of negative 1 and what we're gonna do is we're just gonna system out this like so and when we run this we get not a number the first not a number is the one we're printing right here and then the second one is doing the square root of negative 1 inside a double there are methods to test for this so for example we could say is nan and there's also methods for is finite and is infinite which will is infinite we'll test for the positive or negative infinity but we can just show this double is NaN and pass in the math square root of negative 1 and then we're just going to output this whole thing so it's gonna get a little complicated here with the parentheses but we can do it and we can see that outputs true so the way this is set up is pretty interesting just so you guys can see how things get evaluated this math the square root gets evaluated first and then that whatever the result is the return value of that gets passed to this double dot is an N which is right here and then the answer of that is passed to the print line so math dot square root of negative 1 gives us not a number not a number is passed into is not a number and it's evaluated to true and then true is passed into the print line just like certain expressions can give us n a n or not a number there's certain expressions that can give us infinity so for example I could do math dot pal and I could take you know some really large number here like 9 9 9 9 9 raise that to the tons of power and then we're just going to oh got an issue here let me just bring that down a little bit there we go it just has to be in the range of an integer and now I want to output this to the console and it prints out infinity you could do the same thing by passing in a negative sign and then we get negative infinity so that is your introduction to the numeric data types and just some of the special values that come with the double data type hopefully that makes things super crystal clear and the cool thing here is that the whole concept of infinity negative infinity and not a number is not just a Java thing you're gonna get this in JavaScript and other programming languages as well that's because the double data type is based on a standard ie 754 or 754 so if you want to learn more about the double data type you can check that out but that's all I got for you for now please be sure to check out the next video and subscribe if this has been helpful for you in addition to that please check out the description for a link to the crash course the blogs as well as our sponsor who has been tremendously helpful in creating this series thank you and I'll see you in the next one [Music]
Info
Channel: Caleb Curry
Views: 43,951
Rating: 4.9682856 out of 5
Keywords: java programming, java, programming, tutorial, tutorial 11, numeric data types, data, types, properties, Properties Infinity, NaN, code, coding, caleb, curry, calebthevideomaker2, java (programming language), learn java
Id: MRiN2lATy2o
Channel Id: undefined
Length: 7min 3sec (423 seconds)
Published: Wed Nov 28 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.