Naming Conventions 자바 네이밍규칙 정하는 방법

박두팔이·2023년 12월 6일
0

자바

목록 보기
24/26

ORACLE Naming Conventions 참고

  • Naming conventions make programs more understandable by making them easier to read. They can also give information about the function of the identifier-for example, whether it's a constant, package, or class-which can be helpful in understanding the code.

  • 명명 규칙은 프로그램을 더 쉽게 읽을 수 있도록 하여 이해도를 높입니다. 또한 식별자의 기능(예: 상수, 패키지 또는 클래스)에 대한 정보를 제공하여 코드를 이해하는 데 도움이 될 수 있습니다.


Identifier Type에 따른 Rules for Naming

식별자 종류에 따른 네이밍규칙

1. Packages 패키지

  • 고유한 패키지 이름의 접두사는 항상 소문자 모두 소문자로 작성되며 최상위 도메인 이름(현재 com, edu, gov, mil, net, org) 중 하나이거나 1981년 ISO 표준 3166에 명시된 국가를 식별하는 영문 두 글자 코드 중 하나이어야 합니다.
  • 패키지 이름의 후속 구성 요소는 조직의 내부 명명 규칙에 따라 달라집니다. 이러한 규칙에 따라 특정 디렉토리 이름 구성 요소는 부서, 부서, 프로젝트, 머신 또는 로그인 이름으로 지정될 수 있습니다.
Ex)
com.sun.eng
com.apple.quicktime.v2
edu.cmu.cs.bovik.cheese

2. Classes 클래스명

  • Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).
  • 클래스 이름은 명사로, 대소문자를 혼용하고 첫 글자를 대문자로 사용해야 합니다.
  • 클래스 이름은 간단하고 설명적인 이름을 사용하세요.
  • 약어를 사용하지 말고 전체 단어를 사용하세요(URL이나 HTML처럼 약어가 긴 형식보다 훨씬 더 널리 사용되는 경우가 아니라면).
Ex)
class Raster;
class ImageSprite;

3. Interfaces 인터페이스

  • Interface names should be capitalized like class names.
  • 대문자를 사용
Ex)
interface RasterDelegate;
interface Storing;

4. Methods 메서드

  • Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized.
  • 동사로 작성합니다.
  • 첫 글자를 소문자로 혼용하고 각 내부 단어의 첫 글자를 대문자로 사용해야 합니다. (=카멜케이스)
Ex)
run();
runFast();
getBackground();

5. Variables 변수

  • 첫 글자는 소문자로 시작합니다. 두번째 내부 단어의 첫 글자는 대문자로 시작합니다.
  • 변수 이름은 밑줄 _ 또는 $ 문자로 시작해서는 안 됩니다(둘 다 허용되기는 하지만).
  • 변수 이름은 짧으면서도 의미가 있어야 합니다. 변수 이름은 누가 봐도 그 사용 의도를 알 수 있어야 합니다.
  • 임시 '버려지는' 변수를 제외하고는 한 문자로 된 변수 이름은 피해야 합니다. 임시 변수의 일반적인 이름은 정수의 경우 i, j, k, m, n, 문자의 경우 c, d, e입니다.
Ex)
int             i;
char            c;
float           myWidth;

6. Constants 상수

  • The names of variables declared class constants and of ANSI constants should be all uppercase with words separated by underscores ("_"). (ANSI constants should be avoided, for ease of debugging.)
  • 클래스 상수로 선언된 변수와 ANSI 상수의 이름은 모두 대문자이며 밑줄("_")로 구분된 단어를 사용해야 합니다. (=SCREAMING_SNAKE_CASE)
Ex)
static final int MIN_WIDTH = 4;
static final int MAX_WIDTH = 999;
static final int GET_THE_CPU = 1;
profile
기억을 위한 기록 :>

0개의 댓글