title: Role of Compiler and JVM in java?
body: <p>I am new to java and bit confused about the role of compiler and JVM . I have read couple of resources and to name few</p>
  
  <ol>
  <li><a href="https://www.quora.com/What-are-the-functions-of-Java-Compiler" rel="nofollow noreferrer">What-are-the-functions-of-Java-Compiler ?</a></li>
  <li><a href="https://stackoverflow.com/questions/7674839/is-the-jvm-a-compiler-or-an-interpreter">Is the JVM a compiler or an interpreter?</a></li>
  </ol>
  
  <p><strong>Compiler</strong>
   As i save the file .java file in system, computer internally saves it in bytes 0 and 1's. I understand compiler is validating whether written java program
  confirms to java standard or not. If not throws the error otherwise jenerate the class file. </p>
  
  <p>My question is what is need of generating .class file. 
  Can't 
  JVM interpret it directly (from bytes generated corresponding to .java file) without needing .class file? Does compiler(javac) do any  kind of optimization here ?</p>
  
  <p><strong>JVM :-</strong> This question is other way around. Can't compiler generate the byte/machine code which can be interpreted by CPU directly? so why JVM is needed here ?
  Is  JVM required to interpret the byte code specific to platform for example windows or linux ?</p>