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.
现在应用程序已编写完毕,我有一些后见之明,我想知道开发应用程序的最终产品和经验会是什么使用过 Django、Rails 或 Java。我得出的结论是,主要 Web 开发语言之间的差异不是它们微小差异的总和,而是程序员编写智能、高效代码的技能。
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:
I could learn PHP code quickly at php.net
Symfony documentation and forums were very helpful
Being a virgin with SQL, Doctrine made sense and gave me some confidence that my queries were well written
The LAMP stack cost is unbeatable
It is hard to sift through J2EE, Beans, Spring, JMV, and the several other problem domains Java fills
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.
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.
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");
除此之外,请查看样板 hashCode()、equals()、 toString() 和 getter/setter 复制代码最终出现在大多数 Java Web 应用程序中。
There's nothing you can't do in one that you can do in the other. Pick whichever one you're most familiar with. That's far more important than any alleged technical advantages. The less important differences are:
PHP hosting is typically cheaper;
Java handles multithreading much better;
You end up writing a lot of boilerplate code in Java for stuff PHP has API functions for;
PHP development tends to be smoother just because there are no build and deploy steps. You click save and reload your browser;
Java has probably way more frameworks and libraries than PHP does;
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.
发布评论
评论(4)
浏览器不关心它们看到的 HTML 是由 PHP 还是 Java 生成的,因此差异纯粹是后端的。
您通常应该使用您已经了解的语言,因为“足够好”地学习另一个软件平台(例如具有任何给定 Web 框架的 Java)所需的工作量将相当高。由您决定是否需要编写足够的代码来让您的成品值得考虑。
我个人的看法是Java是用来建造大教堂的东西。建造需要相当长的时间,但它们可以屹立几个世纪。如果这就是您所需要的,那么就选择 Java(并学好它)。如果没有,请选择您最熟悉的语言。
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.
我使用 PHP 框架 Symfony (symfony-project.org) 和 ORM Doctrine 在九个月内构建了一个电子商务应用程序 (www.perqworks.com),但对服务器端代码或数据库设计知之甚少。为什么我相信 PHP 是正确的选择是:
现在应用程序已编写完毕,我有一些后见之明,我想知道开发应用程序的最终产品和经验会是什么使用过 Django、Rails 或 Java。我得出的结论是,主要 Web 开发语言之间的差异不是它们微小差异的总和,而是程序员编写智能、高效代码的技能。
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.
Java 拥有大量的企业级支持,比 PHP 多得多。您有分布式事务、大量数据库驱动程序、消息队列、持久性管理器(如 Hibernate 和 iBatis)、Spring 框架、模板引擎、Web 服务支持等等。有很多高性能应用服务器,如 Glassfish、JBoss 和 WebLogic。因此,我认为您应该考虑 Java 而不是 PHP,除非您的应用程序
规模较小且具有小规模的电子商务需求,并且您已经对 PHP 感到满意。无论如何,这是去年北美一家大型电子商务网站的工程副总裁给我的建议。
更新:根据 这些基准(可能没有使用操作码缓存,请参阅评论)。
更新:来自 highscalability.com。它强调了这样一个事实:Java 语言不如 Java 平台和 Java 社区重要。有很多成熟的工具可供选择,有很多人在研究它。甚至还有许多新的 JVM 语言可以与 Java 一起使用(Scala、JRuby、Groovy、Clojure、Jython 等)。完全或部分使用 Java 的大型网站的示例包括 Fotolog、Amazon、E-Bay、Flickr、LinkedIn、GoogleTalk。
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-scalehas 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.
没有什么是你在一个方面做不到的,而在另一个方面却可以做到的。选择您最熟悉的一个。这比任何所谓的技术优势都重要得多。不太重要的区别是:
编辑:您真的认为 Java 没有大量样板代码吗?严重地?我举一个例子:将文件读入字符串。
Java:
PHP:
除此之外,请查看样板
hashCode()
、equals()
、toString()
和 getter/setter 复制代码最终出现在大多数 Java Web 应用程序中。There's nothing you can't do in one that you can do in the other. Pick whichever one you're most familiar with. That's 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:
PHP:
Beyond that, look at the boilerplate
hashCode()
,equals()
,toString()
and getter/setter copying code that ends up in most Java Web applications.