Variables
In any programming language, variables provide the foundation upon which all else is built.
You can think of a variable as a "place holder", or a "name" that represents one or more values.
In essence, it is a data structure that is provided by the language itself.
The generic syntax for defining variables is as follows:
variableName = value;
Thus, for example, we might assign the value of twenty-seven to the variable named "age" with the syntax:
age = 27;
From then on, unless we change the value of age, the script will translate it to twenty-seven, acting as a placeholder for the value.
So if we then say:
System.out.println(age);
The Java Console will display the value "27".
Naming Variables
In Java you can name your variables anything you like so long as they are not a "Java Keyword" and contain only characters within the set of Unicode characters.
However, a good practice is to use characters within the ranges of "A-Z, a-z, 0-9, or _".
Of course, variable names should help you understand what is happening in your program.
Thus, it is useful to name your variables intelligently, such as "firstName".
Notice that we created a variable firstName in which the first word was lower case, the second word began with an uppercase letter and there were no spaces.
This is pretty standard practice in Java and naming your variables like this is a good habit for you to get into.
|
Note: many developers use an underscore to prefix private variables such as "_adminName" and ALL_UPPERCASE to denote statics.
|
NEXT
Selena Sol contributes to the JavaBoutique's Introduction to Java. Selena curently works for Barclays Capital in London, one of the leading global investment banks in Europe and has worked as a software developer for the National Center for Human Genome research, Microline Software, Neuron Data, and Electric Eye in Singapore. Selena is perhaps best-known for creating the Public Domain Web Script Archive (Extropia) and writing several books on Web Programming (Perl, CGI, Java).
Email: selena@extropia.com
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.
|