Skip to main content

Style

This style is influenced from the Google Java Style Guide.

Indentation and Spacing / Horizontal Spacing

Always use 2 or 4 space tabbing (i.e. not \t character).
Keep spacing around operators.

script.java
int sum = a + b; // goodint sum=a+b;     // bad

Limit line length to be < 100 characters.

Vertical Spacing

Use blank lines to separate logical blocks.

script.java
void foo() {  validateUserInput();  processAuthentication();  initialize();  otherThing();}

Prefer to use vertical separators sparingly, having single lines of code isolated vertically is not preferred.

One blank line between class members (fields, constructors, methods). Two blank lines between top-level class definitions.

Braces

Start braces on the same line.

script.java
if (true) {  // good}if (true){  // bad}

Always use braces, even for single-line bodies.

script.java
if (condition) {  return; // good}if (condition) return; // bad

Empty blocks should be written on one line.

script.java
void doNothing() {} // goodvoid doNothing() {} // bad (unnecessarily spread out)

Declarations

One declaration per line

script.java
// goodint a;int b;    // badint a, b;

Access modifiers

Always declare access modifiers explicitly.
Order them as: public / protected / privateabstractstaticfinaltransientvolatile

script.java
private static final int MAX = 100; // goodstatic private final int MAX = 100; // bad

Variable declarations

Declare variables close to where they are first used, not at the top of the block.

script.java
// goodprocessInput(input);String result = compute();use(result);// badString result;processInput(input);result = compute();use(result);

Annotations

Each annotation on a class, method, or constructor goes on its own line.

script.java
@Override@Nullablepublic String getName() { // good  ...}@Override @Nullable public String getName() { // bad  ...}

Annotations on fields may appear on the same line when there is only one.

script.java
@Nullable private String name; // ok

Imports

Never use wildcard imports, it wastes resources.

script.java
import java.util.List;import java.util.Map; // goodimport java.util.*;   // bad

Imports are ordered as follows with a blank line separating each group:

  1. Static imports
  2. java.* and javax.*
  3. Third-party libraries
  4. Internal/project imports

Order imports alphabetically within each group.

Commas

Always use trailing commas in multi-line enums and annotations.

script.java
enum Status {  PENDING,  ACTIVE,  CLOSED, // <-- trailing comma}

Strings

Always use double quotes for string literals. Single quotes are for char literals only.

script.java
String s = "hello"; char c = 'h';

Comments

Use // for inline and single-line comments. Use /** */ Javadoc for all APIs.

For Javadoc, include description, parameters (@param), return value (@return), and errors thrown (@throws)

script.java
/** * Process a registration using a one-time token. * * @param token one-time registration token * @param request user email and first/last name captured from the form * @return response containing success, message and user email * @throws RegistrationException if token is invalid/expired or any step fails */public RegistrationResponse processRegistration(UUID token, RegistrationRequest request) {    ...}

Don't write comments that just restate the code:

script.java
i++; // increments i by 1 — badretryCount = 0; // reset retry counter after successful connection — good

Copyright © 2026 Atheesh Thirumalairajan