PHP vs. Java … and why I hate Java
October 22nd, 2008 by Peter Glaeser |
RSS feed for comments on this post |
TrackBack URI
Java is a widely-spread programming language. It’s used for many client-based software applications (for example most of the games you’re downloading for your mobile phone) as well as web applications. Everywhere you go you find people using Java. Hardcore developers love it because the structure of the language works pretty much like their brains. But getting a larger website live using Java takes ages. Whenever you change the code you must re-compile and deploy. I think there are much better ways to run websites than this.
PHP is a programming language used primarily for websites. It’s relatively easy to learn and you can get by using dirty code, at least in the beginning. The best thing about PHP is that it is a script language. You don’t need to compile the source code which can take a long time if you’re using Java. The PHP interpreter does that for you on the fly when a script is executed. You can change the website instantly and seamlessly so that deployment isn’t really a big issue.
The beauty of Java is that it’s fast because upon execution it’s code has been translated into machine language already. PHP tends to be slower here because it has to translate the code in real time. However, I don’t think using Java instead is a good trade-off. If traffic volume and execution time of PHP-based applications become an issue I just use more servers. Nowadays it’s a lot cheaper to spend money on infrastructure than on switching a platform to Java. You can also speed up PHP big time by using Memcache.
Some of the largest social media properties on the internet have been using PHP from the very beginning: Facebook, Wikipedia, Digg. So you see, it’s possible to scale PHP-based services. You just need to do it right. My point is, if for example Facebook had been written in Java, hardly any of these optional applications would exist and its viral growth wouldn’t have happened.
To validate my point, here’s a picture I took in my room at the Novotel London Excel where I stayed for a4uexpo. I hate the fact that even the entertainment systems of hotels run on Java and do not work:



11 Responses to “PHP vs. Java … and why I hate Java”
By SVachon on Mar 21, 2009 | Reply
Your article is more on interpreted vs compiled languages. In fact, java is not compiled to machine code but into bytecode to be interpreted by the jvm. And I don’t think it takes a long time to compile java code, but I admit that it is longer than not having to compile at all. However, you don’t have to compile your Jsp pages. Pages and classes can also be hot redeployed individually on the fly, hence you “can change the website instantly and seamlessly so that deployment isn’t really a big issue.”
I think one of the main advantage of php over java is how easy it is to get an operational lamp stack so you can start working.
And finally I don’t think that showing as 404 status error page proves anything about php beign better than java. This is a developer issue, all sites can have broken links.
By Dwoos on May 12, 2009 | Reply
If you need an enterprise-level, high-performance web application, then choose Java. The fact that PHP is “easy to learn” is not relevant. The concept of implementing “dirty code” with PHP or any language is flat-out scary. For large projects, you’d better have expert developers no matter what the programming language. Also, the previous comments from SVachon are 100% accurate.
$recommendation => $java;
By Julian Kennedy on May 28, 2009 | Reply
I agree with the two comments above. When looking at enterprize applications, there are other issues which crop up. Like what happens when a low level programmer gets hold of your code. Or when the business needs to develop a complex feature. What about adding the ability to expose functionality as web services in a robust manner, without affecting application availability. Or having accurate debugging and performance statictics.
Having “dirty code” code in your any application is like having cooking oil in your Ferrari engine. And sticking one’s head in the sand with regards to enterprize issues is just shoddy.
Anybody who has worked at the enterprize level should know this. There is nothing wrong with PHP or JAVA. They were built for different reasons.
Apples and Pears my friend.
By Shah on May 30, 2009 | Reply
I have read most of these comments and still not sure to start learning more java or get to know php coding at an expert level. Am actually a masters student. We have been taught JAVA and is very boring when it comes to write codes. After Masters, my intentions to pursue a carrier in programming. Right now, I have to start my final project of web application for a shop and have only 3 months to complete it. Should I continue doing JAVA as I have learned it some how in the past 6 months, or work on PHP for it if it’s more demanding at a professional level.
cheers
By Jaime on Jul 8, 2009 | Reply
I like that java is strongly typed, that way debugging is easier, and always you know what is really happening, without too much hassle.
By kappa on Jul 27, 2009 | Reply
@Shah,
use PHP. Java is for very big projects with its advantages of good refactoring. Given the time, you must go ahead with php and use Kohana framework (MVC architecture) for good understanding and practices. This gives you a good understanding of OOP and atleast one Design pattern.
At a later stage, learn Design patterns in java (particularly adapter pattern), JSF, JPA and you are to market.
Looking even further, start learning a function/OO hybrid language like Scala which will replace java eventually. (2 years time)
Cheers,
kappa
By Jim Pixton on Sep 23, 2009 | Reply
good article on java based php framework http://www.ibm.com/developerworks/opensource/library/wa-quercus/index.html
By Memoks on Dec 1, 2009 | Reply
“if for example Facebook had been written in Java, hardly any of these optional applications would exist and its viral growth wouldn’t have happened.”
Too right.
By Nick Yeates, Baltimore, MD on Dec 23, 2009 | Reply
I have heard too many times people give the “php is not scalable to enterprise levels”, “java does enterprise well”. I dont think that I can speak to this first hand.
What I can say is, that I touched both languages and ultimately chose php for its quicker ramp up, ease of use, ease of reading, no headaches for overhead. Java functions, in the past, were hard for me to lookup, understand. Say I wanted a simple existing function that searches a string for a sub-string. It took me ages to find with java, and the code was ugly to read once implemented. Php I found the function in under a minute of searching its docs, and the code was very understandable.
I was coding very small programs for myself and my work basically, NOT enterprise or professional level. So, I always trusted what others said: PHP doesnt scale. Well, now that I have seen a .php stuck into one of the pictures at facebook…. facebook is the ULTIMATE of scaling. I mean, really you cannot scale to more users than that. There really is nothing currently higher in users that I can think of.
I think that PHP can be easy to use/learn, and dangerous to scale. But, if done right apparently, it can shoot you to the moon.
I am going to learn Python I think. It is a mix between java and php qualities. Python is more heavily object oriented and strict and enherently scalable, yet it too is script-based… it compiles as you run it. No need for go-live or compilation headaches.
By Saif on Jan 16, 2010 | Reply
My Comment is different, i am waiting for a time where database manages this better then language. once the database performance gets increased most of the programming language can do better jobs.
Its on database we have to give more concentration. Languages are only mediators.
Java and PHP. two are not good.
Why should we want to stick will an intermediate language like this better we can go for C++ or c compiled language .
Will can give high performance.
So my conclusion is,
1. Database is the main part need a good optimisation in performance.
2. Me frameworks have to be developed in c++ or c so that other can do web projects in these language. perfectly.
3. Both Database and language should have a good garbage Collection Methodology.
4. Good IDE for developement. with lots of auto generate facilities.
etc..
I am waiting for such a high performance.
By Rajnish Gupta on Feb 11, 2010 | Reply
Hi,
I am M.C.A fresher student. I had started to teach java but i don’t know market position.Someone says php is better than java for job purpose. Please tell me ..