
Java
- 4 installs
- 8 repo stars
- Updated February 25, 2026
- testdino-hq/google-styleguides-skills
Applies Google's official Java style guide for indentation, naming, imports, Javadoc, and exception handling.
About
Google's official Java style guide covering indentation, line limits, naming, imports, Javadoc, and exception handling. A developer uses it to write and review consistent, maintainable Java code.
- Google's official Java style guide: 2-space indent, 100-char limit
- Covers naming, braces, imports, Javadoc, lambdas, and streams
Java by the numbers
- 4 all-time installs (skills.sh)
- Ranked #76 of 89 Java & JVM skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/testdino-hq/google-styleguides-skills --skill javaAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 4 |
|---|---|
| repo stars | ★ 8 |
| Last updated | February 25, 2026 |
| Repository | testdino-hq/google-styleguides-skills ↗ |
What it does
Applies Google's official Java style guide for indentation, naming, imports, Javadoc, and exception handling.
Files
Google Java Style Guide
Official Google Java coding standards for consistent, maintainable code.
Golden Rules
1. 2-space indentation — no tabs 2. Column limit: 100 characters 3. Use `@Override` whenever applicable 4. No wildcard imports — import specific types 5. Braces required even for single-statement blocks 6. One top-level class per file 7. Prefer interfaces for type definitions
Quick Reference
Naming Conventions
| Element | Convention | Example |
|---|---|---|
| Packages | lowercase.dotted | com.example.project |
| Classes/Interfaces | UpperCamelCase | UserService |
| Methods | lowerCamelCase | getUserById |
| Variables | lowerCamelCase | userCount |
| Constants | UPPER_SNAKE_CASE | MAX_RETRIES |
| Type parameters | Single letter | T, RequestT |
Classes
// ✓ CORRECT
public class Animal {
private final String name;
public Animal(String name) {
this.name = name;
}
public String speak() {
return name + " makes a sound.";
}
}Control Structures
// ✓ CORRECT - braces always required
if (condition) {
doSomething();
}
// ✗ INCORRECT - no braces
if (condition)
doSomething();
// ✓ CORRECT - enhanced for loop
for (String item : items) {
process(item);
}Exception Handling
// ✓ CORRECT
try {
processData(input);
} catch (IOException e) {
logger.error("IO error: {}", e.getMessage());
throw new ServiceException("Failed", e);
}
// ✓ CORRECT - try-with-resources
try (InputStream in = new FileInputStream(file)) {
return IOUtils.toByteArray(in);
}
// ✗ INCORRECT
try {
...
} catch (Exception e) { // too broad
e.printStackTrace(); // don't use printStackTrace
}Lambdas and Streams
// ✓ CORRECT
List<String> names = users.stream()
.filter(u -> u.isActive())
.map(User::getName)
.sorted()
.collect(Collectors.toList());
// ✓ CORRECT - method references
users.forEach(System.out::println);Javadoc
/**
* Finds a user by their unique identifier.
*
* @param userId the user's unique ID
* @return an Optional containing the user, or empty if not found
*/
public Optional<User> findUserById(long userId) { ... }Imports
// ✓ CORRECT
import java.util.List;
import java.util.Optional;
// ✗ INCORRECT
import java.util.*; // no wildcard importsCommon Mistakes
| Mistake | Correct Approach |
|---|---|
| Wildcard imports | Specific imports only |
| Omitting braces | Always use braces |
| Missing @Override | Always annotate overridden methods |
| e.printStackTrace() | Use a proper logger |
| Catching Exception broadly | Catch specific exceptions |
| 4-space indentation | Use 2-space indentation |
When to Use This Guide
- Writing new Java code
- Refactoring existing Java
- Code reviews
- Setting up Checkstyle rules
- Onboarding new team members
Install
npx skills add testdino-hq/google-styleguides-skills/javaFull Guide
See java.md for complete details, examples, and edge cases.
Google Java Style Guide
Source: https://google.github.io/styleguide/javaguide.html
Golden Rules
1. 2-space indentation — no tabs 2. Column limit: 100 characters 3. Use `@Override` whenever applicable 4. No wildcard imports — import specific types 5. Braces required even for single-statement blocks 6. One top-level class per file 7. Prefer interfaces for type definitions
---
1. File Structure
// CORRECT
package com.example.project;
import java.util.List;
import java.util.Optional;
public class UserService {
// ...
}---
2. Naming Conventions
| Element | Convention | Example |
|---|---|---|
| Packages | lowercase.dotted | com.example.project |
| Classes/Interfaces | UpperCamelCase | UserService |
| Methods | lowerCamelCase | getUserById |
| Variables | lowerCamelCase | userCount |
| Constants | UPPER_SNAKE_CASE | MAX_RETRIES |
| Type parameters | Single letter | T, RequestT |
---
3. Classes
// CORRECT
public class Animal {
private final String name;
public Animal(String name) {
this.name = name;
}
public String speak() {
return name + " makes a sound.";
}
}---
4. Control Structures
// CORRECT - braces always required
if (condition) {
doSomething();
}
// INCORRECT - no braces
if (condition)
doSomething(); // braces required
// CORRECT - enhanced for loop
for (String item : items) {
process(item);
}---
5. Exception Handling
// CORRECT
try {
processData(input);
} catch (IOException e) {
logger.error("IO error: {}", e.getMessage());
throw new ServiceException("Failed", e);
}
// CORRECT - try-with-resources
try (InputStream in = new FileInputStream(file)) {
return IOUtils.toByteArray(in);
}
// INCORRECT
try {
...
} catch (Exception e) { // too broad
e.printStackTrace(); // don't use printStackTrace
}---
6. Lambdas and Streams
// CORRECT
List<String> names = users.stream()
.filter(u -> u.isActive())
.map(User::getName)
.sorted()
.collect(Collectors.toList());
// CORRECT - method references
users.forEach(System.out::println);---
7. Javadoc
/**
* Finds a user by their unique identifier.
*
* @param userId the user's unique ID
* @return an Optional containing the user, or empty if not found
*/
public Optional<User> findUserById(long userId) { ... }---
Common Mistakes
| Mistake | Correct Approach |
|---|---|
| Wildcard imports | Specific imports only |
| Omitting braces | Always use braces |
| Missing @Override | Always annotate overridden methods |
| e.printStackTrace() | Use a proper logger |
| Catching Exception broadly | Catch specific exceptions |
| 4-space indentation | Use 2-space indentation |