Java Programming Tutorial 7 - Primitives and Objects

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
whoa dude this series is so awesome I know that's what you guys are thinking and let me tell you're right because in this video we're gonna be talking about how to create even more awesome variables so yeah you've seen hey we can make a string wow that's fun but now we're gonna be talking about what are known as primitive types it's basically a fancy word just to say more variables but before we dive in I definitely need to give a shout out to our lovely sponsor pram pram is a super legit website where you can go to get interview practice for an upcoming job interview or just to practice your data structures and algorithms really make sure you understand computer science concepts basically the way the app works is you get paired with another individual and you guys do mock interviews with one another basically if you use pram Pugh start really improving your interview skills just by practicing and people are using this to get offers at Google Amazon Twitter and more so check that out guys if you sign up with the link in the description that'll definitely help me out as well alright so so far we've talked about creating string variables and how to create them using this string constructor as well as this more sexy syntax right here but you know we're obviously gonna need more than just strings right we can't build a whole application with just words we need numbers we need dates we need more complex objects and all kinds of stuff so this just requires me to go in a little bit more depth with Java data types so what the crap is a data type so a data type is basically real helpful the type of the data how the computer interprets the data alright so for example we could have the value 5 and then we could have the value 5 these are two different things right so this is a number and this is a string yeah they're trying to represent the same thing but the way the computer interprets it is different right so if you use this the computer thinks hey this is a number this can be added this can be subtracted from well if you use this it's a string so hey we can concatenate to this string and and add content in this string but we can't use it for math right so even though we're using the same here the data-type itself is different Java is known as a statically typed programming language and what that means is we need to say what type our variables are up front so we say yo Java we're going to store a string value in this variable so we basically need to say the type of all of our variables up front and basically Java is just saying yo dude in order for me to best work with your variables I need to know what type they are and with that you need to define all of the types up front before we even compile this is in contrast to different programming languages such as JavaScript for example which by the way is not related to Java in any way in JavaScript variables do not have types they can store anything that is not the case in Java you can only store a string inside of this string variable so that means if I go down here and say string equals 5 well guess what we're gonna get an error and it's gonna say bro you need to change the type from string to int so once you define the type of a variable it's permanently that type so yeah that means we have statically typed which means all data types up front before compiling and in contrast we have dynamically typed and this means variables do not have types and for statically type I should probably say variables are given data types up front okay so I admit I kind of went off on a tangent it's really not what I wanted to talk about in this video but that is useful information what I wanted to talk about is just the way we can break up different data types so there's actually different categories of data types and you know guys anytime you can categorize things this is really good because it helps you memorize things which is why I categorize languages and to statically type and dynamically typed there are primitive types and then there are objects anytime we call a constructor like this or any time we use a string with this fancy syntax here where we don't need that constructor we are creating an object so somewhere there's defined this string class that fines the way a string works and what we're saying is hey we like this implementation we want to make an instance of this this blueprint that you're defining in this string class and we're gonna name it easier so an object is just an instance of a class and the class is the data type by the way just for clarity so in this case string is the data type it's also the class name for primitive types there's a limited number of possibilities when we're talking about objects well hey there are tons of classes out there and anyone can create their own classes so there's essentially unlimited object types so here are the eight primitive types we have boolean byte char or car at short some reason I was thinking s Hort which doesn't even make sense int long float in double all these tell Java to treat the data in different ways and we're going to get into these types and how to use them but now I just want to look at data types from a conceptual view so when we create a primitive type the way we create it is different so we do not do this new stuff here we don't do that so for example if I wanted to make an integer all I would say is int X and then I use the assignment operator and give it a value so this is how we create a primitive now for every primitive type there is a way to create an object similar to this type and this is what's kind of confusing but I'm just going to get over this right at the beginning so we can create an object version of the integer using a capital I and spelling out integer and giving it an identifier and then assigning a value to it so you could assign a value to it just like this as well you're not always going to be able to do that but for Strings here you can and for these primitives you can because this is basically going to be this value is going to be converted to an object okay so this is an object and by the way that conversion to an object is called auto boxing okay so what in the world is going on why do we have a primitive type and a class type well sometimes you're going to need to you the primitive and then other times you're going to need to use an object created from the integer class 99% of the time we're going to use these primitive values but just so you know there is a class equivalent and the way these work are fundamentally different and that is something we're going to get into throughout this series and that is how primitive values are different than object values in general we can use them in the same way so I can come down here I can print X I can print Y and it should work yep they both print 5 nothing out of the ordinary here the difference between primitives and objects really shows up more when we're passing data around to other variables or as arguments to methods and you'll see that when we get to it so I'm just gonna clean this up here that covers everything I wanted to talk about in this video so now you should have a pretty good understanding of the primitive types as well as how they're created in comparison to objects so at this point consider your learning the LEGO pieces of a Lego set and eventually you're gonna start be able to put these LEGO pieces together to build like you know some crazy spaceship or something so stick with it don't quit I know this stuff can be a little what's the word boring but trust me it gets funner all right I'll catch you guys in the next video and please be sure if you've enjoyed this content to subscribe as well let's check out the links in the description alright peace out [Music]
Info
Channel: Caleb Curry
Views: 69,769
Rating: 4.9457626 out of 5
Keywords: java programming, java, programing, tutorial, tutorial 7, how to, primitives, objects, beginner, caleb, curry, calebthevideomaker2, java tutorial, learn java, programming tutorial
Id: r4wWYgkBcpI
Channel Id: undefined
Length: 8min 27sec (507 seconds)
Published: Tue Nov 27 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.