In Apache tomcat, there was a project created that included Servlets to service the incoming requests. Java class files were kept under
WEBINF\classes\com\example\web
Why do the Java files need to include “package com.example.web” statement so that their compiled classes may be kept in com\example\web folder? Tomcat container can easily locate the class files because of the Servlet mappings.
Why is this package statement necessary?
Because that’s how the language works. You specify exactly which classes you import in order to avoid ambiguities.
Imagine the common scenario when you have two classes with the same name, but different package. Which one should be picked?