I recently ran across code where the developers used both fully qualified class names AND imported class names in their source code.


import packageA.Foo;

public class Example {
    public packageB.Bar doSomething() {
        final Foo foo = new Foo();

I was under the impression that the only reason one might want to use fully qualified name for classes in source code is when they have identical class names in two different packages and they need the fully qualified name to distinguish between the two. Am I wrong?

2 Answers 2


No - you are quite right. Using fully qualified package names is usually considered poor style, except when it is necessary to avoid collisions.

If a package name is especially short and descriptive, using qualified identifiers can make code more expressive. But the JLS prescribes domain-based names for most packages, so package names usually aren't short and descriptive.

  • I always use full qualified name because prevent collision (as you said)
    – Joe Taras
    Commented Apr 29, 2015 at 14:56

The other reason (except collissions) would be if you need a class only once. This is especially true if the class implements a common interface and you only need the real classname for instantiation. Using the fully qualified name makes it easier to recognize that an uncommon class is used here, and where to find it (assuming sane naming conventions).

List li = new com.foobar.veryspecial.MagicList();
  • Intriguing answer. I like that.
    – Brandon
    Commented Mar 12, 2013 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.