How Does Apex Work?
All Apex programs run entirely On-Demand on the Force.com Platform. First, the platform application server compiles the code into an abstract set of instructions that can be understood by the Apex runtime interpreters. The compiled code is stored in metadata. When the end-users trigger the execution of Apex by clicking a button or the VisualForce page the application servers retrieve the compiled instructions from the metadata and send them to the runtime interpreter before returning the result.