Java Essentials - Variables in java
4K views
Nov 18, 2024
Java Essentials - Variables in java Watch more Videos at https://www.tutorialspoint.com/videotutorials/index.htm Lecture By: Mr. Arnab Chakraborty, Tutorials Point India Private Limited
View Video Transcript
0:00
In this video we are discussing variables in Java
0:04
So what are the different do's and don'ts while declaring a variable
0:08
We'll be discussing them in our video. So a variable is nothing but one identified of the memory location or storage area to hold data
0:19
and each variable should have a unique name to identify different data
0:25
We know that variable nomenclature must be very much purposeful. Depending upon the purpose of the variable declaration, the nomenclature or the naming of the variable should be done accordingly
0:36
Let us suppose that is one variable which is nothing but one
0:54
identified which will be holding the value of the sum of a series. Then in that case the variable name should be given, say, a variable, say, A B, C, or say, count, or whatever you prefer best, that should be given. A variable in that case should not be giving a name like, say, A, B, C, or say, count, or
0:58
or say value so that should not be the good practice so variable naming is a very important thing variable naming and also the function naming so that has to be done purposefully and that is
1:11
falling in the best programmers practice so depending upon the data type of
1:18
the variable some memory space some storage will be occupied against the variable
1:23
and the variable naming should be done perfectly and purposefully so here is
1:29
some syntax to declare variables in Java say i nt my variable you can find that this variable name is preceded by the by the prefix that is the
1:38
mine so that it means i have defined this variable and this variable is having the data type iant in case of java
1:45
for the i nt 4 bytes of memory space is getting occupied that means against this my variable
1:51
32 bits of memory space will get occupied and accordingly it can hold the range of the values
1:57
accordingly so that's why the variable name is not nothing but one identify name depending upon the data type the stores the storage space
2:06
which is going to get occupied in the memory that will be decided so my variable is equal to 10 So I initializing my variable with the value 10 here So we can directly assign values after declaration like this one
2:19
So I ent my variable is equal to 10. So instead of writing these two lines separately
2:24
I can put the whole thing in one line. So declaring the variable and also initializing with
2:30
with some value as we have put that one on the right on side of this equal to operator. So there
2:37
some rules for naming the variable so let us go for some do's and don'ts what are to be
2:42
followed and what are to be avoided so my variable is a valid variable name so it is okay
2:49
for us then we can go for underscore my variable so that is also valid but it is not a good
2:55
name to be used here but obviously you can do it you can go for say my then blank space so
3:01
blank space should not be allowed in our variable name you can go for this proper type of
3:06
So M small letter and V capital in this way we can go for say mine series sum mine all in the lower case series S capital and then some S capital and all other letters will be in the lowercase That is a good programmer choice and practice and best practices will be there
3:23
And so, but a variable name cannot, cannot, cannot take a blank space as it's one of the characters
3:30
So that's why it is invalid. My variable one is valid. Yes, you can go for the numeric digits can be put in the variable name, but a variable
3:38
name cannot start with a digit. it can start with some alphabet or underscore we can have this dollar my variable which is
3:47
also valid but should not be used so that is our session and you can go for this variable
3:52
then single quote or a double quote you can give in between and that is also invalid here
3:58
so depending upon the purpose of the variable the variable nomenclature has to be decided and then
4:04
depending upon the data type of the variable how much storage space is going to get
4:10
occupied during the runtime of the Java application that will be decided so in this
4:16
video we have discussed what is a variable and how to define a variable in case in
4:21
in case of Java programming thanks for watching this
#Java (Programming Language)