Skip to Content
Java Pocket Guide, 4th Edition
book

Java Pocket Guide, 4th Edition

by Robert Liguori, Patricia Liguori
August 2017
Intermediate to advanced content levelIntermediate to advanced
290 pages
4h 10m
English
O'Reilly Media, Inc.
Content preview from Java Pocket Guide, 4th Edition

Chapter 1. Naming Conventions

Naming conventions are used to make Java programs more readable. It is important to use meaningful and unambiguous names comprised of Java letters. The following examples are from various Java sources.

Acronyms

When using acronyms in names, only the first letter of the acronym should be uppercase and only when uppercase is appropriate:

// e.g., DNA is represented as Dna
public class GliesianDnaProvider {...}

// e.g., Most Recent Common Ancestor (MRCA) is Mrca
public class MrcaCalculator {...}

Annotation Names

Annotation names have been presented several ways in the Java SE API for predefined annotation types, [adjective|verb][noun]:

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface FunctionalInterface {}

Class Names

Class names should be nouns, as they represent “things” or “objects.” They should be mixed case (camel case) with only the first letter of each word capitalized, as in the following:

public class AirDensityCalculator {...}

Constant Names

Constant names should be all uppercase letters, and multiple words should be separated by underscores:

private static final double KELVIN = 273.16;
private static final double DRY_AIR_GAS_CONSTANT = 287.058;
private static final double HUMID_AIR_GAS_CONSTANT = 461.4964;

Enumeration Names

Enumeration names should follow the conventions of class names. The enumeration set of objects (choices) should be all uppercase letters:

public enum MeasurementSystem ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java 8 Pocket Guide

Java 8 Pocket Guide

Robert Liguori, Patricia Liguori
Java 11 Cookbook - Second Edition

Java 11 Cookbook - Second Edition

Nick Samoylov, Mohamed Sanaulla

Publisher Resources

ISBN: 9781491938683Errata Page