views:

169

answers:

5

I had never heard that you can use Java for a web site. I just learned it today when my future employer told me.

The web site in question runs @ 15,000 daily visitors and it's only the beginning, so is it faster than PHP? Why did they pick Java over PHP?

  • What are the pro/cons for a website using java compared to PHP?
  • What website should I go to learn the basics of using Java for a web site
  • Will it be difficult to me to switch from PHP / Symfony to Java for web?

Edit: It's JSP based. Does that change your answers?

Thanks

+3  A: 

The main disadvantage is that overall java is not as suitable for shared hosting as PHP/Ruby and the alternatives (clouds, virtual private servers, private servers) are all in the upper-price range. Also deployment is not as easy.

About advantages - there are tons of them - much better scalability, tons of tools/libraries/frameworks coming from reputable vendors. The modern application servers have features incomparable to the ones that Apache+mod_php has.

About where to get started - in Java there are a lot of different ways to create web applications - there is a great choice of building tools, object-relational mapping libraries, frameworks, application servers and web frameworks (both MVC and component-based). Good starting points would be the official Java EE tutorials (using a JPA/Java EE/JSF stack) and the Spring Framework ones.

vstoyanov
Not sure scalability is a key selling point of Java any more. Just look at Facebook. One of the biggest sites in the world, written in PHP.
Codemwnci
@Codemwnci the front end of Facebook is in PHP. They use a variety of languages for the rest, I believe including Erlang (chat), Scala, Python and Java. And, they had to build the HipHop compiler to improve PHP performance...
Alex JL
@Codemwnci Yes, but Facebook is a company with great amount of resources, which is literally built around this single product. They have developed tons of their own libs (e.g. HipHop) and infrastructure to complement their product.A typical enterprise application team would hardly be able to devote that much resources and that's where java comes in.
vstoyanov
@Alex JL and @vstoyanov. Both very true, I just wasn't prepared to say that Java is far more efficient because I am aware that HipHop exists as an open source product that can be used. Facebook know that for every ounce of performance they squeeze out of their code, the hardware savings are huge. HipHop obviously does the job for them.
Codemwnci
+6  A: 

Let me try to answer each question one at a time

What are the pro/cons for a website using java compared to PHP

Many years ago, Commercial applications would be written in Java or .Net. PHP was for hobbyists and small firms...or so the big corporations thought. Facebook et al have now rubbished that idea by showing that PHP can be used for highly scalable, high performing websites.

Java has great support for frameworks and a very strong community. Java hosting is very difficult to find and not cheap. If you are deploying to your own server though, this is not an issue.

What website should I go to learn the bases for java for a website

  • Here is a good place to start.
  • Next start to look on the web for a good web application framework, such as Struts, Wicket, Spring MVC or Play (there are far too many to list here).
  • Once you have chosen a framework, follow the examples to get to understanding how to build applications. They will point you in the right direction to continue your learning.

Will it be difficult to me to switch from PHP / Symfony to Java for web ?

It won't be a huge leap. PHP is based on the C language. Java was designed with C in mind, as an easy transition for C programmers. Some things are different (like string concatenation in Java is with a plus(+) and not a dot/period(.), but they are not a million miles apart.

Codemwnci
I disagree very much. Java is a much different language from PHP. Java is object oriented only, deployed sites require re-compilation when classes change (JSP can mitigate this to an extent), and the basic language constructs are wacky. My biggest peeve with Java is the almost useless `switch` statement. It will _only_ work with integers, and only explicit integers. You can't `switch (IntObject.someProperty) { case IntObject.OBJ_CONSTANT_1: ...; }` or anything similar. And the documentation? That's a damn mess.
jsumners
"Java is object oriented only" - true but I think this is a good thing..."sites require re-compilation" - not always the case, see playframework.org as an example...."almost useless switch statement." - I believe Java 7 will solve this issue, but true for now
Codemwnci
Also, I sent a PHP developer on a Java course recently and they absolutely flew through it. They are not identical I admit, have some fundamental differences (like OO), but I don't think the leap is a big one, especially when using a framework which will guide the developer through the process anyway.
Codemwnci
+3  A: 
  • What are the pro/cons for a website using java compared to PHP ?

