Home > Articles > Programming > Java

Java Coding Standards

  • Print
  • + Share This
Michelle Johnston suggests a set of Java coding standards and looks at what such coding standards aim to achieve.
Like this article? We recommend

The Purpose of Coding Standards

When writing a set of coding standards, it's important to make clear what the standards aim to achieve for those who will be asked to implement and enforce those standards. This technique helps to encourage buy-in for the standards by all concerned; it also helps developers to make decisions whenever they come across a situation that's not covered by the standards or creates some kind of ambiguity.

For example, if it's clear when reading the standards that the number one aim is to create code that's easily understood by other developers for maintenance purposes, then it will be obvious that the following line of code:

netProfit = (sales - costOfGoodsSold) - ((sales - costOfGoodsSold) * percentageTax);

is less preferable than the following few lines of equivalent code:

grossProfit = sales - costOfGoodsSold;
corporationTax = percentageTax * grossProfit;
netProfit = grossProfit - corporationTax;

On the other hand, if the purpose of the standards is creating concise code, the former example might be more acceptable than the latter.

In a heterogeneous environment—or even in an environment that is not heterogeneous but in which it's assumed that other programming languages may one day be used—one of the clear aims of the coding standards might be to create uniformity wherever possible across the various languages. For example, a .NET environment offers choice about which language to use to create code. In this situation, it would be wise for coding standards (wherever possible) to be based on rules and concepts that apply to all languages that may be used.

  • + Share This
  • 🔖 Save To Your Account