Skip to content

clean-code

Clean Code with underscores in literals

As of java 1.7 the java language specification allows integer literals to contain underscores in order to make them more readable. If it is applied in a good way it can enormously increase the readability of your code. In java 1.6 one had to define integer literals like this: int iterations = 10000000; long bytes = 0b11010010011010011001010010010010; With java 1.7 such integer literals can be written more readably by using the underscore as a  thousands separators. int iterations = 10_000_000; or when using binary literals one can use the underscores to group bytes long bytes = 0b11010010_01101001_10010100_10010010;   Further information can be found at http://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-literals.html http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.10.1 Recommended Reading  

GDPR Cookie Consent with Real Cookie Banner