File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Java V's PHP for Building Websites Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java V Watch "Java V New topic
Author

Java V's PHP for Building Websites

Fergal Crawley
Greenhorn

Joined: Nov 28, 2011
Posts: 18

I know that this forum software is built using Java, however, most forum software (e.g. phpBB, vBulletin, IPB, etc) is built using PHP and MySQL. Most other website development scripts (such as image hosting scripts, classified ad scripts, blogs, CMSs, etc) also appear to be built with PHP.

Why are more websites not built with Java?

How do Java and PHP compare, when it comes to web development?

Does Java have any advantages over PHP, when it comes to web development?

Also it would be great if you could please post links to any quality websites built using Java.

Thanks!


Beginner
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3646
    
  16

I can't say for certain, but I think most server side scripting is done using PHP because of the widespread availability of AMP (Apache, MySQL, PHP) bundles. Most small companies and individual users don't have their own web server, so they have their websites hosted by a company that offer these AMP bundles.

Again, I don't know for certain, but I think Java is mostly used on servers owned by bigger companies.

I think a lot of people who get into building websites can't be bothered to learn a programming language that is fairly strict. They feel scripting is more natural in a dynamic and weakly typed language, like PHP.

As I have no experience in web development using Java, I can't comment on the advantages of either over the other.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3070
    
  33

Fergal Crawley wrote:

Also it would be great if you could please post links to any quality websites built using Java.

Thanks!

this site is built using Java.


Mohamed Sanaulla | My Blog
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3070
    
  33

Hosting for Java applications is expensive than that for php. But with the likes of Google App Engine, Heroku, Jelastic, Cloudbees, Cloudfoundry and others providing free hosting (upto certain limit) for Java applications or applications that run on JVM its no longer required to buy a expensive hosting plan. Twitter for example uses Scala and Rails for their application. JVM platform supports Polyglot programming thereby you can use a scripting language or languages like Scala, Java to build and deploy web applications.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3646
    
  16

I believe KnowledgeBlackbelt is built using Vaadin, which is a Java-based framework.

I'm not sure of the quality of the website though. It looks really nice, and has a lot of fancy features, but it's also often extremely slow.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3070
    
  33

The enterprise applications are mostly built on top of JVM.
Karthik Shiraly
Ranch Hand

Joined: Apr 04, 2009
Posts: 501
    
    5
Pros:
-----
Simpler API: PHP's API is much more intuitive than java. Takes less time to get productive with PHP than with Java

PHP was not a resource hog: This is more relevant to the situation 9-10 years ago, than it is today. But the damage was already done. PHP did not need as much memory or as much processor power as a java web app running in a JVM. So PHP was more suitable to commodity hardware in those days. 9 to 10 years ago, I was told about JSP developer experiences, where people would write JSP and then go have a cup of tea for half an hour while the compiler compiled and server deployed it. Then even the simplest JSP requests would take another 30 seconds to couple of minutes. JVMs became much more performant only later on. Performance is much better nowadays of course, but even now, a request to a java web app requires more memory than one to a PHP app.

Less typing. Faster to write code: PHP was a procedural language that later got OOP extensions. So global functions are still common in PHP. Makes for less typing.
The untyped nature of language too makes for less typing.
PHP is not strongly typed while java is. This is both a boon and a bane. It's a boon because you have to do less typing.
But it's a bane - specially in large projects - because one developer will have no idea what data is being passed by another component unless it's documented well.
This is not so much of a problem when single developer is developing and uses some common sense coding conventions.

Had open source server support much earlier than java (I believe this was one of the main reasons for its popularity): Apache - 1995 I think. Apache Tomcat - 1999.

Arrived much earlier on the scene than JSP (I believe this was one of the main reasons for its popularity): PHP - 1995; JSP - 1999

Easier for web designers to pick up: PHP is easier for web designers to pick up, I believe this is another main reason it got traction

No installation complications: PHP interpreter usually comes bundled with Apache in most installation packages. Java on the other hand requires JRE to be installed.

Development cycles take less time: Changes can be made to a PHP file and these changes can be seen immediately on a refresh. This is due to PHP's shared-nothing architecture. PHP has no concept of shared memory, unlike java's static data and session data which remain in memory between requests. Once a PHP request is finished, all data created on the heap is deallocated. PHP session data is saved on file by default, but can be saved to DB.
In java web development, on the other hand, the only way to make a JSP change or java servlet change active is to rebuild the war and redeploy the web application, thus making it much less nimble than PHP. Of course, some commercial tools like JRebel make this easier, but it's still not as nimble as PHP.

More hosting options: I agree with Stephen's point. It's much easier and cheaper to host PHP websites than it is to host Java websites.


Cons:
------
Not good support for DB transactions: DB transactions are by nature complex. Java has extremely good standardised APIs for transactions (JDBC) and for distributed transactions(JTA).
PHP on the other hand had no such support. Even now, some DB agnostic APIs are available - like PDO - but I don't think transaction support is any better.

No multithreading: PHP has no native threading API. The runtime is also said to be not threadsafe (there's lots of heated debate about this depending on whether the poster is a PHP fanboy or not). I have not done any detailed analysis, so my knowledge is borrowed. But what I understand is some PHP extensions (these are the adapter plugins that add functionality to the PHP interpreter) are thread unsafe, and since nobody seems to know exactly which ones aren't, it's risky to use threading.

No asynchronous processing support: Because there's no multithreading support in PHP. This is a strong point of java, making java a good candidate to deploy in the services (business logic) layer when some heavy backend processing is involved. It's possible to deploy webdesigner friendly PHP in the web tier and deploy scalable java (or other JVM language) in the business logic tier - and then integrate them through web services.

Linkedin uses java extensively. Twitter uses Scala (a JVM language) for its backend. Any site based on Liferay CMS or Alfresco CMS (they're called "portal"s in java world but are comparable to the CMSes of PHP world, like wordpress and joomla) is running on a java stack.
Fergal Crawley
Greenhorn

Joined: Nov 28, 2011
Posts: 18

Thanks everyone for your very helpful replies. I got the info I needed. Karthik Shiraly, your reply was particularly informative.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38793
    
  23
Agree: a lot of effort and knowledge went into that reply.
Jay Orsaw
Ranch Hand

Joined: Jun 14, 2011
Posts: 356

Very good replies here. It makes sense in that last reply, as in the Java vs C++ posts, it's all about what is the best at the time, and how old it is. Back in the day as mentioned PHP and other scripting languages were much faster. As time progresses and we see faster computers and the languages evolve there will be the standards. We see throughout time how different languages were key, and as newer languages came out, older languages were replaced or edited to keep up.

As for Java itself, IMO it is newer than most, and in the comment about JSP vs PHP JSP was young 10 years ago, and now that Java has advanced so much it is a powerhouse. IMO what it can do far exceeds what scripting languages can do on the web, but the issue is do you need all that power? Some people only want small tasks completed, so why go crazy if it's not needed? It also comes down to what you know and if it's worth it to learn another language... The thing I like about Java overall it is it connected to everything. Even other languages are mixed with Java, or what it seems to be (JRuby/JPython)?? It all comes down to who, what, where, when, why, and how... You can only base your choices on what you want to do.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java V's PHP for Building Websites