Table of contents
In short the answer is that it is both. Before knowing this I thought that programming languages were either interpreted (like javascript,python etc.) or compiled (like C,C++ etc.). In java when you write code the following happens :-
- The source code is compiled by the java compiler and converted into bytecode.
- It is then interpreted and executed by the JVM(Java Virtual Machine).
So as our code is both compiled then executed we can easily say that java is both compiled as well as interpreted languages.
Advantages of JVM
There may be questions in your mind as to why go the extra step to compile then iterpret and then execute the code.
This is done to eliminate platform dependence. Once the source code is compile and converted into bytecode then that bytecode can run on any platform which supports java i.e. we don't need to compile the code everytime we run it on a new platform. This principle is known as WORA(Write Once Run Anywhere) and this is what makes the java programming language stand out from the rest.