In PHP, we have:
<?php include 'external_file.php'; ?>
Whereas in Java, you have imports:
import javax.servlet.http.HttpServlet;
It is to my understanding that PHP includes simply dump the contents of the external file into the file that contains the include statement.
My gut feeling is that Java handles these includes/imports differently than PHP. What are the key differences?
PHP’s include is pretty much the exact same thing as having literally cut/pasted the raw contents of the included file at the point where the include() directive is.
Java’s compiled, so there’s no source code to “include” – the JVM is simply loading object/class definitions and making them available for use. It’s much like the
#includedirectives in C. you’re not loading literal source code, just function definitions/prototypes/fingerprints for later use.