In developing a web application that will handle credit cards, purchases, digital downloads, is there any real world benefit to using Java over PHP?
This will be a store that sells digital downloads.
In developing a web application that will handle credit cards, purchases, digital downloads, is there any real world benefit to using Java over PHP?
This will be a store that sells digital downloads.
There's nothing you can't do in one that you can do in the other. Pick whichever one you're most familiar with. Thats far more important than any alleged technical advantages. The less important differences are:
Edit: Are you really arguing Java doesn't have a lot of boilerplate code? Seriously? I'll give you one example: reading a file into a string.
Java:
public String readFile(String fileName) {
StringBuilder s = new StringBuilder(4096);
BufferedReader in = null;
try {
in = new BufferedReader(new FileInputStream(file));
char buf[] = new char[4096];
while ((numRead = in.read(buf)) != -1) {
String chunk= String.valueOf(buf, 0, numRead);
s.append(chunk);
}
} catch (IOException e) {
// handle
} finally {
if (in != null) { try { in.close(); } catch (Exception e) { } }
}
return s.toString();
}
PHP:
$s = file_get_contents("filename.txt");
Beyond that, look at the boilerplate hashCode()
, equals()
, toString()
and getter/setter copying code that ends up in most Java Web applications.
Java has tons of enterprise-grade support, a lot more than PHP has. You have distributed transactions, lots of database drivers, message queues, persistence managers like Hibernate and iBatis, the Spring Framework, templating engines, web services support, and on and on. There are a lot of high-performance application servers like Glassfish, JBoss and WebLogic. So you should consider Java over PHP in my opinion, unless your application is small-scale has small-scale e-commerce needs and you already feel comfortable with PHP.
For what it's worth, this was advice given to me last year by the VP of Engineering at a large North American e-commerce site.
Update: Java also wins on raw performance, about 30x faster than PHP according to these benchmarks (which are probably not using opcode caching, see comments).
Update: A take on Java from highscalability.com. It emphasizes the fact that Java the language is less important than Java the platform and Java the community. Lots of mature tools to choose from, a lot of people working on it. Even lots of spiffy new JVM languages that you can use along with Java (Scala, JRuby, Groovy, Clojure, Jython and so on). Examples of large sites using Java fully or partially include Fotolog, Amazon, E-Bay, Flickr, LinkedIn, GoogleTalk.
Browsers do not care if the HTML they see was generated by PHP or Java, so the differences are pure backend.
You should generally go with the language you know already, as the amount of work needed to learn another software platform "well enough" e.g. Java with any given web framework will be rather high. It is up to you to decide if there is enough code needing to be written to get your finished product to warrant even thinking about it.
My personal opinion is that Java is the stuff used to build cathedrals. Takes quite a while to build, but they stand for centuries. If that is what you need, then go for Java (and learn it well). If not, then choose the language you know the best.
I built a e-commerce application in nine months (www.perqworks.com) with the PHP framework Symfony (symfony-project.org) and the ORM Doctrine knowing very little about server-side code or database design. Why I believe PHP was the right choice is:
Now that the application is written and I have some hindsight, I wonder what the end product and experience developing the app would have been with Django, Rails, or Java. What I have concluded is that the difference between the major web development languages is not the sum of their small differences, but the skill at the programmer to write smart, efficient code.