This is a simple question, but I am really bugged by it. I was trying to find a duplicate, and googled it, but I was more surprised when I couldn't find a satisfying answer.
import java.util.Scanner;
In this statement .Scanner
is the class,
.util
is the name of the package
What is java
or javax
or whatever would stand before the first period in general?
UPDATE:
I also found this picture:
http://www.javatpoint.com/package
Is it true?
Classes in Java are identified by a fully qualified name consisting in a concatenation of the package of the class and the name of the class (and any outer classes, if any). In general, in an import statement like:
everything except the last dot-separated field is the package name (
foo.bar.baz
) and the last field is the class name (MyClass
). In your example,java.util
is the package name andScanner
is the class name.The process is actually a bit more complicated, as inner/nested classes and interfaces may be involved, but you get the idea.