CodeGym /Courses /New Java Syntax /What are compilers?

What are compilers?

New Java Syntax
Level 1 , Lesson 5
Available
What are compilers? - 1

"Hi, Amigo. My name is Professor Hans Noodles. I'm head of the Scientific Council here on the Galactic Rush. I also oversee our efforts to teach you Java programming."

"Hello, Professor Noodles."

"I'd like to explain to you why Java is a very cool programming language."

"You will hear more than once that Java's unmatched advantage is its platform independence. What is that and what's it for, you ask? Let me take a roundabout approach."

"A computer can execute only the simplest numerical commands. When training dogs, we use commands like 'Heel', 'Shake', etc. to make a dog do something we want it to do."

"For computers, numbers play the role of such commands. Every command is represented by a certain number or code (sometimes called machine code)."

"But it's really hard to write a program using only numbers, so people invented programming languages and compilers. A programming language can be understood by both humans and compilers. A compiler is a special program that converts a program written in a programming language into a series of machine codes."

"A programmer usually writes a program in a programming language and then runs a compiler, which turns the program code files written by the programmer into a single file with machine code – the final (compiled) program."

  • Program in C++
  • Compiler
  • Machine code

"The resulting program can be executed by the computer immediately. The bad news is that the code of the final program strongly depends on the processor and operating system. This means that a program compiled for Windows will not work on an Android smartphone."

"So, if I write a program and compile it for Android, it won't work on Windows?"

"Exactly."

"I see."

"However, Java uses a much more innovative approach."

  • Program in Java
  • Java compiler
  • Special platform‑independent code (bytecode)
  • JVM
  • Machine code

"A Java compiler doesn't compile all the classes into one machine-code program. Instead, it compiles every class independently and, what's more, not into machine code, but into a special intermediate code (bytecode). The bytecode is compiled into machine code when the program is started."

"So, who compiles the program into machine code when it's being executed?"

"There is a special program called the Java virtual machine (JVM). It must be started first when you need to run a bytecode program. The JVM will compile the bytecode into machine code before the program is executed."

"Interesting. Why would that be necessary?"

"It's a very powerful approach and one of the reasons for Java's total domination."

"This approach allows programs written in Java to be run on virtually any device: computers, smartphones, ATMs, toasters, or even credit cards!"

"Cool!"

"This approach has many advantages. It's why all Android programs are also written in Java. Thanks to the quick growth of the mobile phone industry, Java dominates the following areas of programming:

1) Enterprise: heavy server-oriented applications for banks, corporations, investment funds, etc.

2) Mobile: mobile development (smartphones, tablets), thanks to Android.

3) Web: PHP is in the lead, but Java has captured a solid share of the market.

4) Big Data: distributed computing in clusters consisting of thousands of servers.

5) Smart devices: programs for smart homes, electronic devices, IoT refrigerators, etc."

"Java isn't just a language, but a sort of ecosystem: millions of ready-made modules you can use in your program; thousands of online communities and message boards where you can get help or advice."

"The more you write programs in Java, the more answers you will find to the question 'Why Java?'. That's it for today."

"Thank you, Professor. This was really interesting and inspiring."

Comments (201)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Anonymous #11437070 Level 2, Sacramento, United States
3 June 2025
ifykyk
Tariq Kichawele Level 1, United States
29 May 2025
kjkjkjk
Kathir Viswa Level 2, CodeGym University in India, India
26 May 2025
i love the way of teaching style
Kiwi Level 2, Mexico
14 April 2025
Wow :0 I was just learning Java to mod Minecraft haha Didn't know it was so important; is awesome!!
Anonymous #11640470 Level 1, Los Angeles, United States
1 April 2025
Amazing!
Moshood AHMED Level 2, Nigeria
7 February 2025
great lesson learnt.
Anonymous #11619446 Level 2, Kolkata, India
31 January 2025
Thank you, Professor. This was really interesting and inspiring.
larsintech Level 16, Switzerland Expert
4 January 2025
The compiler checks the syntax and translates source code into Java Bytecode (intermediary). The Interpreter (JVM) in turn interprets the Bytecode and translates it into platform independent machine code.
Ruchika Jadhav Level 2, CodeGym University in India, India
12 November 2024
jvm
Jorge Arturo Sanchez Chan Level 2, Culiacan, Mexico
30 September 2024
Una JVM puede estar en un sistema operativo y también en un hipervisor de un servidor?...