Java & J2EE Page 4 - Java and Object-Oriented Programming |
Variables Since we spoke about variables or fields in the Object portion of our tutorial, we'll cover them more in depth here. Java allows for four types of variables. They are as follows: Instance Variables are used for storing the individual states of an object. Class Variable is a single variable that used for all of the objects within a class. Local Variables are used to store temporary states of an object. A local variable is used only within a method and is not usable outside of where it was declared. Parameters are always variables, and never fields. Variable Naming Conventions Just as you can't run around calling everyone "Hey you!" (well you could, but good luck finding the right Hey You in your phone book), you can't simply tell your computer to use "that variable over there with the funny haircut." Below is a list of rules for naming variables.
In the next tutorial on Programming in Java, we will discuss the Data Types of variables (certain variables hold certain types of data) and cover more of the basic language rules.
blog comments powered by Disqus |