enfrptes

sendassignment@tutorspoint.com

Compiler Responsibility Homework Help

What is Compiler Responsibility?

Whenever the Java compiler converts a source code into its equivalent bytecode, it does two things:

a) It converts the source code into its equivalent bytecode statement wise and

b) It checks whether that bytecode can be properly executed by the JVM or not. i.e. if finds out whether the JVM has the proper environment or not

 
Complication error

In fact, it is the duty of the compiler to create a proper environment for the JVM to execute the bytecode. While compiling a source code if, at any time the compiler finds out that the proper environment is not there, then the compiler tries to create the proper environment. Even then, if it is not possible, then it generates a complication error.

Run-time-errors

Even though the compiler creates the necessary environment for the JVM to execute the bytecode, sometimes JVM will not able to execute the bytecode because of some errors. These errors are known as run-time errors.

Example:

Class x

{

Int a, b;

Void function()

{

System. Out. Prinn (“inside function x ()”);

}

}

Class Y

{

Int    I;

Public static void main (String args[])

{

X. x = new X ();

X.a = 10;

Function x ();

}

}

Explanation:

When we try to compile the y.java file, the compiler creates the proper environment for the JVM to execute the bytecode of the Y.class file. But in this program, we need the object of the x.class file. But the X .class file is not there on the hard disk since we have not compiled it. It should generate an error, but it will not. Instead, the program will get executed perfectly. This is possible because the compiler, as it has to create the proper environment, it compiles the X.java file to generate the x.class file and makes it available to the Y.class file for execution.