Java  VS  PHP

英文对比

  • Language features & libraries

Java is strong and statically typed, while PHP is rather weakly typed

There thousands of OSS projects for Java (apache.org). Java provides a clean mechanism to combine these libraries (jar) to compose a complex application.

Java has a persistence mechanism to convert Java objects to database table entries and table entries to Java objects.

 二、Operation mechanism

Java programs tend to be built from a "program runs, stays running, processes requests" kind of way, whereas PHP applications are built from a "run, handle the request, stop running" kind of way.

三、Security

Java Application servers enforce security model. Each application runs in its own container.

Java/JVM has its own extensive security framework.

No security guarantees from PHP: Administrators run PHP in CGI mode in order to avoid security nightmare. That is, PHP engine is forked for each page hit.

Even Administrator chroots (each time to you hit a page) for security.

And finally, Java has traditionally been considered a more secure option. While this has been contested, particularly following exposure of security vulnerabilities earlier this year, many enterprise systems are unlikely to move to PHP, which is hard pressed to make claims of decreased vulnerabilities. For this and the other reasons stated here, a lot of big businesses (not all) prefer to build with Java.

四、Debugging

 All Java editors allow you to debug your project within the editor.

 PHP debugging is just “print” statements.

五、Programmers

Everybody is a PHP programmer. Even monkeys! Changing or creating a page in PHP is easy

For a complex application, monkeys cannot do programming in Java.

 

Ultimately, these characteristics imply that java can be a good choice when development is complicated and relies on teams of professional developers. Rather than making work more challenging, the precisely defined standards allow for easier understanding and greater efficiency among teams. On the other hand, PHP is more accessible to inexperienced programmers.

Most small and medium projects are better with PHP vs. Java. However, larger projects are better with Java vs. PHP.

中文对比

  • 运行机制

Java的优点则是稳定可靠、运行效率高(尤其是JIT的出现之后差距更大了)、不容易犯错(强类型、预编译、必须拦截异常等等),缺点是开发和发布的效率相对较低。

java是纯面向对象开发,功能强大,分支众多,没有java不能做的软件

  • 数据库访问比较

Java访问数据库的接口比较统一;

PHP对于不同的数据库采用不同的数据库访问接口,所以数据库访问代码的通用性不强。例如:用java开发的web应用从mysql数据库转到oracle数据库只需要做很少的修改。而php则需要做大量的修改工作。

  • 处理并发
    Java在并发处理上采取单进程多线程的方式,Java要做的仅仅是业务逻辑处理了。
    PHP在并发处理上时采取多进程的方式,多出了一定的IO损耗,另一方面进程池内的进程间也很难进行通讯,所以在并发处理上仍然无法和Java相比。PHP能够将单一的事件做好,但却不适合完成集成度较高的多项并发事件。
  • 缓存技术
    Java是单进程,很多缓存可以直接在Javaheap中做,而无需借助外在的工具,当然也有很好的缓存框架,比如Ehcache,因为没有网络IO,所以性能非常高。
    PHP多进程单线程决定了它只能借助外来的缓存服务器,比如Memcache.
  • 源代码安全

java开发的程序,最后用户拿到的是只是一些编译好的class类,无法看到完整的源代码,安全性高。

php开发的程序的源代码都是公开的,他人拿到php开发的程序后都可以进行修改。

  • 性能比较

语言特征决定了执行速度,在执行速度上,总结而言Java优于PHP

 

综上所述,对于一个普通的Web应用而言,如企业展示网站、个人博客搭建、微商平台、小型ERP、CRM系统,技术角度PHP完全足够,价格角度PHP也便宜于Java,开发速度PHP略优于Java。对于一个复杂的Web应用而言,面向对象的Java将会是不二的选择,虽说费用高,但贵只有贵的一个缺点,便宜则只有便宜一个优点    

             

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值