Question

In: Computer Science

Explain how Java is both a compiled and interpreted language.

Explain how Java is both a compiled and interpreted language.

Solutions

Expert Solution

Hi,

Before getting into the question, let us first get clear with what exactly compiler and interpreter will do and what makes them different from each other.

A compiler is a computer program that converts the code written in high level programming language(like C,Java etc) into a machine code(binary i.e 0s and 1s) which computer can understand and process.

A interpreter is a computer program that converts high level programming statements into machine code(binary).

So now you might think both compiler and interpreter does the same thing. Yes, they both do the same thing but in a different way. While compiler compiles the code at once, an interpreter convers each high language statement one by one. Therefore compiler compiles the code before the execution of the program whereas interpreter conver the code into machine language during run time i.e during execution of the program.This makes comiplers work faster than interpreter.

Now that we understood the difference between a compiler and interpreter, let's get into our question. Is Java a compiler and interpreter language ?

The answer is Java is both compiler and interpreter language. The programming code written in java is saved as .java file . When a .java file is executed , javac  a java compiler compiles the .java file into a byte-code . But this byte can't be executed by the cpu because it is not native code. Now, this byte-code is then converted to an machine code by the java interpreter called Java Virtual Machine(JVM). The JVM interpreted code is a binary code and can be executed by the CPU. Therefore Java is both a compiler and a interpreter language.

Now you might come across a question. What is the use of converting the .java file to an byte-code and then interpreting to a binary code which increase the execution time of the program when it can be converted directly to an binary code using just compiler which executes program quicker?

Here comes the java's magic. A java program unlike any other programs like C,C++ etc , can be run on any operating system without changing the code nor changing the type of compiler beacause of the byte-code generated by Javac(java compiler). The byte-code can be run on any kind of operating system without changing the code by using JVM on that system. This made Java very popular languange. A single can be used on multiple systems is made possible by java by using both compiler to convert the code to byte-code and allowing this byte-code to be used across a large variety of systems without any changes by using JVM.

Hope I have answered your question.

Thank you :)


Related Solutions

explain how data are to be analyzed and interpreted
explain how data are to be analyzed and interpreted
11. What is the difference between Interpreted and Compiled program languages? Describe briefly the advantages and...
11. What is the difference between Interpreted and Compiled program languages? Describe briefly the advantages and disadvantages between these two categories of language. Under which category the language Python falls? 12. What is an identifier? List the rules for writing identifiers in Python language. 13. What is a Python statement? Give examples of different ways you can write multiline statements. Explain, with examples, the use of indentation in Python language. 14. How do you write comments in Python? How many...
A language that is interpretted can be distinguished from a purely compiled language in that... (select...
A language that is interpretted can be distinguished from a purely compiled language in that... (select all that apply) a it requires another program to run the source code at run time. b the source code is translated into another language. c the source code can be used, unmodified, to run the program. d interpretted code can be run directly on the CPU, generally.
1.   Define each of the following fundamental concepts Interpreted vs. Compiled Languages Interpretive Overhead Scripting (Procedural) vs....
1.   Define each of the following fundamental concepts Interpreted vs. Compiled Languages Interpretive Overhead Scripting (Procedural) vs. Object Orientation vs. Logic Programing vs. Event Driven Programming Paradigms Programming Libraries/Modules Command Line (Prompt) ASCII Functions Control Flow Hashes/Dictionaries List Comprehension True or False 2.   A dictionary is a random-access data structure. 3.   An array is a sequential access data structure. 4.   Using functions to isolate code is a good programming practice. 5.   Lexicographical ordering starts by comparing the first letters of two strings to determine the...
How are animal behaviors measured and interpreted?
How are animal behaviors measured and interpreted? Give details.
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data...
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data structures (queues, lists, STs, hashtables etc.) Have a unit test implemented in main(). And comment every code. Show examples from the executions. Assume that the edges defined by the vertex pairs in the data base are one-way. Question: Write a program that can answer if there is a path between any to vertices. For the vertex pairs use this as your input example: AL...
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data...
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data structures (queues, lists, STs, hashtables etc.) Have a unit test implemented in main(). And comment every code. Show examples from the executions. Assume that the edges defined by the vertex pairs are two-way. Question: First step: write a program based on DFS which can answer questions of the type: "Find the a path from X to Y" Which should result in a list of...
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data...
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data structures (queues, lists, STs, hashtables etc.) Have a unit test implemented in main(). And comment every code. Show examples from the executions. Question: First step: write a program based on DFS which can answer questions of the type: "Find the a path from X to Y" Which should result in a list of vertices traversed from X to Y if there is a path....
In JAVA, Briefly explain how objects are able to achieve both data hiding and implementation hiding.
In JAVA, Briefly explain how objects are able to achieve both data hiding and implementation hiding.
How to identify when to use super() in constructor for java language in a easy way?
How to identify when to use super() in constructor for java language in a easy way?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT