Java Server-Side – Why Use Java Over Interpreted Language?

compilerinterpretersjavaruntimeweb

Web pages are usually tested by refreshing the page, clicking some UI component, then either writing to a debug log or adding some breakpoints in the IDE… in larger applications, unit tests are written to guarantee the output of the program, etc.

It seems like Java is an awful server-side language for a web page. You have to recompile every time you modify any line of code and pass the built EAR or WAR to the application server… something like Python or PHP (or any other interpreted language) would execute at run-time, removing the need for compilation before testing.

My question: what is the justification to using Java as a server-side language? Why is it better to use than an interpreted language?

Best Answer

There's the title of your question which is a valid one and then there is the content of the question which contains some poor assumptions and/or incorrect statements. I'll address the body first:

You have to recompile every time you modify any line of code and pass the built EAR or WAR to the application server...

Not true. First of all, technology exists for Java which allows you to modify code and have it change a running application without even restarting the application. I link to the product not to endorse it but rather as proof. I have used it and can verify that it works. Secondly, python must also be compiled. It's just when that compilation occurs. In java you do it ahead up front. In python it happens at runtime (the details may vary depending on the Python variant)

As far as why one would use a pre-compiled language, here are a few reasons off the top of my head

  • bytecode files are smaller than source files and servers (not being human) don't need source.
  • Compiling ahead of time allows you to catch syntactical errors. Why wait until you've loaded your file on the server to find out that you forgot a colon?

The rest of the reasons around why you would choose one over the other really aren't about when you compile. They tend to center around dynamic versus static code and the advantages and disadvantages between the two approaches. I would expect well written Java code to be faster than well written Python though this is a factor that can change over time in both actual speed and whether it matters.

Related Topic