Sr. No. | Function / Feature | JSP | PHP |
1. | Programming Approach | Completely object oriented Advantage: Clean code Disadvantage: Too descriptive | Scripting with object oriented support Advantage: Functional and quick coding, you can use OOP practices at your convenience Disadvantage: May get clumsy |
2. | String and data manipulation | Rich library, too much descriptive and object oriented code | Rich functionality. Functional and easy coding. |
3. | Web Oriented features
| Almost everything is built in or supported by libraries. Complicated and too much of code. | Inbuilt functionality. Easy to use functions, written for the specific tasks |
4. | Database Access features | Standard JDBC structure/ Use EJB/ Struts framework built over JDBC. Descriptive and too much overhead or boiler plate code involved. Uses the same API for all databases using JDBC drivers | Dedicated inbuilt libraries for most of the commonly used databases. Very tight integration with MySQL and PostGRESQL. Very minimal boiler plate code required. The libraries and results are straight forward and easy to use. |
5. | XML/XSL/XPATH | Use standard SAX/DOM parsers. Too much boiler plate code involved. Well defined APIs and stable implementations are available for XSL and XPATH | SAX and DOM parsers available are easy to use and to the point. Another library, Simple XML provides very easy OO approach to handling XML data. XSL and XPATH functionality is also built in. |
6. | Extensibility | Java Classes and Libraries. Run’s in sandbox and hard JNI approach needed to integrate with server programs. | PHP/C/Any thing executable by the underlying OS platform. Can very easily interact with programs on the server. Very good support for native code. |
7. | Dynamic Graphics/PDF and bells and whistles | Almost everything has a readymade library | Supported internally or though libraries. |
8. | Web Services/SOAP | Addon Libraries like Axis, JAX-WS, etc. | In Built |
9. | Portals | Spec JSR-168 and 286 | Many different Portal frameworks |
Conclusion:
I have generally found that anything can be down in both the languages. Just while working with the Web Applications, PHP tends to do easy things the easy way and also manages difficult things in a fairly decent manner. JSP, being built over Java, a generic OOP language, involves more structure and coding.
Generally observed in my past experiences and by most of people who have worked on both platforms is production in PHP is quick as compared to Java. But maintenance of PHP code tends to be difficult due to lack of constraints on the developer for structuring the code. But this can be made over by following proper coding guidelines.
The lack of tooling for PHP is also many a times a concern.
But overall, PHP is much more well established with libraries, frameworks, patterns and code base for general Web Dev, while java’s base is much more standard’s oriented. For example we can take the Portals. Java has a standard Portal Spec, while PHP has hundreds of Portals/Frameworks available not conforming to any standard.
A note about the libraries:
Though Java tends to be very much standard oriented, there isn’t much effort on the community or user or promoter’s side to organize/gather/test generic or readily available libraries.
The PEAR project for PHP libraries hosted at http://pear.php.net/ provides a large library for PHP, most of which are actively developed and tested and in production use.
Gut feeling, there is a library for everything on both platforms. Java is much more commercialized than PHP. So chances of getting a free to use, unrestricted and one source PHP library is easier than for Java.
There are many implementations for similar tasks to be done. A central location like PEAR is a good pointer to have.
Design pattern wise, like for MVC, also both platforms have libraries available. The functionality and approaches vary from library to library.
There can’t be a more stronger reason to suggest the scripting benefits than JSR 223, which plans to bring Scripting languages, specially PHP to J2EE.
With a vast number of frameworks easily available, PHP shall be my obvious choice for websites and portals.
I will prefer Java or may be .Net depending on various factors for Web Based Applications, because, they are more structured and easy to maintain and moreover may be just because they have the enterprise appeal and wide array of tools.