What would be the best way to count lines of code from Java classes excluding comments and blank lines.
Search for software metric for Java I am pretty sure you can find something. LOC is the metric for line of code
See JavaNCSS. Also be aware that LoC is a worthless "metric".
I will now make a blatant appeal to authority by citing Dijkstra:
The practice is pervaded by the reassuring illusion that programs are just devices like any others, the only difference admitted being that their manufacture might require a new type of craftsmen, viz. programmers. From there it is only a small step to measuring "programmer productivity" in terms of "number of lines of code produced per month". This is a very costly measuring unit because it encourages the writing of insipid code, but today I am less interested in how foolish a unit it is from even a pure business point of view. My point today is that, if we wish to count lines of code, we should not regard them as "lines produced" but as "lines spent": the current conventional wisdom is so foolish as to book that count on the wrong side of the ledger.
— EWD, On the cruelty of really teaching computing science
UPDATE: If you're doing this as a practice exercise, then you should probably be using a parser and counting the actual statements.