I\'m learning Java and the following things are a bit confusing for me. What I understood is:
Java Compiler → The Java compiler just conver
At the end, even in an interpreter the machine code that is equivalent to a bytecode instruction gets run, it just happens more indirectly. Think of it like a piano. A CPU is like a player piano. A compiler punches holes into a strip of paper, which you then run on the piano. Using an interpreter is essentially placing a human-like machine in front of the piano who reads the sheet-music and pushes the keys on the piano. In the end, the same chords sound out, but there's an additional level of indirection.
Yes. Pretty much.
As you mention, Java was touted as "compile once, run anywhere". So the bytecode is an important feature to deliver that promise. The reason why it doesn't get compiled when it arrives on your computer is a practical one: Compiling is slow. Usually, it happens at the software developer's. If every Java application you launch was compiled the first time, you would be waiting a while.
Since most programs do not get run completely (there are branches that aren't taken, menu items you never choose etc.), it is usually faster to compile the parts that are needed, as they are needed. It also saves on disk space, as otherwise you'd have two copies of every program on your computer.
That said, you're not the first one to wonder about this, and in fact some people write their programs in Java, but use a compiler to actually generate executables from them. Java(-to-native) compilers exist, they're just not the common use case, because many people at that point use portable C or C++.