I'm going to ask some general questions before I explain about programming languages.
1. What is a language?
Your answer - ??
My answer - A language is a communication tool between two persons, for example you're reading this because you know the language English.
2. Why do we need a language?
Your answer - ??
My answer - A language is used to fulfill our needs (requests).
Like two humans can communicate with each other with a language, a human can communicate with computer by using programming languages to fulfill needs. The program that we wrote cannot be directly recognized by the computer. Computer recognizes only machine code. So, we have to convert our program into machine understandable signals. For this purpose we are having translators.
Translator- It is a program which coverts program into machine understandable code (electric signals or pulses). There are three types of translators available.
Interpreter - Coverts only one line of the program at a time
Compiler - Coverts all lines of a program in a single step (Note: Compiler is 10 times faster than the interpreter)
Assembler - Converts assembly language instructions into machine level language.
Here I explain a sample process of compiler with C compiler. When you write and compile a program C language, the below tasks will be carried out
When we compile a program, the compiler will create a new object code (.obj) file. An object code is equivalent machine code for our program. Whenever we first execute our program, the compiler will create an executable file. An EXE file has the machine language instructions (A group of instructions that understand by a micro processor are called as instruction set) including header files also. (It directly executed without compiler). The first microprocessor in the world - 4044. Later on 8080, 8085, 8086, 8088, 80286, 80386, 80486, 80586 have been developed.
System dependent program
If a program is executable only on the computer system where it was developed - called system dependent program. All the existing languages before the invention of Java are system dependent. For example if you write a program on Windows which can't be executed on Linux. Hence, we can't use these languages to develop software which runs on internet.
Java is system independent, hence it is highly suitable for internet. Whenever we compile java source, it will create a class file. A class file contains byte code equivalent to our program. Each instruction size of a byte code is 1 byte. There are total of 220 byte code instructions available.
When we compile Java program, compiler will rewrite the program as another set of instructions. The rewritten code is said to be byte code.
JVM refers Java Virtual Machine. JVM is a program which will convert byte code instructions into machine language instructions understandable by Micro processor. Right Java program write once, later on run anywhere.
JVM is a system dependent, because it was developed in C language, where as class file is a system independent.
Question: What is the difference between class file and exe file
EXE file contains machine language instructions understandable by Micro processor, where as class file contains byte code instructions for JVM. EXE file is system dependent, where as class file is a system independent.
Sun Microsystems has developed different JVMs for different operating systems. Hence, you can write a single Java program and generate the class file which can be executed on any other operating system.