#2.2 Java Tutorial | Working with Variables

preview_player
Показать описание
In this lecture we are discussing
1) Why we we are using variable if we can use literal (data) directly ?
2) What is type safe or static type language ?
3) Method to declare variable
4) Way to store data in variable when error occur

#1
if we use directly literal and want to operation and print in console
then you can do only once. If you want to reuse in next operation or want to use
then you need to write this literal and remember this variable every time.
But if you can store in variable then you can use this value multiple time.

e.g

in every operation you need to remember the the literal 5 and 2
so they violate the DRY principle which is known as don't repeat yourself
So, for using multiple times we are declare the variable
int num1=5;
int num2=2;

#2
java is known as type safe or static type language. It means
data type declaration is necessary. Because during compilation type
is check if does not found give error
int a=5;
int num=6;// required to declare type of variable which we are using

#3
Method to declare variable
There are basically 3 steps to declare a variable in correct way:
step1: Remember We can use alphabets, digits and only two special symbol in variable declaration underscore(_) and dollar($).
step2: First letter can only start with alphabets , underscore and dollar sign but we cannot start first letter with digits.
step3: We cannot use reserved key word to declare the variable
e.g
//abstract , assert , boolean , break , byte , case , catch , char , class , const , continue , default ,
do , double , else , enum , extends , final , finally , float , for , goto , if , implements , import , instanceof ,
int , interface , long , native , new , package , private , protected , public , return , short , static , strictfp ,
super , switch , synchronized , this , throw , throws , transient , try , void , volatile , while

#4
Way to store data in variable
if you can declare
int i=5;
then , double d=i;
but it is incorrect to use int x=d;
because size of double is bigger than integer

by default 5.5 is double
then if you want to intialize 5.5 in float
then float x=5.5f;

More Learning :

Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
Рекомендации по теме
Комментарии
Автор

Hello sir, please upload data structure video. Implementation of Binary tree and others.

AkshayGuptaMe
Автор

Thanks Naveen, Can you also please explain why other special characters except $ and _ are not allowed in Java variable declaration.

jesharose
Автор

Hello sir i have one doubt that can we extends interface????
Because just now i saw that Stream class extends BaseStream class which is an interface also BaseStream extends AutoCloaseble that is also interface so how is it possible to extends an interface??

unadkatparth
Автор

Can you please add this new java core series in a playlist and also provide a link for that playlist in the video description. It will be easier for new users to find it.

aigeanthokchom
Автор

sir cn u make videos on object oriented programming

mrunalkalkar
Автор

R u starting the java tutorial series, y this 2 videos are made? Thank you

MrAmarSindol
Автор

Sir, I have one doubt .

Why you inserted _ underscore character as a integer value ?

Negative impact of doing so ? Or any positive ?

im_swapnil_musale
Автор

"who actually uses _$a4bc_ right? *deletes and replaces with num" - I DIED

awhile later ... types in max meso 2, 147, 483, 647 I DIED AGAIN HAHAHAHA this is so hilarious

moonchipss
Автор

sir u can add google ads on your site telusko and post all your video only there...may it can solve some funding issue....just an idea, yesterday u ask for so...😊😊

ShubhamSingh-retr
Автор

Hello sir, ,,I m anish and student of GNIIT software engineering from NIIT, sir I confused in Java's topics should I learn awt and swing package in java if my profile is java web developer, , is it important to learn for java web developers, ,

mohdanish
Автор

Sir please make video on frameworks rather than core java

tanveershaikh
Автор

Please make a video on jsp and servlets

vigneshwaran
Автор

Put background music for better quality videos.

skd
Автор

To learn servlet ? There is need to learn jsp

hardik_it