btrballin
btrballin

Reputation: 1464

What are identifiers in java exactly?

I don't understand the full definition of a java identifier. For example in:

String st = "hello";
if(st.equals("hello") return st;

Would equals count as an identifier? I need to create a program in which identifiers are detected in source code and stored if they are. But if the java library methods don't count as identifiers, then there's no way I could store only the programmed named variables, methods, and classes.

Upvotes: 0

Views: 677

Answers (2)

Nirmal Aravind
Nirmal Aravind

Reputation: 1

An identifier is a name given to a variable, method, class, interface, or other program element. Identifiers are used to uniquely identify these program elements within your code.

st, equals, and return are identifiers.

st: This is a variable identifier of type String.

equals: This is a method identifier (a member function of the String class) used to compare strings.

return: This is a keyword used to return a value from a method. Java library methods, such as equals in your example, are indeed considered identifiers.

Upvotes: 0

ElliotSchmelliot
ElliotSchmelliot

Reputation: 8362

From a quick Google search:

Identifiers are the names of variables, methods, classes, packages and interfaces. Unlike literals they are not the things themselves, just ways of referring to them. In the HelloWorld program, HelloWorld, String, args, main and println are identifiers.

So in your case: String, st, and equals are all identifiers as they are the names of classes, variables, and methods respectively.

Upvotes: 1

Related Questions