Learn Pain Less

HomeOur TeamContact
Java
Why Declare Variables as Local and Global
Pawneshwer Gupta
Pawneshwer Gupta
February 08, 2015
1 min

Table Of Contents

01
When we declare local Variables:
02
When we Declare Global Variables:
Why Declare Variables as Local and Global

When we declare local Variables:

We declare local Variables when we want some variables for local use only and which we don’t want later. If we need Variables only inside 1 method then don’t declare them as Global Variables. Local Variables store value for less time, I mean to say that when execution of method finish then local Variables lose their value and become available for another method. Using Local Variables manage memory allocation in JVM. That’s why avoid declaring Variables as Global. Declare Variables as Global when its requested in multiple methods.

When we Declare Global Variables:

We declare Global Variables when we need same value inside multiple methods and inner classes. Global Variables work as communication medium between multiple methods.

For example, if we want to transfer value from 1 method to another method then we can pass value to Global Variables and get value from that Global Variables inside another method.

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Tags

startvariables

Share


Pawneshwer Gupta

Pawneshwer Gupta

Software Developer

Pawneshwer Gupta works as a software engineer who is enthusiastic in creating efficient and innovative software solutions.

Expertise

Python
Flutter
Laravel
NodeJS

Social Media

Related Posts

Working with Files, Folders java
Working with Files, Folders java
March 25, 2015
1 min
Learn Pain Less  © 2024, All Rights Reserved.
Crafted with by Prolong Services

Quick Links

Advertise with usAbout UsContact Us

Social Media