https://github.com/erran/java-style-guide
A Java coding style guide
https://github.com/erran/java-style-guide
Last synced: 11 months ago
JSON representation
A Java coding style guide
- Host: GitHub
- URL: https://github.com/erran/java-style-guide
- Owner: erran
- License: mit
- Created: 2015-01-24T06:03:27.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-05-02T15:59:16.000Z (about 11 years ago)
- Last Synced: 2025-03-20T08:47:44.871Z (about 1 year ago)
- Size: 188 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Java Style Guide
My personal Java coding style guide. These are standards I've learned from
different sources and want to convert into a format similar to the Ruby
style guide's.
## Table of Contents
* [Source Code Layout](#source-code-layout)
* [Classes](#classes)
## Source Code Layout
* Use three **spaces** (soft tabs) per indentation level.
* Adopt a consistent brace-line style. There are two popular styles in the
Java community both of which are considered good - trailing braces (Option A) and leading braces (Option B).
* **(Option A)** Braces on the same line as the previous expression.
```java
// bad - can be unclear when using throws/extends/implements
// on class/method definitions
if (isOdd()) {
}
// good - works naturally with throws/extends/implements
if (isEven())
{
}
```
* **(Option B)** Braces on the subsequent line.
```java
// bad - adds extra insignificant lines
if (isOdd())
{
}
// good - reduces the LOC (lines of code)
if (isEven()) {
}
```
# Classes
* Use a consistent structure in your class definitions.
```java
public class Car
{
// public constructors
public Car(String make, String model)
{
m_make = make;
m_model = model;
}
// public methods
public String toString()
{
return getMakeString() + " model: " + m_model;
}
// protected/private methods
private String getMakeString()
{
return "make: " + m_make;
}
// protected/private members
private String m_make;
private String m_model;
// protected/private static members
private static Logger ms_logger;
}
```