A simple Java Program normally undergoes following five key steps:

·         Create and Edit
·         Compile
·         Load
·         Verify
·         Execute

We have seen first three steps: Editing, Complication and Loading in the first part of this post, Phases of Java Program Execution: Part-1. Now here we examine the rest of the two phases i.e. Verification and Execution. And we also discuss few commonly occurring errors that we might encounter during our program execution.

Phase 4: Bytecode Verification

In this Phase, as the classes are loaded, the bytecode verifier inspects their bytecodes to make sure that they’re valid and does not violate Java’s security restrictions. Java reinforces very strong security to make sure that Java programs coming over the network do not damage our files or our system (as computer viruses and worms might).

Phase 5: Execution

In the final phase, the JVM executes (runs) the program’s bytecodes, thus performing the actions instructed by the program. In early Java versions, the JVM was   a simple interpreter for Java bytecodes. Because of this, most Java programs execute slowly,since the JVM would interpret and execute one bytecode at a time. Some modern and advanced computer architectures can execute several instructions in parallel. Nowdays JVMs ususally execute bytecodes using a combination of interpretation and so-called just-in-time (JIT) compilation. In this process, the JVM examines the bytecodes as they’re interpreted, searching for hot spots parts of the bytecodes which are meant to execute frequently. For these parts, a just-in-time (JIT) compiler— called as the Java HotSpot compiler—converts the bytecodes into the underlying computer’s machine language. When the JVM encounters these compiled parts again, the quicker machine-language code executes. Thus Java programs actually go through two compilation stages—

·  Firstly, one in which source code is translated into bytecodes (for portability across JVMs on different computer platforms) and

·   A second in which, during execution, the bytecodes are translated into machine language for the actual computer on which the program executes.

Common Problems Which May Occur at Execution Time

Programs might not work on the first attempt. Each of these preceding phases can fail due to various errors .For instance, an executing program might try to divide by zero ( which is an illegal operation for whole-number arithmetic in Java). This would result the Java program to display an error message. If this happen, we need to return to the edit phase, make the necessary corrections and proceed through the remaining phases again to determine that the corrections fixed the problem(s). [Note: Most programs in Java input or output data. When we say that a program displays a message, we normally mean that it displays that message on our computer’s screen. Messages and other data may be output to other devices, such as disks and hardcopy printers, or even to a network for transmission to other computers.]

Errors such as division by zero occur as a program runs, so they’re called runtime errors or execution-time errors. Fatal runtime errors cause programs to terminate immediately without having successfully performed their jobs. Nonfatal runtime errors allow programs to run to completion, often producing incorrect results.

  Modified On Dec-16-2017 02:24:51 AM

Leave Comment