• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why does Application Server need to host APIs ?

 
jignesh soni
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?

thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34860
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jignesh,
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65124
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Despite it's name, importing does not include a package's or class' code anywhere. It simply imports the definitions that are referenced in the code in the java file.

The .jar file containing the referenced code needs to be in the classpath when the code is executed.
 
jignesh soni
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65124
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My reply already answered your question.
 
jignesh soni
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still one thing is not clear.

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 ?

If possible, please answer questions point wise.

thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65124
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The classes need to be available while compiling, and the classes need to be available at run-time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic