To make Java code platform independent.
Updated
If a C-programme is compiled on a particular platform, then it would produce compiled code that is capable of running only on the platform on which it was compiled. A C-program compiled on windows machine cannot be run on Linux/Unix/MacOS machines.
One of the main design goals of Java was to make the code platform-independent.
This was achieved by adding an extra step in between code compilation and code execution. That is the step of generating the 'byte code'.
Compiling a Java programme results into what is called as "byte code" file, having an extension of .class. The byte code actually contains instructions that can be interpreted by Java Virtual Machine. That is to say that 'javac' converts Java programme into a set of instructions that a JVM can understand.
JVM - Java Virtual Machine, runs on top of the OS and is implemented for each platform (OS and underlying hardware) separately.
With this design it is possible to compile a Java program in Windows machine and run the generated .class file on a Linux box, thus achieving platform independence.