What is the difference between an identifier and variable?

Reena picture Reena · Jul 11, 2012 · Viewed 50.3k times · Source

I'm a bit confused about identifiers. In my textbook it says, "We use identifiers to name variables (and many other things) in Java."

I'm not really sure what this means. Is it like assigning a variable...to a variable? What?

So far, I'm getting this impression:

int a, b, c; a = 2; b = 99; c = a + b;

Is c an identifier? When it says, "Using identifiers to name variables," are identifiers like int, double, boolean, things used to categorize variables? Please provide some examples.

Answer

user267885 picture user267885 · Jul 11, 2012

You can think of an identifier as variable's name. I wouldn't get too worked up about it.

For example:

int a;
a = 15;

In this example, a is a identifier that refers to the variable with the same name. If a weren't a variable but a function:

int a()
{
}

a();

Then a would still be an identifier but it would identify a function. Just as "Reena" can identify both a person and some kind of a non-profit organization.