Tutorial - Java - Local variables


Coding Friends Tutorial Index - > Java

Author Ian - Tutorial Posts = 62
This is a tutorial about variable scope, a variable is a means to store data within the context of the program. For example, if you wish to store a numerical value then you would not store that number in a string, but within a integer or floating point number.

There are different types of variables, integer / string etc, but the scope of a variable is the area in which the variable is defined within block of code that it is situated.

This is some java code to demonstrate the difference between local variables and global.
---
class localvariable
{
       private static int value1 = 1;
       
       static public void globalVariable()
       {
              System.out.println("Global : " + value1);
       }
       
       static public void main(String args[])
       {
              int value1 = 0;
              globalVariable();
              System.out.println("Local : " + value1);
              return;
       }
}       return 0;       
}
---
the output would be
---
Global : 1
Local : 0
---
Creation of cool tutorials :)
User Name Password
Copyright@CodingFriends, 2005-2006. All Rights Reserved.
Home | Forums | Tutorials | Users
RSS Feeds - Global Global CodingFriends RSS Feed - Tutorials Tutorials CodingFriends RSS Feed - Forums Forums CodingFriends RSS Feed - News News CodingFriends RSS Feed
Users
Login|Password problem| Register here

Tutorials
Tutorials Home| C/C++| C#/Mono| Java| Javascript| PHP| Ruby| SQL| (X)HTML/CSS| VB| Linux| Windows

Forum
Forum Home

Projects
3D Game

Site
Home| About me| Links| FAQ

Search