Server-Site Web: Java Vs PHP

I had a conversation the other day with a fellow Software Engineer about a web-based project I want to start.  There are several advantages of these two technologies, and clearly either one would be sufficient to do the job.  As a Software Engineer who is constantly striving to improve and up my skillset, I also have to think about what technologies are going to further my career.  Developers, I would love to get a discussion going on this topic, so please leave comments. Oh, and I am purposely sticking to these technologies because I believe strongly in cross-platform tools, and these are the two top contenders in that arena.  And we’re talking server-side options.   So no whining from the .NET/Flex crowd.

Let’s look at the technical side:

Pro Java Pro PHP
  • Very scalable
  • Bountiful collection of free libraries
  • Strongly-typed, clean OO implementation
  • Many real standards that are sometimes even followed
  • Best practices for security, unit testing, logging, messaging, localization, threading,…
  • Strong compile-time checking promises fewer runtime surprises and greater optimization
  • The non-web code can be reused on your desktop, your phone, or large servers
  • Plenty of cheap or free hosting options
  • Very short knowledge ramp-up time
  • Can be much faster to prototype in
  • In general, it takes much less code to do the same thing
  • PHP is designed for the web, while Java needs JSP, Servlets, Beans, JDBC, …
  • Very low resource. Will run on an old PDA
  • You can use frameworks, cachers, etc, but you don’t have to
Con Java Con PHP
  • 65-line “Hello World”, 4 nested method calls to open a file
  • Better brush up on XML just to get it running
  • Some really bad designs/implementations, like *generics*
  • Weak typing is the Devil’s playground
  • Compile time = run time, so your users can see your errors
  • That quick-to-develop prototype often ends up as the start of your “production” code
  • OO is sorta slapped on, and not enforced at all

As you can see, there are strong merits and problems on both sides. Clearly which one to go with depends on the pain points, size, and features of your project. OK, so far not that helpful. But your personality, coding style, and “battle scars” may lead you to prefer one or the other. The quick-and-dirty or the verbose-and-clean. The rugged or the agile. The instant gratification or the surer foot.

In a way, Java is a lower-level language than PHP. PHP has many functions to do common operations that take many separate instructions in Java. Why is there no single function in Java to read in a text file? Why are there so many factories and adapters needed? You lose nothing by providing the existing Java functions with their micromanaging of the process along with convenience functions that handle common variants with few parameters.

Personally, I’ve moved pretty solidly into the Java camp over the years, but I also believe strongly in using the right tool for the job, so I don’t discount any of them (except COBOL. Buy me a drink and ask me sometime.) However, I’ve written not one, but two posts on what I think is wrong with Java (here and here), so it’s not all sunshine and roses.

Now let’s look at the career side:

Recently someone showed me a really cool feature of the job hunting website Indeed (if you’re a data geek like me). You can do searches of job trends over time, and even do some pretty complicated AND/OR logic. Good times. here we go:

As you can see, there are over 3 times as many Java web development jobs as there are PHP jobs. We have a clear winner on this front, at least. Of course all jobs are not created equal. And then there’s salaries to consider.

Career-wise, Java is two-for-two, with a 13K bump in salary.

What do you think?

I’m still torn in what to use for my project (which I’ll describe in a separate post RSN).  If it was just a matter of “I just want to throw together this functionality and get on with my life”, I would probably opt for PHP.  But I’m also doing this to stay sharp, and to have a body of work to show off, so I am leaning a little towards Java at this point.  I would love to hear other points of view, corrections, additions, or random knock-knock jokes.

Share

3 comments

  1. Hmmm… interesting dilemma and clearly there is no wrong answer. The constraints of the funding and time would weigh heavily if it were my call to make. My $0.02 is go with Java if you have the budget and time on the project. The career opportunities and staying sharp are would be the big drivers in the decision matrix.

    As for my knock-knock joke… Knock-knock. Who’s there? Flex. Flex-who? Don’t question me! I am doing it in Flex!

  2. From a programming perspective, I generally prefer Java or Perl for large projects, because they both have better support for automated testing. However, for web development, PHP frameworks tend to be more mature and easier to use.

    That said, I believe that the “correct” tool for the job is as much about what’s comfortable for the developer as what fits with the project. For example, you’re preference for a strongly-typed language—with which I sympathize—is largely just that, a personal preference, because experienced software engineers also defend loose typing as being better.

    -TimK

  3. Quote that needs to be read in the right context from the following link –

    http://java.sun.com/developer/technicalArticles/J2SE/Desktop/scripting/

    Reasons to Use a Scripting Language

    Most scripting languages are dynamically typed. You can usually create new variables without predetermining the variable type, and you can reuse variables to store values of different types. Also, scripting languages tend to perform many type conversions automatically, for example, converting the number 10 to the text “10” as necessary. Although some scripting languages are compiled, most languages are interpreted. Script environments generally perform the script compilation and execution within the same process. Usually, these environments also parse and compile scripts into intermediate code when they are first executed.

    These qualities of scripting languages help you write applications faster, execute commands repeatedly, and tie together components from different technologies. Special-purpose scripting languages can perform specific tasks more easily or more quickly than can more general-purpose languages. For example, many developers think that the Perl scripting language is a great way to process text and to generate reports. Other developers use the scripting languages available in bash or ksh command shells for both command and job control. Other scripting languages help to define user interfaces or web content conveniently. Developers might use the Java programming language and platform for any of these tasks, but scripting languages sometimes perform the job as well or better. This fact doesn’t detract from the power and richness of the Java platform but simply acknowledges that scripting languages have an important place in the developer’s toolbox.

    Combining scripting languages with the Java platform provides developers an opportunity to leverage the abilities of both environments. You can continue to use scripting languages for all the reasons you already have, and you can use the powerful Java class library to extend the abilities of those languages. If you are a Java language programmer, you now have the ability to ship applications that your customers can significantly and dynamically customize. The synergy between the Java platform and scripting languages produces an environment in which developers and end users can collaborate to create more useful, dynamic applications.

    For example, imagine a calculator with a set of core operations. Although the base calculator may have only four or five fundamental operations, you can provide programmable function keys that the user can customize. Customers can use whatever scripting language they prefer to add mortgage calculations, temperature conversions, or even more complex functionality to the calculator. Another example of this collaboration could be a word processor that allows customers to provide customized filters for generating various file formats. Examples throughout the remainder of this article will show how to use scripting to provide customizable Java applications for your customers.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.