It knows by the first method called when run. An application starts with a
call to the main()
method, while an applet starts with a call to the
init()
method. (It's an Applet. It's an Application.
It's both!, page 520 (7th ed.) or 532 (8th ed.))
The answers, in no particular order and approximately verbatim:
The trick is recognizing that resource files are not class files and can't be handled in the way that class files are, particularly with respect to location and the class path. It's true that resource and class files can be combined in the same jar file, but they can also be placed in separate jar files. Something more than jar files is required.
The class loader is the missing piece. It remembers the packages from which
it loads classes and assumes that a resource requested by a class is found in
the same package as the class. This is why class instances loading resources
have to use the getResource()
method associated with the Class class. Page
529 (7th ed.) or 498 (8th ed.).
The answers, in no particular order and approximately verbatim:
javac
.
import anyprog.*;
will bring this resource into the class file.
This also requires the resources to be in the class path.
This page last modified on 31 March 2008. |
|