开发者

Count Lines of Code from Java class

What would be the best way to count lines of code from Java classes exclu开发者_运维百科ding comments and blank lines.


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.


CLOC is a utility that does this.

If you're using Eclipse, there are plugins that do this.


CodeAnalyzer is a good tool for *.java files.

We used the FindBugs which gives line of code from .class file. *.java file had 99 lines excluding comments & blank lines but .class gave only 59 lines.

So I think some more compacting happening in class file other than simply removing comments and blank lines


switch to the directory of the classes,and enter the bash code:

find . "(" -name "*.java" ")" -print | xargs wc -l

it can show out the lines of all the *.java file and count the total lines of all the files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