In this lecture, I'm going to talk about variables.
OK, so what are variables?
Variables are used to store information, something like a number letter, a sentence or a combination
of these.
It is a piece of memory segment where the data is stored.
First, we're going to look into the declaration and definition of a variable.
So how to declare a variable and what it means.
So to declare a variable in Java is the following.
You need to type and data type first, then the variable name and a semicolon to the end of the line.
We don't assign any value to it.
Here, let me show you how it works in practice.
So we created this program previously.
Now let's delay the system that outdate print and online here.
And instead, Tiepin and a number of followers and a semicolon, this variable can represent a number
of YouTube or Twitter followers, or we can use another name like number of countries.
And here is used for whole numbers.
As you can see, the variable name is great because it isn't used and it doesn't have a value.
So how we assign a value to this variable, that's what is called definition.
It is very simple.
First, the data type than the variable name equals and value we would like to assign to the variable.
And finally, a semicolon to the end of the line.
Or we can first declare the variable and then you type in the name and equals the value and a semicolon.
OK, how it works in practice.
I'm going to show you the second case here.
So and enter here and number of followers.
And intelligence offers us the variable name Anta.
And then equals and one hundred and ninety five and a semicolon here as well.
The other option is to define it in one line, the easiest way to do that is to delete this here and
that's it.
Both correct, but the second one is used one, we don't know the value of the variable at the beginning,
but we will calculate it later.
OK, so what data types Java has, there are two groups, primitives and object references, there are
separate lectures to explain them in details.
But I'm going to give you a short introduction to them here.
So let's start with primitives.
Hole number data types are Boit, short end and long.
They are very based on how big number they can store in here is bold because it is the default data
type of whole numbers.
They can be used to store whole numbers like number of players on the field or number of passengers.
The next group is floating point numbers.
There are two types float and double here.
Double is the default value.
They also vary based on how big and precise numbers they can store.
They can be used to store bank account balance or transaction amount.
The next group has only one type boolean which can have two states.
True or false, it is a simple one and a good option to store values like Willett's now tomorrow, true
or false, and the last one which can be used to store one single character char.
It can be used for storing the energy efficiency category of a refrigerator or washing machine.
OK, now let's move on to object references.
They are a bit different from the primitives I mentioned in the introduction section that Objects has
a state or states and also have behaviors.
Primitives doesn't have that kind of functionality that objects has.
There are many object reference types and primitives has that object reference versions as well.
So whole numbers, byte short, integer and long.
They are almost the same, except that they are all start with uppercase and instead of end here we
have integer uppercase here shows that these types are object reference types and you will see all object
types start with an uppercase.
OK, now let's move on to floating point numbers float and double.
Nothing special here.
Also, Boolean has its object reference version as well.
What is new here is the text types instead of char.
We have a character with uppercase which can do the same thing for a single character and a new data
type string string can store almost unlimited amount of text.
It can be used to store sentences, descriptions, titles, basically any kind of text.
The last group here is the built in and custom object references.
It can be a five right, which can be used to modify a file or system that we used in the first Java
program lecture that blue ware can be the name of a custom object in a game or an ATM machine for a
banking system.
So besides these inbuilt object reference data types, we can define our custom ones as well.
In the upcoming videos, I'm going to show you how to use primitives, how to use object references
and how to define and use your own custom versions.
But before that, I would like to tell you more about the naming conventions of variables.
So variables are case sensitive.
For example, if you would like to use a variable, you need to type in exactly the same name Binya
declared it.
The next one is that typically variables cannot be declared two times with the same name in the same
class or in the same method.
Also, variable name must start with a letter or dollar mark or underscore, but I don't recommend you
the last two after the first letter.
It can contain numbers, but it isn't recommended either.
And last here, variable names cannot be equal to reserved keywords of Java.
Here you can see a list of the reserved keywords abstract continue for new switch and the list goes
on.
You don't need to memorize these Java.
We warn you that you cannot use these words as variable names.
You might think this list is very long, but don't worry, I will explain all of them later in the course.
One last thing I would like to share with you is the naming standards and business.
These are not forced by Java and it is not necessary to follow them.
But they can make your code more readable if you stick to them.
Also, if you apply for a job and you apply these recommendations, it will show the interviewers that
you are familiar with the business naming conventions.
The first point is Camil case.
So the variable names first word should start with lowercase and every other word in the variable name
should start with uppercase, like I did with number of followers.
No lower case than of with uppercase and follower's.
With uppercase to.
The next one is that the variable names should fully describe what the variable contains.
So don't name the variables like X, Y, Z or A or B or C instead is meaningful names.
If you go back to your code a week later, you will hardly remember what A or B or C means.
The following point is that do not use abbreviations if you can avoid them, use long variable names
instead.
OK, the next recommendation is that do not reduce the variable names for other purposes.
For example, do not use the number of followers variable to store number of notifications.
Create another variable for that instead.
And the last one I mentioned before, do not use Tollerson or underscore in the variable names.
OK, that's pretty much it.
See you in the next video.
But I will tell you more about primitives.