hi , i want to ask if some one know how can i calculate number of variables or used variables in a java file?
is there any way to do it?

6 Years
Discussion Span
Last Post by NormR1

Are you asking for the information that would be shown in a variable cross reference listing if the compiler were to generate such a thing?

You'd need a java language parser to scan the source and generate a cross reference.


what i'm asking about is if i have a code just like this one

int x=5;
int y=4;
int z=x+y;

is there any way to get for example : number of integer = 3 ???
without use scanner or any thing like it?


scanner won't help you detect that. if that is what you were looking at, NormR1 is right and you'll have to parse your java code.

what exactly do you need this for?


i need it in my senior program that's all ... ok thx for u and for him ^_^


Another possibility would be to compile the source into a .class file and read that file. It has a well defined format that you could scan for variable definitions. Look at the language definition doc.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.