java
SKILL.md
Google Java Style Guide
Official Google Java coding standards for consistent, maintainable code.
Golden Rules
- 2-space indentation — no tabs
- Column limit: 100 characters
- Use
@Overridewhenever applicable - No wildcard imports — import specific types
- Braces required even for single-statement blocks
- One top-level class per file
- 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 imports
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 |
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/java
Full Guide
See java.md for complete details, examples, and edge cases.
Weekly Installs
2
Repository
testdino-hq/goo…s-skillsGitHub Stars
1
First Seen
14 days ago
Security Audits
Installed on
amp2
cline2
opencode2
cursor2
kimi-cli2
codex2