Published by nick on 24 Feb 2009 at 10:22 am
PHP vs Java vs C/C++ for web applications
From Incremental Operations Blog, this call stack shows the layers involved in a [typical?] Java stack.
To be fair, this is not necessarily Java itself, but poorly written Java code. But based on my experience, this type of excessive architecture is accepted best practice in the Java world, and the architecture astronauts seem to gravitate to this technology.
The original pipe dream of Java was "build once, run anywhere". Since that hasn’t exactly materialized, Java is the bastard step child of programming. It doesn’t really fit in anywhere. It is neither high performance nor robust (C/C++), nor easy to program in (PHP/Python/Ruby). It’s awkwardly stuck in the middle, and doesn’t do either well. If you need performance that exceeds native PHP/Python capabilities (rare in the typical work place), use a C/C++ extension for the heavy lifting, and if that’s not enough, your app is at the top 1% of performance demand, and you need to use C/C++ directly.
I’ve heard the defendants of java claim that’s faster than C/C++, but fundamentally that’s not possible, since it’s a layer on top of C/C++. Yes, JIT this and caching that, but these add complexity, which violates my #1 rule of software design, and if you added those same JIT and caching layers to C/C++, they would be even faster.
I will give Java the win in 2 areas of web based programming:
- Where development time and performance does not matter, and data integrity is the absolute most important factor. For example, stock trading and banking sites. If I was asked to build E*trade.com, I would use Java and Oracle instead of PHP and MySQL. It would take 5 times longer to do everything, and hardware/software costs would be 10x more, and the web site would be slower, but it would be the most robust solution.
- Where development time and performance does not matter, and there are advantages in maintaining advanced "state" information with transactions and rollbacks. For example - online poker sites and ticketmaster.com (advanced reservationing). I’m sure someone’s done that using Ajax, but I wouldn’t trust money flowing over such a system, and I’d recommend Java.
For the other 99.9% of web applications, scripting languages or C/C++ is a better choice, and the complexity that Java introduces is despicable, and in my opinion, making the choice for Java is doing a disservice to your company in terms of cost (both development time and hardware).
Show me a web application that scales well in Java, and I’ll rewrite it for in in PHP in half the time and it will be twice as fast and one more "9″ in availability. If it’s still not fast enough, it needs to be done in C.
I am not always popular with this argument. Quite a few of my developer peers, whom I respect, have strong pro-java arguments. I have a bet with one of these Java ninny’s - I think that Java will be less prevalent in 5 years than it is now, because of it’s excels-at-nothing nature. There is a bottle of expensive tequila riding on this, so I expect to be right. We’ll see.

Mike on 23 Mar 2009 at 6:33 pm #
Build once, run anywhere works excellent in many cases, Web applications as an example. Java is not actually "a layer on top of C/C+". JIT has absolutely nothing to do with design "complexity"… Etc…
Blogmarks pour le 25/03/2009 » Glagla Dot Org - Le blog sans prétentions d’Olivier Mansour on 25 Mar 2009 at 12:07 am #
[…] Tech Your Universe » PHP vs Java vs C/C for web applications […]
jistr on 01 Apr 2009 at 9:04 am #
I’ve done most of my work in C++, Java and PHP so far. I must say this is very poor, blindly biased blog post. You obviously have no idea what you’re talking about.
Making multiplatform applications in Java is as easy as it can be.
For anything big involving web AND desktop applications connected together, Java is the way to go, otherwise you’d have to write parts in PHP/Python (for web parts) and C++/Python (for fast desktop/server parts), but having to integrate these two into one working thing would be so painful that it would blow your budget to the sky. As I wrote, Python could be used for this too, but corporations usually do not choose it because it’s API is changing way too fast and Java is better at performance + offers more advanced features anyway.
Alex on 14 Jul 2009 at 7:14 am #
Regarding the size of the Java stack. Those various APIs and frameworks are there to make complex coding and maintenance easier. It would be the same size in ANY language. Compare it with the .Net framework to be fair. Java has the richest set of libraries and frameworks of any language.
Regarding the speed of Java, I understand that web server software runs continuously without restarting. Most of the Java classes would be compiled by the JIT compiler to native machine code and remain so. Just as fast as C, not interpreted
So servers is where Java really shines and with ease of maintenance PLUS plateform independence and ONE code base.
I’m writing music desktop software in Java using Eclipse. It has a snappy and beautiful score notation interface using Java 2D. For music playback, I get enough timer resolution under Java 1.4.2 to reach an older installed base. Under 1.5, there’s even higher resolution available and updated threading classes.
My application runs flawlessly on Windows and on my old 867 Mhz Mac with no tweaking required so far. I have not tested Linux yet.
It can play 32th notes on my old machine!
Every API and language has its intricacies. With Java, you must learn Design Patterns to appreciate much of the Java API, like Swing for example. OOP Design Patterns make my coding much cleaner - it would in any OOP language. Now I pickup new parts of the Java API quickly. It is quite elegant in comparison to other APIs.
My application IS restarted continuously and it is fast even if byte codes are interpreted.
Tiago on 19 Dec 2009 at 8:46 pm #
"For anything big involving web AND desktop applications connected together, Java is the way to go, otherwise you’d have to write parts in PHP/Python (for web parts) and C++/Python (for fast desktop/server parts), but having to integrate these two into one working thing would be so painful that" […]
And If we use Python for both, web and desktop/server parts? We will have big problems to integrate these?
I think not.
I like Java, but when we are willing to leave out some maintainability to reach more development speed and similar or better performance, Python is the way to go.