Java

왜 자바 패키지는 com으로 시작할까? (Package Naming convention)

쟈비쓰 2023. 1. 7. 13:21
728x90

자바에서 package를 만들면 보통 com.foo.package 와 같은 형식으로 com으로 시작하거나, org으로 시작하는 경향이 있다.

저 두개는 도메인 명의 끝에 있는 것인데, 왜 그것이 패키지명의 시작에 들어가는지 궁금해서 찾아보니 "Java Package Naming Convention"을 따르기 때문이다.

 

네이밍 컨벤션에 따르면 자바의 패키지명은 도메인명을 역순으로 나열하는 것이다.

 

예)

- 도메인명 : dobbycantype.com

- 패키지명 : com.dobbycantype

 

 

이때 com이 흔한 이유는 많은 패키지가 회사들에서 만들어지기 때문에 도메인명이 com으로 끝나고, 그래서 패키지명의 시작이 com이 되는 것이다.

org로 시작하는 것은 동일한 이유로 도메인의 끝이 org인 경우 패키지명을 그렇게 짓는다.

 

Java language의 패키지들은 java, javax로 시작한다.

 

 

 

참고

↓ Oracle에서 공개한 Java Package naming convention

https://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html

 

Naming a Package (The Java™ Tutorials > Learning the Java Language > Packages)

The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available. See Java Language Changes for a summary of updated

docs.oracle.com

↓ 위 내용을 설명해주는 스택오버플로우

https://stackoverflow.com/questions/4620045/why-is-the-root-package-in-source-code-called-com

 

Why is the root package in source code called "com"?

In most source codes, the root package/folder is named "com". Why is that so? It it just convention or does it stand for something?

stackoverflow.com

728x90