image-ru-00-18

"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."