Java Package Folder Naming Conventions

Java Package Folder Naming Conventions

This is very entry level question and might have been answered already.
My question is, what is the correct way to name my package folders?
for example, I want to have package named - com.stack.abc
Option A- shall I create package folder with name - com.stack.abc?
or
Option B- shall I create folder structure as shown below?

com   
  |_stack   
        |_abc

To summarise, I should have only one folder (com.stack.abc) or 2 subfolders under com?

2 Answers

To your question, com.stack.abc should be the folder hierarchy structure.

com |-stack |-abc

2

Edit due to main post edited;

You would create 3 different folders. One folder called com, one folder inside com called stack, and one folder inside stack called abc. On some, or most IDEAs, it will look like 1 folder because it looks like com.stack.abc but it's really 3 folders.

Generally you define the source folder (top level of all java files) as

src/main/java/

Then you define the package that represents your website (if any)

com.stack.abc

This would resolve to;

abc.stack.com

The entire directory would look like this;

src/main/java/com/stack/abc

This might be a helpful link into packaging conventions.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Marcus Vance
Author

Marcus Vance

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.