In the earlier days programming was not as easy as it is now, at that time the codes were written in Binary format.
For example: The word “hello” in binary code is: 01101000 01100101 01101100 01101100 01101111 – you can verify that with the binary translator and the same code with python will be print("hello").
History of Programming
What is meant by Compiler ?
As we saw in the history of Programming that how a binary code to output hello was 01101000 01100101 01101100 01101100 01101111 is tried to make easy by just using print("hello").
To make this possible something should be going on between the the python code and computer to make it understand this High Level language. Here the compiler comes, In short, a compiler converts a program from a human-readable (Example: Python Code) format into a machine-readable format (Example: Binary Code).
The High Level Code is called the Source Code and the basic machine code translated by the compiler is called Object Code, which the processor can "digest".
A Compiler is a Computer program (Set of Instructions) that is responsible for changing programmed code (Source Code) into a more basic machine language code (Object Code) which is easy to read and understand by the computer itself.
How does the Compiler Work ?
As to how a compiler works, that is indeed complicated. There are books and university courses on the subject. I will attempt to briefly outline the main stages of the process, but this will be a very cursory overview.
Lexing - break up the text of the program into "tokens". The tokens are the "words" of the programming language, such as identifiers (keywords, variable names, function names, etc.) or operators (=, *, &, etc.).
Parsing - convert the sequence of tokens into a parse tree, which is a data structure representing various language constructs: type declarations, variable declarations, function definitions, loops, conditionals, expressions, etc.
Optimization - evaluate constant expressions, optimize away unused variables or unreachable code, unroll loops if possible, etc.
Compilers go through the whole code at once and then compile the whole source code code unlike Interpreter which goes line by line.
Translate the parse tree into machine instructions (or JVM byte code). Again, I stress that this is a very brief description. Modern compilers are very smart, and, consequently, very complicated.