본문 바로가기
정리하기 이전 자료 ( before 20-11 )/Java

Naming Conventions

by IMSfromSeoul 2020. 4. 6.

2. Classes naming conventions

In Java, class names generally should be nouns, in title-case with the first letter of each separate word capitalized. e.g.

public class ArrayList {}

 

public class Employee {}

 

public class Record {}

 

public class Identity {}

 클래스의 이름은 명사여야 한다.

 

3. Interfaces naming conventions

In Java, interfaces names, generally, should be adjectives. Interfaces should be in titlecase with the first letter of each separate word capitalized. In same cases, interfaces can be nouns as well when they present a family of classes e.g. List and Map.

public interface Serializable {}

 

public interface Clonable {}

 

public interface Iterable {}

 

public interface List {}

 인터페이스는 형용사여야 한다. 그치만 명사일 수도 있다.

 

4. Methods naming conventions

Methods always should be verbs. They represent an action and the method name should clearly state the action they perform. The method name can be a single or 2-3 words as needed to clearly represent the action. Words should be in camel case notation.

public Long getId() {}

 

public void remove(Object o) {}

 

public Object update(Object o) {}

 

public Report getReportById(Long id) {}

 

public Report getReportByName(String name) {}

 메소드의 이름은 동사여야 한다. 한개 혹은 2-3개 단어가 명확하게 표현되게 이름을 짓자.

 

6. Constants naming conventions

Java constants should be all UPPERCASE where words are separated by underscore character (“_”). Make sure to use final modifier with constant variables.

public final String SECURITY_TOKEN = "...";

 

public final int INITIAL_SIZE = 16;

 

public final Integer MAX_SIZE = Integer.MAX;

 고정 상수는 UPPERCASE로 이름을 짓자.

 

6-1). Enumeration naming conventions

Similar to class constants, enumeration names should be all uppercase letters.

enum Direction {NORTH, EAST, SOUTH, WEST}

7. Generic types naming conventions

Generic type parameter names should be uppercase single letters. The letter 'T' for type is typically recommended. In JDK classes, E is used for collection elements, S is used for service loaders, and K and V are used for map keys and values.

public interface Map <K,V> {}

 

public interface List<E> extends Collection<E> {}

 

Iterator<E> iterator() {}

 제네릭은 일반적으로 T를 사용한다. 한 글자로만 사용해야 한다.

 

 

출처:

 

https://howtodoinjava.com/java/basics/java-naming-conventions/

 

Java Naming Conventions - Best Practices - HowToDoInJava

Java naming conventions are sort of guidelines which application programmers are expected to follow to produce a consistent and readable code.

howtodoinjava.com

 

댓글