5

I am searching about JVM in detail to understand the working of it and to work properly with Java programming language so, how much JVM is important for java compilation except Operating system independent.

6
  • 2
    JVM is needed to run the compiled code. The compiler is the only thing you need to compile code, JVM has nothing to do with compilation. Then again, the compiler is written in Java, so you need the JVM to run the compiler. Commented Sep 26, 2016 at 19:24
  • 1
    You can write a Java compiler in C if you want. Java won't care. Commented Sep 26, 2016 at 19:24
  • 2
    It is important as the Java compiler is written in Java. Doesn't have to be, but it is. Commented Sep 26, 2016 at 19:31
  • Why would you want to produce byte code but not use a JVM? Commented Sep 26, 2016 at 20:19
  • There is an abandoned Java compiler written in C++ (jikes.sourceforge.net), it does not depend on JVM runtime. Commented Sep 27, 2016 at 9:03

3 Answers 3

5

If using the primary compiler, Javac, you'll need a JVM.

The JVM does not affect compilation, it's only needed because the primary compiler is actually a Java program itself, and a JVM is needed to run Java programs.


Theoretically, a compiler is the only thing you need to compile Java code. In fact, the JVM knows nothing of the Java programming language, only the byte-code generated from compilers. The JVM allows your computer to run Java programs, and does not affect the compilation process.

However, Java's primary compiler was written in Java. To run the primary compiler, you need a JVM.

If you used a compiler written in a different language, you wouldn't need the JVM to compile code.

Sign up to request clarification or add additional context in comments.

Comments

-3

JVM does not compile the code, it interprets.

Java is both an interpreted and compiled language. The Java compiler ,'Javac' produces byte-code which is platform-independent. This byte-code is, we can say generic, ie., it does not include machine level details, which are specific to each platform. The instructions in this byte-code cannot be directly run by the CPU. Therefore some other 'program' is needed which can interpret the code, and  give the CPU machine level instructions which it can execute. This program is the 'JVM' (Java Virtual Machine).  Note that the JVM is platform specific.

Comments

-3

The JVM has nothing to do with compiling java code. The JVM is purely responsible for running already compiled code. There exists lots of software for compiling java code, for example, the javac compiler included in the JDK, or the integrated compilers in most IDE's, and there are seperate compiling tools such as gradle or ant.

5 Comments

The 'separate compiling tool javac' being written in Java, your answer is not correct.
That was a sentence derp on my part, I've edited the answer.
Other stuff is wrong here, too. gradle and ant are not separate compiling tools, they all rely on javac and add dependency resolution and management. All widely used and up-to-date Java compilers actually run on the JVM.
What I meant by "seperate compiling tools" was programs specifically devoted to compilation of Java code, not whether they were using the javac compiler. But, that's beside the point here, sure, javac requires the JVM to run, just like any other Java program, but you don't absolutely need it for compiling, which was what the question originally asked.
'Don't absolutely need it for compiling' unless you're using the tools you mentioned . Not making much sense here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.