Skip to content

Commit

Permalink
Update Java style guide
Browse files Browse the repository at this point in the history
  • Loading branch information
cushon authored and shicks committed Sep 30, 2017
1 parent 520cd9f commit 911d9f4
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions javaguide.html
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,16 @@ <h3 id="s4.3-one-statement-per-line">4.3 One statement per line</h3>
<a name="columnlimit"></a>
<h3 id="s4.4-column-limit">4.4 Column limit: 100</h3>

<p>Java code has a column limit of 100 characters.
<p>Java code has a column limit of 100 characters. A "character" means any Unicode code point.
Except as noted below, any line that would exceed this limit must be line-wrapped, as explained in
Section 4.5, <a href="#s4.5-line-wrapping">Line-wrapping</a>.
</p>

<p class="tip">Each Unicode code point counts as one character, even if its display width is
greater or less. For example, if using
<a href="https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms">fullwidth characters</a>,
you may choose to wrap the line earlier than where this rule strictly requires.</p>

<p><strong>Exceptions:</strong></p>

<ol>
Expand Down Expand Up @@ -551,7 +556,7 @@ <h4 id="s4.6.2-horizontal-whitespace">4.6.2 Horizontal whitespace</h4>
</ol>

This rule is never interpreted as requiring or forbidding additional space at the start or
end of a line; it addresses only <em>interior</em> space.<p></p>
end of a line; it addresses only <em>interior</em> space.

<h4 id="s4.6.3-horizontal-alignment">4.6.3 Horizontal alignment: never required</h4>

Expand Down Expand Up @@ -623,6 +628,9 @@ <h5 id="s4.8.2.1-variables-per-declaration">4.8.2.1 One variable per declaration
<p>Every variable declaration (field or local) declares only one variable: declarations such as
<code class="badcode">int a, b;</code> are not used.</p>

<p><strong>Exception:</strong> Multiple variable declarations are acceptable in the header of a
<code class="prettyprint lang-java">for</code> loop.</p>

<h5 id="s4.8.2.2-variables-limited-scope">4.8.2.2 Declared when needed</h5>

<p>Local variables are <strong>not</strong> habitually declared at the start of their containing
Expand Down Expand Up @@ -842,15 +850,17 @@ <h4 id="s5.2.3-method-names">5.2.3 Method names</h4>
<code class="prettyprint lang-java">stop</code>.</p>

<p>Underscores may appear in JUnit <em>test</em> method names to separate logical components of the
name. One typical pattern is <code>test<i>&lt;MethodUnderTest&gt;</i>_<i>&lt;state&gt;</i></code>,
for example <code class="prettyprint lang-java">testPop_emptyStack</code>. There is no One Correct
name, with <em>each</em> component written in <a href="#s5.3-camel-case">lowerCamelCase</a>.
One typical pattern is <code><i>&lt;methodUnderTest&gt;</i>_<i>&lt;state&gt;</i></code>,
for example <code class="prettyprint lang-java">pop_emptyStack</code>. There is no One Correct
Way to name test methods.</p>

<a name="constants"></a>
<h4 id="s5.2.4-constant-names">5.2.4 Constant names</h4>

<p>Constant names use <code class="prettyprint lang-java">CONSTANT_CASE</code>: all uppercase
letters, with words separated by underscores. But what <em>is</em> a constant, exactly?</p>
letters, with each word separated from the next by a single underscore. But what <em>is</em> a
constant, exactly?</p>

<p>Constants are static final fields whose contents are deeply immutable and whose methods have no
detectable side effects. This includes primitives, Strings, immutable types, and immutable
Expand Down

0 comments on commit 911d9f4

Please sign in to comment.