PHP is more common for web hosting providers.

From my point of view, Java "learning curve" is little longer, than PHP.

On the other hand, Java language is little more strict, so it may be more suitable for complex enterprise systems with long maintenance supposed.

  • What website should I go to learn the bases for java for a website

If you already have Java experience, familiarize with some web development frameworks, for example:

Spring framework: http://www.springsource.org/

Stripes framework: http://www.stripesframework.org/display/stripes/Home

Otherwise, go to Java Tutorial: http://download.oracle.com/javase/tutorial/

  • Will it be difficult to me to switch from PHP / Symfony to Java for web ?

Depends on your Java experience. Most web development frameworks generally have similar structure, so if you worked with Synfony, it would be easier for you to get familiar with Java web frameworks.

Kel
+2  A: 

Having worked in an enterprise-level Java shop (using Struts and Spring), and being a certified PHP developer, I can tell you that I'm a much bigger fan of PHP. Here's my reasoning:

  1. Java is ornery. One slight mistake and it's barking at you. PHP is far more forgiving.
  2. Good luck finding community-supported plugins for Java. They exist, but not like PHP.
  3. Compile time on Java is good for checking Facebook, not so good if someone else isn't signing the paycheck. When you write PHP, it's ready to go.
  4. Java tuts for simple, silly stuff can be a bear to track down. PHP may be the most documented language on the internet today.
  5. Weblogic STINKS. Nuff said.

If you're working in Symfony (as I am currently too, unfortunately), the other language you'd likely be most familiar with out of the chute is Ruby--they use many of the same tags. It wasn't terribly difficult for me jumping from PHP to Java, but I wouldn't want to be in a situation where I was doing it and didn't have expert assistance around me when I got stuck.

In the web world, 15,000 visitors is really not that much...I've worked on apps for 1 million uniques a day on PHP using Apache and MySql with no problem, using 3 servers and load balancing. Don't let some techie tell you it can't or shouldn't be done. PHP got a bad rap in the beginning, and my bet is that Microsoft and Sun's sales arms had a lot to do with that.

Given your current experience, I'd stick with PHP.

bpeterson76
the problem is that I really love the project, so i'll need to make sacrifice by learning java even if i would prefer stick with PHP / Symfony
Tristan
+2  A: 

Watch out, you're likely gonna start a religious war with such a question! The truth is you can read tons of articles on this topic and you probably still won't get an accurate answer. This is simply because the context matters a lot. There are probably as many answers to the question "Java vs PHP" than there are developpers.

I have a bit of experience with both so I'll give my 2 cents here:

  • If the choice was simply between PHP and Java to build a web site, PHP wins by far. After all, this language was invented for the web.
  • But very few people still build web sites with PHP or Java by itself. Most developpers rely on frameworks now. That's where it becomes tricky to compare.
  • I believe there are far more frameworks for Java than for PHP. Some of those frameworks really suck but are still widely used.
  • If you end up working with only Servlets/JSP or with an obsolete framework like Struts 1, you're gonna miss Symfony very soon.
  • If you're lucky and work with frameworks like Grails, Play, GWT or Spring Roo to name a few, you may like it.
  • You likely won't waste your time learning Java in any case. It's widely used and has a broader scope than PHP for Enterprise solutions. There are tons of cool stuff you can do in Java other than web applications.

For your second and third questions:

  • It's hard to provide any link to learn Java for web site as any reading could be very far from what the people you've met do.
  • Since you mentioned JSP, it could be of some interest to read the basics about Servlets, JSP and JSTL but if it's all this company does ... well ... stay away or Java will disappoint you a lot.
  • It shouldn't be too hard for you to switch if you have some good general programming background. It's not tough to make something work with Java.
  • However it's a bit harder to avoid spaghetti code and make things properly. Good knowledge of object oriented concepts and design patterns is a must ... but so many java developpers just don't have it.

Side note: this french blog is a must for any French Java Web Developper.

Damien