IT Community - Software Programming, Web Development and Technical Support

Java:Tutorial - The Variable

This is a discussion on Java:Tutorial - The Variable within the Java Programming forums, part of the Software Development category; The variable is probably the most important feature in any programming language. It gives the programmer the ability to store ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Java Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 02-24-2007, 12:59 AM
pranky pranky is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 51
pranky is on a distinguished road
Default Java:Tutorial - The Variable

The variable is probably the most important feature in any programming language. It gives the programmer the ability to store a value in the computers memory and call upon it when ever they want. We will come across variable declarations in a variety of situations in Java. At its most basic, a variable declaration consists of a type (discussed in another tutorial) and an identifier. They may or may not have an access control modifier. A variable may look similar to this

Code:
Code:

private int x = 0;
String colorBlue = “blue”;
There are also different kinds of variables:
Instance Variables: Instance variables are so named because they are variables that are associated with instances of a class; each instance of a class has its own set of instance variables.

Class Variables: Class variables are static, no mater how many instances of the class there are, there is only instance of a class variable.

Local Variables: Local variables have no meaning outside their method. I often refer to them as “trash variables” because after they are used in a method, they are discarded as “trash.”


Naming Conventions
1. A variable can consist of any alphanumeric character and must begin with a letter, a dollar sign, or an underscore. The use of a dollars sign is highly discouraged and so is the underscore. However, it is becoming a popular trend to define instance variables with an underscore.
2. Variables are case sensitive. MyVariable is NOT the same as myvariable.
3. It is convention to start your variable names with a letter, and each subsequent word capitalize. It is also a bad programming practice to use abbreviations as variables and ambiguous variables.

Poor program practices would be
Code:
Code:

int MyVar = 0; //var???
int x = 0; //what is x?
Perfred programming practices
Code:
Code:

int myVariable = 0;
int xLocation = 0;
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java:Tutorial - A better looking GUI pranky Java Programming 2 03-08-2007 12:34 PM
Java:Tutorial - Arrays pranky Java Programming 0 02-24-2007 12:54 AM
Java:Tutorial - Flow Control pranky Java Programming 0 02-24-2007 12:53 AM
Java:Tutorial - Getting Started pranky Java Programming 0 02-24-2007 12:48 AM
Java:Tutorial - Tic-Tac-Toe pranky Java Programming 6 02-23-2007 09:48 AM


All times are GMT -7. The time now is 11:29 PM.


Copyright 2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0