Variable Data Types

7 minutes
Share the link to this page
Copied
  Completed
The data types that hold numeric values are: byte , short , int , long , float and double . The difference between them is the size and precision of the value they contain. Multiple characters or 'strings' (eg words and sentences) are also supported in Java through the use of String .

Transcript

Hello in this video I am going to show you variable data types. So as you can see, you know from the variable video we've got three variables here named var one and var two name is a string, as you can see, it's just you know two words and a space in between and var one and row two all numbers. So you can see they are basically two different types of data. So that's why data type is so there, you know, there's a bunch of different types of data let me actually get rid of this. So what we have, let me comment this and then you have integer. So integer, and this is anything that is a whole number.

This can be a negative number, because I have a decimal point. So negative one, no, zero is valid one is valid 100 valid, anything like that is fine. Then what we have is a double. This is also sometimes called a float in other languages, though, so double float. Note, and this is basically like an integer, it supports decimals. So it can be any of these.

So it could be any of these. But you also could have like 567, from negative three from 45 08, for example, they're all valid doubles. Next, what we have is a Boolean. And this is essentially only true or false. So it's true or false. You can think of it as like, on or off, or one or zero.

But Daisy. So this is great for stuff like flags. So if you're checking if the user has successfully logged in, see the true or not, there's nothing else obviously there might be a reason. And like there could be a multitude of reasons why the user has not successfully logged in, but the flag could just be have have they logged in or not. And next, what we have is no So, this is actually like a special data type. And he only has one value, which is actually no basically meaning it has no value not a zero or empty, immediate has no value at all.

Next is a string. And this is basically you know, carry too, you know, together. So the, you know, valid could be Hello, that's valid. And you always put you know, quotation marks can be single quotation marks or double quotation marks, preferred double, just because single in some other languages like c++ indicates a character only, which is just one, you know, like ABC or D. And to have a character in, you know, PHP you literally just have a script just with the one character that's, you know, a valid string. Hello the Nova valid screen number one could be like, Hello, well for example, deja vu valid strings. Do Next we have an array.

And an array is basically like an advanced variable that has a specific name. And that has a bunch of values that are sort of, you know, organized together. So if you see a collection, actually, that between everything, all the source code will be provided. In collection of values, I'm actually gonna have a separate video covering all of this. Next is objects. And again, I'm gonna have a separate video covering this but this is basically a class you can create and the object is an instance of the class.

Instance of class that can have its own properties like mefferd, and you know, variables, etc. Sooner very advanced concept, which I'm covering in a separate part of this series. And I'm trying to think, is there anything out? No often that's really much it in terms of all the data types. And remember to create the data type, you just put dollar, then you specify the name, do var one equals nine, for example, that is an integer. And I printed it so I could do echo barwon.

Go back, as you can see, it says, and PHP is what is known as a loosely typed language. And what that essentially means is that we don't have to specify like in c++ if I created a variable, so you know, Vol one you would do something like int barwon you Not, so you're specifying not just the name and the value you're assigning to it. You're also specifying basically that particular variable data type, it's accepted datatype. And this isn't just saying this is the data type is expecting why now that you're saying, that's the data type end of you can't have any other, you know, data. So you wouldn't be able to assign a string later on in a variable like that. Whereas in PHP, it automatically detects what data type you're trying to assign to it.

And if you try and find something else different later on, that's fine as well. So what you also can do here so for question, one, var two equals 10 times dollar var two, we get 90, but obviously, you know bear in mind depending on what sort of data type you have, like if this was a string, for example, like hello. We can get a space there. Not trying to that we get a warning, a non numeric value encountered here. So yes, any variable can have any data type in there. But bear in mind, depending on what you do after you've created the variable, you may be limited because you can't find a number and a string together.

Because you know times operation is for numbers only. But in For example, this will a number or a different data type. Can you think what what he can be? What else is a number but not an integer? If you guessed double that will be correct or float. So if I do like minus two to nine, for example, minus 9.5, so minus 9.5.

So if I run that now, as you can see, it worked fine even though it's two different data types, because they all you know, you know, similar they can compute In a similar fashion. So that's it for variable data types. If you have any questions, feel free to pop me a message. And as usual, I look forward to seeing you in the next video.

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.