Non-Numeric Data Types

Learn the Basic Java Concepts Working with variables and operators
9 minutes
Share the link to this page
Copied
  Completed

Transcript

Hello there, and welcome back to this Java development course. So, last time we went over numeric data types, and you had some homework to do, your job was to create six variables each have a different numeric data type that we went over, assign them just some random values, and then print the sum of those values. So here's essentially what you should have done. So I have six variables of type, byte short, int, long float and double. And I assigned each of them their respective types of data. So for here are integers here just with decimal points, and then I create a double sum, put the sum of those variables into the double sum, and then print the sum.

So we can run this application run not ruin and we get 121.1 which is the correct amount. So that is essentially what should have done. What was also acceptable was just doing instead of doing some, we can just Do like this without some, that would have also been acceptable. You know, either way it works. So, yeah. Without further ado, then Ah, if you've got a good if not try to understand what this code does and you'll try.

So, other than that, then let's get into today's lesson. All right, so, they're gonna be going over non numeric data types of all the other data types. They're only two Boolean and characters. First of all is going to rename our classes here. So we're going to do refactor rename, to numeric variable types, numeric, here's the weekend stay organized. And then here as well, refactor, rename numeric whoops, numeric, variable types homework, and finish up.

And there we go. Okay, so now let's go ahead and create a new class. We're going to do new class. We could also just do class up here. So we're going to do new class. It's going to be Non numeric data types.

There we go. Let's go ahead and actually create the main method as well. And let's finish. Alright, there we go. So there are two non numeric data types that we need to go over. So there are a comment over this is a comment just something that is ignored by the compiler.

There are what are their right Booleans forgot what type of data data there was. Okay? bullies and characters. There we go. Okay, so, Boolean are essentially just true or false. And characters are just letters.

So I know that isn't nearly enough to understand but so let's go over them together. So first of all, let's go over Boolean. So Boolean 's are created using the Boolean keyword. So it's of type Boolean, assign a name just like an integer, Boolean, a is equal to and true. So we have a tricky word true from a lowercase letter. And then Boolean V equals false at false is another key word from a lowercase letter as well.

So we have two separate variables now of type Boolean true and false, we cannot go to print them, print them, system out, print ln A and then system out print ln B. There we go. And I'll just run this application. There we go, we have true and false. So true and false are actually pretty important in computer science. Since at a very low level, what computers actually do is they have two different states.

So it's called Boolean logic, essentially. So there are two different states in computers. So there's true and false on or off or one in zero. It doesn't matter exactly what you call them. They're just two possible states. And it's actually there's a number system called binary, which is based on that we've already went over a little bit.

So binary is essentially just A number system which works to create, how can I say this? It works on the notion that there are only two possible numbers. So zero and one, right? And this is useful for computers, because in computers we actually have on a roof, so electrical signals on or off. And then from there we can perform Boolean logic. So for example, let's say that we have on and off, and then yeah, on and off, that's going to be one and zero, then we can just simply add them, and it's going to be one.

So one plus zero is one. So there we go. If we have on and on, we can add them as well. And that's going to be two. So that's essentially a very basic sort of unpractical example impractical example of how it works. But yes, that's generally Booleans.

For now, all you really need to know is that there are true and false later on when we go over the Boolean modifiers logical models. files as well as if else statements, which we'll go over very soon. You're gonna we're gonna get a little bit more into Boolean and how they work and how useful they are actually in coding. But for now, just know that they're true or false. And that's really all there is to Boolean. So, without further ado, then let's go over charts.

Okay, so what are characters so characters are essentially letters. So we can create them using the char keyword. So a data type called a variable called a of type char, and we assign them a value using single quotation marks. So let's just say, hey, all right, there we go. Okay, so now we have a variable of type character with the name a, and we assign it a character. Hey.

So pretty simple, you know, print this character System dot out dot print ln, Okay, there we go. And so now we can run this application and we get eight printed. So now we can actually do a a H, and we get an error. So what do we get an error? Well, because a character is by definition, only one character, so we can't have multiple characters. So just one.

So we can only hold one character. I really don't know how else to explain it. So I know a yes, that's actually just one character. Now multiple characters, there actually is a different data type. If you want to store sentences, there actually is a string data type, which actually isn't primitive. But we'll go over strings in more detail in a future lesson, we will actually have a lesson that will purely be dedicated to strings and how they work and what we can do with them.

But for now, this is a character. Now, the important thing to understand with a character is that they're all represented in Java by different numbers. So in this case, let's say we have a we can cast it to int, so we can do a int Hey, there we go. Okay, so what this, what will this do, so we have a character a, so that's all stays the same and we assign a character A, then we print the integer representation of a. So now if we run this application, we get 97. So that means that in Java 97, means Hey, so we can actually go in and actually add 97 to it, we of course, have to, actually we don't even need to cast it, we can just do now a, there we go.

And if we run this, we get a perfect. So what's point to understand is that all characters in Java have an integer representation or numeric representation of the characters themselves. But that really isn't all too useful to know because you're really not going to be working with it that much, but just know that it does actually exist. So that is essentially how we work with characters now. Let's assign you some homework. All right.

So before I send you some homework, actually, we're going to go over one last thing. So let's do you have a chart A equals A and then we have a Boolean. T equals true, say true, we can actually combine them, we can do a plus T. And now let's see. Yeah, we have to do right here, answer double quotation marks. So now if we actually run this, we get a true, we actually put a space here. So what these quotation marks actually do is it creates a new string.

So inside here, we can record we can actually put anything, and we will go over strings, as I already said. But for now, just understand that we can create strings by doing this. And so by doing that, we can actually combine things so we can do a plus t plus and then we can do, let's just say I don't know, a space, a space, and then plus. Let's just say a true sentence. Looks like that. Okay.

So now for this a true sentence. So that essentially how we can combine different characters and Boolean together. Right now for homework, your job is to create two Booleans and two characters, assign them some values, I don't really care which values you assign it to them, just they have to be you know, of type, character and Boolean, respectively. And your job is to print. So a character and then a Boolean, and then a character and a Boolean, all on one line. So, it's a pretty simple homework.

Actually, it's pretty simple homework. We went over everything that you need to know for it in the In this lesson, so yeah, it shouldn't be too hard. Either way, I wish you luck, and I'll see you next time soon.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.