Let's see what happens when the Compiler and the JVM come together to discuss the topic "Who is more important ?" 😝
The Java Virtual Machine -
What, are you kidding? HELLO. I am Java. I’m the one who actually makes a program run. The compiler just gives you a file. That’s it—just a file. You can print it out and use it for wallpaper, kindling, lining the birdcage whatever, but the file doesn’t do anything unless I’m there to run it.
The Compiler -
I don’t appreciate that tone. 😡
The Java Virtual Machine -
And that’s another thing, the compiler has no sense of humor. Then again, if you had to spend all day checking nit-picky little syntax violations...
The Compiler -
Excuse me, but without me, what exactly would you run 🙄? There’s a reason Java was designed to use a bytecode compiler, for your information. If Java were a purely interpreted language, where—at runtime—the virtual machine had to translate straight-from-a-text-editor source code, a Java program would run at a ludicrously glacial pace.
The Java Virtual Machine -
I’m not saying you’re, like, completely useless. But really, what is it that you do? Seriously. I have no idea. A programmer could just write bytecode by hand, and I’d take it. You might be out of a job soon, buddy. 😄
The Compiler -
Excuse me, but that’s quite an ignorant (not to mention arrogant) perspective. While it is true that —theoretically—you can run any properly formatted bytecode even if it didn’t come out of a Java compiler, in practice that’s absurd. A programmer writing bytecode by hand is like painting pictures of your vacation instead of taking photos - sure, it’s an art, but most people prefer to use their time differently. And I would appreciate it if you would not refer to me as “buddy.”
The Java Virtual Machine -
(I rest my case on the humor thing.) But you still didn’t answer my question, what do you actually do?
The Compiler -
Remember that Java is a strongly-typed language, and that means I can’t allow variables to hold data of the wrong type. This is a crucial safety feature, and I’m able to stop the vast majority of violations before they ever get to you. And I also—
The Java Virtual Machine -
But some still get through! I can throw ClassCast- Exceptions and sometimes I get people trying to put the wrong type of thing in an array that was declared to hold something else, and—
The Compiler -
Excuse me, but I wasn’t done. And yes, there are some datatype exceptions that can emerge at runtime, but some of those have to be allowed to support one of Java’s other important features— dynamic binding. At runtime, a Java program can include new objects that weren’t even known to the original programmer, so I have to allow a certain amount of flexibility. But my job is to stop anything that would never—could never— succeed at runtime. Usually, I can tell when something won’t work, for example, if a programmer accidentally tried to use a Button object as a Socket connection, I would detect that and thus protect them from causing harm at runtime.
The Java Virtual Machine -
OK. Sure. But what about security? Look at all the security stuff I do, and you’re like, what, checking for semicolons? Oooohhh big security risk! Thank goodness for you!
The Compiler -
Excuse me, but I am the first line of defense, as they say. The datatype violations I previously described could wreak havoc in a program if they were allowed to manifest. I am also the one who prevents access violations, such as code trying to invoke a private method or change a method that – for security reasons – must never be changed. I stop people from touching code they’re not meant to see, including code trying to access another class’ critical data. It would take hours, perhaps days even, to describe the significance of my work.
The Java Virtual Machine -
Whatever. I have to do that same stuff too, though, just to make sure nobody snuck in after you and changed the bytecode before running it.
The Compiler -
Of course, but as I indicated previously if I didn’t prevent what amounts to perhaps 99% of the potential problems, you would grind to a halt.
The Java Virtual Machine -
Oh, you can count on it. Buddy.
🙂 🙂 🙂 😀 😃 😄 🙂 🙂 🙂 😀 😃 😄 🙂 🙂 🙂 😀 😃 😄 🙂 🙂 🙂 😀 😃