Short answer
The Java compiler requires that a public top-level class live in a file of the same name (Order in Order.java), so tools and the class loader can locate a class predictably from its name.
Explanation
If they do not match, javac reports an error. Non-public top-level classes do not have this restriction, which is why small demo files sometimes use a package-private class to avoid the filename constraint.
Common mistakes
- Thinking every class must match its file name — only the public top-level class must.
- Putting two public top-level classes in one file.