Just curious to know which is the longest class in Java Source Code ( any version above Java 6 ) and how many lines of code is it?
Why do I want to know, what is the use-case?
IMHO, knowing this is also a good way to understand how Java adheres to SOLID principles i.e. How long was the longest class after all those effort to keep it as small as possible.
jdk1.8.0/src> wc -l **/*.java | sort -n | tail -n 2
10159 java/awt/Component.java
Other example are ORBUtilSystemException which is 9063 lines long, Character is 7231 lines, BigDecimal is 5224 lines. These probably shouldn't be used as examples of good design but what might happen in large projects over time. The average line count is 310.
find . -name '*.java' | xargs wc -l | sort -nr | head -n 10
Result for jdk1.8.0:
10161 ./awt/Component.java
7231 ./lang/Character.java
6312 ./util/concurrent/ConcurrentHashMap.java
5858 ./util/regex/Pattern.java
5564 ./util/Collections.java
5257 ./math/BigDecimal.java
5115 ./util/Arrays.java
4986 ./awt/Container.java
4698 ./util/Formatter.java
Note that the shorter idiom wc -l **/*.java is not recursive by default. You need to shopt -s globstar to make the operator recursive. Without that you'll miss large classes such as,
6312 ./util/concurrent/ConcurrentHashMap.java
4503 ./time/format/DateTimeFormatterBuilder.java
Note for mac users:
For the accepted answer to work (wc -l **/*.java), you need bash with globstar support (≥ 4.x). macOS Catalina, for example, comes with an older version of bash (3.2.57). In that case you need to install bash with Homebrew (brew install bash), and turn on recursiveness with shopt -s globstar. You can find more details here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With