Home arrow Java & J2EE arrow Page 4 - Java and Object-Oriented Programming

All About Variables - Java

In the olden days, not only did we have to walk a mile in the chilling winds of a snowstorm to get to school (hey our grandparents had it rougher; they had to do it to get to day care), we also had to make programs without buttons and scrollbars. Now, of course, we have object-oriented programming. This article will introduce you to the most important concepts as they relate to Java.

  1. Java and Object-Oriented Programming
  2. How State and Behavior Affect One Another
  3. Class, Inheritance and Interface
  4. All About Variables
By: James Payne
Rating: starstarstarstarstar / 15
September 19, 2007

print this article




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.

  1. Names may consist of letters, numbers, dollar signs, and underscores.

  2. It is better to use the full word when naming variables to avoid confusion later on. For instance instead of naming a button b_g, take the time to spell out bubble_gum. When you get a call at three o'clock in the morning because your program isn't working, you'll thank yourself.

  3. To make the names more readable, if it contains two words, always uppercase the first letter of each word. If it is one word, keep it lowercase. (Example: BubbleGum or bubble). And remember: no spaces.

  4. Variable names are case-sensitive. If you name your variable bubble and refer to it later as Bubble, it will not work.

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.

>>> More Java & J2EE Articles          >>> More By James Payne

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates


Dev Shed Tutorial Topics: