Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any widespread, modern Java coding conventions? [closed]

Sun's "Code Conventions for the Java Programming Language" was last updated April 1999. Ten years later a lot has changed in the language, as well as general usage patterns. Are there more up to date, widely adopted standards?

Most guidelines omit specifying file encoding and line endings. Sun recommends mixed tabs and spaces. The Eclipse IDE defaults to Eclipse's standard, which is tabs only. The Maven style guide is spaces only. Many style guides, such as JBoss, follow Sun's guidelines, but prefer K&R braces instead of OTBS. Each Apache project has it's own style guide, with slight differences between each one.

like image 373
brianegge Avatar asked Sep 01 '09 23:09

brianegge


People also ask

What are the coding conventions of Java?

Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters. Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed. Variable names should be short yet meaningful.

Which of the following are widely accepted naming conventions in Java?

Java uses CamelCase as a practice for writing names of methods, variables, classes, packages, and constants.


Video Answer


2 Answers

Four spaces - it's what God uses.

like image 158
codingfloor Avatar answered Oct 20 '22 03:10

codingfloor


The only coding standard you really need to follow is that as accepted by your project team. You might not agree with tabs instead of spaces, but if that is the coding convention of your team, you will do best to follow it.

like image 32
akf Avatar answered Oct 20 '22 01:10

akf