Member-only story

A short summary of Java coding best practices

based on coding standards by Oracle, Google, Twitter and Spring Framework

14 min readNov 30, 2018

--

The objective of this article is to give you a quick summary of do and don’ts in other words prefer and avoid based on coding standards from tech giants such as Oracle, Google, Twitter, and Spring Framework.

You might or might not agree with some of the best practices presented here, and that’s absolutely fine as long as there is some coding standard in place.

Why coding standards in the first place? There are many good reasons if you Google it and I will leave you with the following illustration

Coding standards document can be lengthy and boring. This article cherry picks bits and pieces from coding conventions by Google, Oracle, Twitter and Spring and it’s objective is to provide you with an easy to follow and less boring set of practices to make your code easy to read and maintain.

Almost always you will join teams working on existing software and there is a pretty good chance that most of the authors have left or switched to different projects, leaving you stranded with portions of code that make you question humanity.

Let’s dive into best practices from various coding standards.

Java Source File

The following is considered as best practices when it comes to java source files:

  • The source file length is lower than 2,000 lines of code
  • The source file is organized with documentation comment, package declaration, followed by a class comment, imports grouped (static last), class/interface signature and so on as shown below
package com.example.model;/**
* Implementation-free perspective to be read by developers
* who might not necessarily have the source code at hand
*
* @author x,y,z
* @date
*…

--

--

Rafiullah Hamedy
Rafiullah Hamedy

Written by Rafiullah Hamedy

Staff software developer • Love to write • Over 250K views • Connect on linkedin.com/in/rhamedy • Medium referral https://medium.com/@rhamedy/membership

Responses (21)

Write a response