This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
When a source code is written in java, APIs are used at that time by importing the package. Once source code is compiled and byte code is created, thats the one installed on servers. So everything needed now is the JRE to execute this byte code, whenever this code is invoked. So even if there is no API installed on application server, as long as JRE is there, this code will be executed. IS it correct ? So where is the need of APIs on application server ?
I'm not sure what you mean by an API. If you mean a jar containing other classes, it is still needed as your code just links to those jars. If you mean the source code that you just compiled, you don't need it since you have the .class files.
A source code is written using package imported in the code on the desktop. When this code is compiled, doe the compiler just check the availability of package on the desktop and compile the code or does it actually import the package at compile time ? If package is imported in the code and byte code is created, does the application server need only JRE or does it still need all the packages imported in the source code ?
If packages are not imported in the code at compile time, then all the packages will be required o the server in order to import tyhem at runtime.
My confusion is at what point of time , is the package imported in the source code ? Do these packages need to be on both the machines where source code is created and where byte code is deployed ?
In case of servlets, does the APIs imported in the code need to be on application server too ? Or does the bytecode have all the required APIs imported in it when source code is compiled ?
Please excuse the terminology used. As I am myself not clear and trying to get the whole idea how application server works and where these APIs need to be.
1) Are these definitions or methods used from the imported package or class, are they used in the source code at compile time ? If no, then do these packages need to be available on the machine where the source code is created and compiled ?
2) If these methods in the source code from imported package are used at the runtime of bytecode, where bytecode is deployed (mostly application server)then these imported packages and APIs used in the code should be available on the application server.
So are these packages need to be available on both the machines where source code is created and where byte code is run ?