Тёмный

#4 Variable Declaration and Initialization in Java | Java Tutorial for Beginners 

SG Tutorial
Подписаться 1,2 тыс.
Просмотров 12 тыс.
50% 1

Variable Declaration and Initialization | Java Tutorial for Beginners
About this video:
Hello Everyone,
In this video,I have explained,
What is Variable?
How to Declare Variables?
How to Initialize Variables? in simple way with real life example
Links :
Free core Java tutorials for beginners 👇 • Java Basics
Java Inheritance:
• Java Inheritance | Jav...
Class and Object :
• #1 class and object in...
Java Method:
• #2 Method in Java | Ja...
Java constructor:
• #5 Java Constructor | ...
Java Instance Block:
• #6 Instanse Block in J...
Why do we need programming language?:
• Why we need Programmin...
Notes:
1. What is variable?
2. How to Declare Variables?
2.1 Syntax
3. How to Initialize Variables
3.1 Syntax
1. What is variable?
Variable is a container that stores the value and value of variable can be change...
2. How to Declare Variables?
To declare means to create
That means,
To declare a Variables means to create a Variables.
Now let's think,
If you have to perform any activity on the stage then before going to perform anything on the stage, first you need to introduce yourself on the stage sothat everyone will khow about you.
Similarly,In Java
If you have to use variables in a program then first you need to declare a variables so that compiler knows about variables and if you won't declare a variables and directly use the variables in a program then compiler will raised an error and program won't compile so basically,before using variables in a program we must be declared variables
2.1 Syntax:
Syntax is nothing but the set of rules that you have to follow to write the code.
Same as other languages
Such as english language
You know that where you have to put fullstop ,where you have to put comma n all.
So Basically each language has its own set of rules to write.
Similarly,
In java programming language, there is a syntax ,that we have to follow to write the code of a program.So you can use following syntax to declare a Variables.
access_ modifier data type var_name;
access - modifier :
Access - modifier controls the access level or scope of Variables.
You can use four types of access-modifiers for variables in Java.
public,private,protected,default
For example:
If you create your profile on social media and set your profile as a public then everyone can see your profile.That means,
Your profile will be vissible for everyone
Similarly,
If you declare variable as a public then variable is vissible / Accessible to all classes in a program and If you declared variable as private then variable is accessible only within the same class, where variable declared..
If variable is declared as protected then variable is accessible within the same package or outside the package.
Note: package is nothing but the group of classes.If you don't declared any access_modifier to the variable then it consider as a default and in this case, variable is accessible within the same package.
dataType :
Each variable has it's type and type is nothing but the datatype.
such as
Boolean,byte,char,short, int ,long,float, double,String.
For example :
You can write like this,
public int var1;
here,public is access- modifier,int is datatype and it's int and var is variable name and at the end you have to put semicolon.
Semicolon is important at the end of each statement in java because
it shows to the compiler that where one statement will ends, and from where the next statement will begins.
3. How to Initialize Variables?
To initialize means to assign / to store
that means,to initialize a variable means to assign value / data to the variable.So basically to give initial values to the variables is called as initialization of variables
3.1 Syntax :
So you can use following syntax
access- modifier data type var name = value ;
First you have to write access modifier and next to access modifier there will be a dataType and then there will be variable name and next to the variable name there will be = sign and equal sign followed by value or data that you have to assign to the variable.
For example :
So you can write like this,
public int var1= 2;
Or you can declare and initialize variables like this,
public int var1; // declaration
var1 = 2; // initialization
Either you can declare variable and initialize a variable in same statement or you can declare and initialize a variable separately.
Thank you for watching 🙏
#variablesdeclaration #variablesinitialization
#javatutorialforbeginners
#sgtutorial
#english
#variablesdeclarationandinitialization

Опубликовано:

 

15 сен 2021

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 20   
@rkrk5378
@rkrk5378 Год назад
WOW BEAUTIFULLY EXPLAINED ❤ Saw many videos but always remained confused specially for what is declaration and intialization
@sgtutorial22
@sgtutorial22 Год назад
Thank you so much for your valuable feedback...
@madhan5129
@madhan5129 2 года назад
Your teaching is great mam....pls complete full Java ♥️
@sgtutorial22
@sgtutorial22 Год назад
Yes,will do..Thank you so much..keep learning..!
@stephanieramosglagola4763
@stephanieramosglagola4763 9 месяцев назад
So clear, thank you.
@sgtutorial22
@sgtutorial22 9 месяцев назад
Thank you so much..keep learning...
@crcreations2406
@crcreations2406 2 года назад
Great explanation. And its very usefull. Tq for your explanation. Your grate future.keep it up.🙂
@sgtutorial22
@sgtutorial22 2 года назад
Thank you so much for your feedback 🙏keep learning..!
@ritvikthakur8800
@ritvikthakur8800 Год назад
you r video helped me a lot , very useful video
@sgtutorial22
@sgtutorial22 Год назад
Thank you so much for your feedback...happy learning..
@zahidsadiq1251
@zahidsadiq1251 7 месяцев назад
My favourite oops mam carry lots of ❤for u thanks mam
@sgtutorial22
@sgtutorial22 6 месяцев назад
Thank you..keep learning!
@crcreations2406
@crcreations2406 2 года назад
Please upload the java important topics ex: OOPS , etc.
@sgtutorial22
@sgtutorial22 2 года назад
Already have uploaded few concepts of oops such as class,object,Java inheritance, polymorphism and types of polymorphism and rest of the concepts will upload soon..! To watch all videos you can click on below link 👇 ru-vid.com/group/PLTSNjybYuOXsW0aRk4iI54ncim2qe3rJb Thank you..!
@paramjeettoor1832
@paramjeettoor1832 2 года назад
Very good and great explanation, I would say go little slow and also your voice goes too down sometime, so please make sure your microphone is on right distance, otherwise perfect.
@sgtutorial22
@sgtutorial22 2 года назад
Thanks a lot for your kind suggestion...
@prayingwithlove6649
@prayingwithlove6649 Год назад
Any one welcome to answer please..Do you use command touch before public class Test { ? what commands do you use before the other entries in the terminal? thanks in advance
@sgtutorial22
@sgtutorial22 Год назад
touch command is used to create empty file. like👇 $ touch Test.java So here Test.java empty file will create.. And then you can open it in notepad or any other editors like👇 $ notepad Test.java And here you can write your program And then compile it.. like 👇 $ javac Test.java And then run it.. like👇 $ java Test So in this way you can create Test.java file using touch command..but touch command is not mandatory You can use another way also as follows 👇 👉Open notepad 👉write Java program 👉save Java file as Test.java Now compile it using terminal as follow, $ javac Test.java And then simply run it like👇 $ java Test
@prayingwithlove6649
@prayingwithlove6649 Год назад
@@sgtutorial22 thank you
@sgtutorial22
@sgtutorial22 Год назад
Keep learning..!
Далее
Cabeças erguidas, galera! 🙌 Vamos pegá-la!
00:10
Variables in Java ✘【12 minutes】
12:32
Просмотров 181 тыс.
VARIABLE DECLARATION & INITIALIZATION - JAVA SCRIPT
11:01
Multithreading in Java Explained in 10 Minutes
10:01
Просмотров 889 тыс.
#1 class and object in java | Java for Beginners
22:11
#2 Method in Java | Java for Beginners | Java Method
16:19
11 Tips And Tricks To Write Better Python Code
11:00
Просмотров 604 тыс.
Generics In Java - Full Simple Tutorial
17:34
Просмотров 1 млн