Java: Use import or explicit package / class name?

There is no real difference; the generated byte code will be exactly the same. An import statement is really just a way to tell the compiler “when I write JFrame, I actually mean javax.swing.JFrame“.

You might want to use fully-qualified package names if you have for example two classes with the same name in different packages. One common example from the standard library are the classes java.util.Date and java.sql.Date.

Leave a Comment