I had a conversation with a co-worker last night, who was trying to convince me that Java, unlike PHP, is always gaining in popularity, so should be used instead.

Luckily, I’m not a person who believes everything that I’m told, no matter how convincingly, so I decided to go looking.

The most recognised index for this kind of thing is the Tiobe Programming Community index (the TPC). here

According to that, Java is, indeed the most popular language, but it is in-fact losing popularity, while PHP is in-fact gaining.

From a numbers point of view, Java has dropped from 26% in 2001 to 21% in 2008, while PHP has gained from 2.4% to 9.89% - more than 4 times as popular as it was in 2001!

And so, I think I’ll stay with PHP. I personally believe Java is only useful if you are working in an already Java environment - otherwise, you are just hurting yourself.

On another note in the Java vs PHP game - we wrote an application a while back in both PHP and Java, and it turned out that the Java was faster. However, the PHP was written in MVC using the Zend Framework. It is well known that ZF is slow (particularly if you use Zend_Loader), so this was not really a fair comparison.

11 Responses to “popularity of php vs java”

  1. John says:

    I know that this is an ancient post, but I feel a bit compelled to reply.

    I currently code in both Java and PHP and I do agree with your assessment. My question is, did you feel that the performance gained by the Java application was so great that it was worth th effort or was it negligible?

    Also, how many users are using each application? Do you feel that PHP applications can scale as well as JEE 5 apps if written correctly or is there something that could possibly hold a PHP application from scaling as well in an enterprise setting?

    Just really curious as I like coding Java, but there just seems to be so much more one has to do in order to develop, test and deploy a JEE app.

    Thanks,
    John

  2. Kae Verens says:

    not that ancient - not even two months old yet!

    The performance gained was noticeable, but as I said in the article, that could be because the PHP version was written in ZF, which is notoriously slow. I think the effort of writing CGI in Java versus PHP tips heavily in PHP’s favour - PHP is simply so easy to code in that doing anything in Java should require proof that it will be better before you start work.

    The work has not been tested in a user-heavy environment.

    I feel that PHP applications can scale if written correctly. Good usage of caches, careful optimisation and reduction of database and file queries - all of these will help reduce the load on the server.

    I think the only thing that can reduce the scalability of PHP is that there is a startup cost for each script in most cases as the files need to be compiled. You can reduce or eliminate this by using a compilation engine, such as Zend, which pre-compiles the PHP. Also, replace home-grown templating solutions (the V in MVC, for example) with Smarty.

    In the end, though, it’s down to choice - if you like coding in Java, then stick with it. Every language has pros and cons.

    My personal grudge against Java is that I remember what it was like in the late 90s. Every site that used JSP /crawled/. This appears to have been corrected over the years, but in my mind, Java will always be a language intended for graphical applications, and not web applications.

  3. John says:

    Thank you for the prompt reply Kae.

    I’ve been doing more coding lately in PHP mostly due to the fact the Zend framework has renewed my interest in PHP. Where your grudge against java is based on past experiences, mine lies with what I perceive as more “work” to get the Java application server, configured, and up and running. Its usually not too bad, but by the time, you finish adding in all of the extra libraries, build paths, ant scripts, etc I feel like I spent very little time getting the coding task completed.

    PHP feels “lighter” to me and allows me to spend my time designing, developing and testing applications. Oh dear me, I actually enjoy coding again! :-O

    Thank you once again for the response.

  4. James says:

    so,

    I’m about as brand-spanking as they get to all of this, and am really trying to figure out a few things. I’ve rounded the corner from designer to developer, and I’ve picked up a book on psp, trying to sound it out. I had believed that the major differences ‘tween java and psp were the client vs server ones, yet I now find that speed is also a consideration? given that what I am intending to do is (at least for now) fairly basic dynamic pages, is there any reason I should consider java? also, how different are they? should I attempt to learn them simultaneously?

    I currently teach fireworks, photoshop and dreamweaver, so I know my way around both a keyboard and a mouse, so to speak….

  5. Kae Verens says:

    @James, good question.

    The speed issue only arises when you are building large (very busy) websites. This is usually not the case, so speed is not usually an issue.

    A beginner programmer will not be asked to write the next Wikipedia (which is written in PHP, by the way), so there are a few years of development where you can safely use whatever language you want - it’s not a crucial choice.

    That being said, I don’t recommend using Java for web development - especially when coming from a static design background. Java is too much of a contextual shift - you (and anyone else, for that matter) would be overwhelmed with the statrling difference in approach.

    PHP, however, is designed as an embedded language. You can start off by writing your web site as usual and just popping in a small bit of PHP wherever it makes sense. This is the opposite of Java, where Java involves writing the entire site with Java in mind (a very anti-intuitive approach, when you are doing small websites).

  6. Steve says:

    I’ve been doing some research on which language is better, and I hear arguments for each side. I’ve been considering teaching myself PHP, but I’ve heard that there are security problems with PHP that you don’t have with java. Is that true? Is Java a more “secure” language?

    What are the biggest pros and cons of each language?

    Sorry for all the newbie questions.

  7. Kae Verens says:

    I hear a lot about these supposed security problems as well.

    To be honest, I believe these rumours are based on two facts:
    1. there were security problems in earlier (PHP3, PHP4) versions and some people have not bothered updating their facts to see those problems have been fixed already in PHP5 and PHP6
    2. a lot of the perceived problems are problems with programmers - not the language. Because PHP is such an easy language to learn, it can be a tempting entry language for some very bad programmers who simply could not be bothered with secure programming.

    As long as you are a good programmer and aware of problems such as SQL injections, etc, you will do fine. These problems exist in all languages, including Java. PHP is more permissive, though, and will let you make your mistakes.

    the pros and cons are really out of my scope - personally, I like PHP for its ease of use in contrast to Java’s unfriendliness and strictness. On the other hand, I kind of like that Java forces you to be “type-safe”, but then again, I like that PHP lets you type-cast variables easily if you want to.

    Which language you use is really up to you. I can only offer my own opinion - PHP is safe and fast to work in if you are an attentive programmer, and Java is an annoying brute of a language which i would not ask /anyone/ to use for web development.

  8. Rix Sanford says:

    I appreciate you comments on both side of the coin. I agree that, like the comparison of Visual C++ and Visual Basic programming, as languages, these two are very similiar in their fundamental characteristics. PHP, being the Visual Basic type language is easy to pick up and yet very powerful in the right hands. I believe, just like VB, it can handle 80%+ of the jobs needed at less then half the time to develop. What you lose in raw speed of execution (mostly in interpretation) is truly negligible for most applications.

    I didn’t see that you had made a comment on the client-server argument of Java over PHP. Now, I am relatively new to both languages, but definately see that there may be issues with trying to write a thin/think client in PHP as where Java seem to be well equipped to do so–given its message-driven been architecture. So there is an example where Java should be decided on over PHP. However, you did cover yourself by saying that you wouldn’t use Java for web development.

    I was actually shocked to see how easy it was to have a data driven page in PHP, and am STILL learning how to do the same thing in Java. I suspect I will be spending a lot more time understanding the concepts of data-driven applications in Java. In that regard for small - medium sites, I can’t see Java as a good choice for developemnt of web applications.

    Thank you again for your article!!!

  9. Kae Verens says:

    Rix, hi! I didn’t comment on client-side code at all, as I was discussing the server-side “CGI” aspect of the languages.

    As you know, PHP has no place on the client-side anyway, so there is no comparison to be made.

    However, that is not to say that Java has any place in a browser either! A look at some articles shows that Flash is more available than Java, and that Java is not appropriate for most cases where a client-side language is needed.

    The one use-case I can think of where Java would dominate client-side is in interaction with the hardware of the machine. File-editing, encryption using hardware-based fobs, etc, cannot be done in Flash (as far as I know) and definitely not JavaScript. It’s difficult even in Java, and requires knowledge of security-signatures, so is not for the faint-of-heart. Even here, though, it’s funny that the only Java you should ever write for a client is when something security-based (and therefore intricate and complex) is needed. This means that you should only write Java on the client if you are an expert and able to confidently state that your programs are secure.

  10. Mr. A says:

    my 2 cents.

    In my opinion a decision must take into account security and scalability. Java is not just servlets and JSP. EJBs are an essential feature of Java. Also, with frameworks like Struts, Java ServerFaces, Hybernate, Velocity, things look pretty much in favor for Java for any serious developers. Finally, strong application architecture requires separation between business logic and user interfaces. Java offers this at several layers, starting from java beans, all the way to a full MVC architecture (e.g. struts) or again, EJBs.

    In conclusion, and without offending anyone, we are comparing apples and oranges! If you are to design a simple web app with a contact us form and perhaps a registration form, then PHP will to the trick, but for any other app where customer sensitive info or a large number of transactions is handleded, then JAVA is the way to go!!!

    Regards,
    Rob.

  11. Kae Verens says:

    Absolutely - there are vast differences between PHP and Java, and each has different strengths to exploit. You argument is that Java is great for building large enterprise applications, which i think I commented on earlier (in your agreement).

    Java is a more “all-round” language, and is a good choice for example if you were in a controlled environment and require programming in the client, on the server, and even in the background running tasks.

    The number of frameworks is not really important - PHP has its own share of frameworks as well, some of which are also MVC. MVC has nothing to do with the language, so that’s not really a pro-Java argument.

    PHP is well-capable of handling more than just a contact form or registration form… I fail to see what Java can do that PHP can’t, in the context of data handling and customer sensitivity. If you really think that PHP cannot be trusted to handle large sites, then I think you should avoid using Facebook, Yahoo, Wikipedia, Flickr, etc.

    As I said earlier, scalability and security are not inherent in the language you choose - good programs are written by good programmers.

Leave a Reply