Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java package convention

I'm developing an Android project which currently has 4 packages:

com.myapp.app.activities
com.myapp.app.db
com.myapp.app.ws
com.myapp.app.utils

Would I be able to create an additional package which is just

com.myapp.app

?

Eclipse isn't letting me create this package. It tells me a package with this name already exists.

If I start a new project and create a package called "com.testing.app" and then create a new package called "com.testing.app.activities" afterward, it works fine.

For Android developers:

What I'm wanting to do is extend the Application class and have it in a separate package. Suppose com.myapp.app can't be used, what's a good name for this new package?

like image 661
Andrew Avatar asked Sep 24 '10 18:09

Andrew


People also ask

What is the naming convention for Java packages?

Naming ConventionsPackage names are written in all lower case to avoid conflict with the names of classes or interfaces. Companies use their reversed Internet domain name to begin their package names—for example, com. example. mypackage for a package named mypackage created by a programmer at example.com .

What is convention in Java programming?

Java naming convention is a rule to follow as you decide what to name your identifiers such as class, package, variable, constant, method, etc. But, it is not forced to follow. So, it is known as convention not rule. These conventions are suggested by several Java communities such as Sun Microsystems and Netscape.

Are Java package names CamelCase?

Java reference type names The standard Java naming convention demands that all reference types be written in PascalCase, also known as upper camel case.

Should Java package names be singular or plural?

Use the plural for packages with homogeneous contents and the singular for packages with heterogeneous contents. By investigating a variety of use scenarios, we were able to demonstrate how to solve the Java Package Naming Convention Plural Singular problem that was present.


2 Answers

Eclipse won't let you create this package because it already exists.

Packages in Java are represented in the filesystem as hierarchical folders: com.myapp.app.activities is in the com/myapp/app/activities folder. com/myapp/app already exists, so you can't create this package.

In Eclipse, juste create a new class, and in the "Package" section, precise you want to create it in the com.myapp.app package. This should work.

like image 139
Vivien Barousse Avatar answered Oct 31 '22 19:10

Vivien Barousse


The package com.myapp.app already exists. You can create a class named com.myapp.app.MyClass, you'll see it right in the app package.

Another thing you can do is changing the layout of your packages from a flat layout to a hierarchical layout :

Example


Resources :

  • help.eclipse.org : Project Explorer view
like image 38
Colin Hebert Avatar answered Oct 31 '22 19:10

Colin Hebert