Code Conventions for the Java Programming Language #Java Short Notes

Why Have Code Conventions?

  • 80% of software life cycle is spent on software maintenance.
  • Hardly the original author maintains a software
  • Code Conventions improve the readability of the software
  • If you require to ship your source code as a product, code conventions make your product well packaged

Java Code Conventions

  • Avoid assigning several variables to the same value in a single statement
  • Avoid using an object to access a class (static) variable or method. Use a class name instead
  • Don’t make any instance or class variable public without good reason. When the class is essentially a data structure, you can use public instance variables
  • Two blank lines: Between sections of a source file, between class and interface definitions
  • One blank line: Between methods, between the local variables in a method and its first statement, before a block or single-line, between logical sections inside a method
  • Blank spaces: Between a keyword and parenthesis, after commas in argument lists, after Casts
  • Each line should contain at most one statement
  • One declaration per line is recommended
  • Initialize local variables where they’re declared
  • Put declarations only at the beginning of blocks
  • No space between a method name and the parenthesis
  • Methods are separated by a blank line
  • Four styles of implementation comments: block, single-line, trailing, and end-of-line
  • Documentation comments describe Java classes, interfaces, constructors, methods, and fields. Use /**…*/ for doc comments
  • Doc comments: One comment per class, interface, or member
  • Doc comments: Should appear just before the declaration
  • Avoid lines longer than 80 characters
  • Break longer lines: after a comma, before an operator, Prefer higher-level breaks to lower-level breaks, align new lines with the previous line, or indent the new line with 8 spaces
  • You can get a detailed code conventions at Java Code Conventions

From: http://sitestree.com/?p=4865
Categories:Java Short Notes
Tags:
Post Data:2012-09-01 18:46:01

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada