Skip to content

Proper CheckStyling

JoelToh404 edited this page Mar 15, 2021 · 2 revisions

Why Checkstyling is important?

CheckStyle is an important skill to have as we want our code to be readable by coders who see it. Having a consistent coding style enables everyone in your team to be able to read code more easily.

Many Companies actually enforce coding styles and we will be following our code style based on Google's Java Coding Style.

Here are some Pointers to take note of

1. Use only whitespace(No Tab)

For vim users , you can add the line in your ~/.vimrc file. ''' set expandtab set tabstop=2 set shiftwidth=2 set autoindent set smartindent '''

2.One blank line after import statements

3.White space should separate Java keywords from parenthesis and braces, and be added on both sides of binary operators.

for e.g ''' for(i=0;i<x;i++){ ''' is bad but ''' for (i=0; i<x; i++){ ''' is good

4. Use Egyptian brackets.

Opening brace have no line break before but line break after. closing brace has a line break before and line break after.

5.Block indentation is 2 spaces.

6. Each statement is followed by a line break.

7. There should be a blank line between constructors, methods, nested classes and static initializers. Blank lines can be used between fields to create logical groupings.

8. Class modifiers should follow this order.

public protected private abstract default static final

9.Class names are written in UpperCamelCase, method names and field names in lowerCamelCase, constant names in ALL_CAPS_SNAKE_CASE. Type parameters in single capital letter.