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
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....
How are animal behaviors measured and interpreted?
How are animal behaviors measured and interpreted? Give details.
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...
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?
Programming language: JAVA First, implement a recursive, Divide&Conquer-based algorithm to identify both the Minimum and Maximum...
Programming language: JAVA First, implement a recursive, Divide&Conquer-based algorithm to identify both the Minimum and Maximum element in an unsorted list. Second, convert your recursive algorithm to a non-recursive (or iterative) implementation. For your input, populate an "unsorted list" with random elements between 1 and 1,000,000.
Language is Java Design and write a Java console program to estimate the number of syllables...
Language is Java Design and write a Java console program to estimate the number of syllables in an English word. Assume that the number of syllables is determined by vowels as follows. Each sequence of adjacent vowels (a, e, i, o, u, or y), except for a terminal e, is a syllable. However, the minimum number of syllables in an English word is one. The program should prompt for a word and respond with the estimated number of syllables in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT