When is Java a good choice for web development?
Please do not say "When you have a development team that knows only Java."
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.Sign up to join this community
Given the many available frameworks, the maturity of the platform etc., I'm tempted to say "almost always". So here are some reasons when you should not use Java:
Java is used in small and medium websites. The crucial point is that there is much less free web hosting for Java websites than for e.g. PHP, meaning that unless you have enough resources to host your own web server you will probably not choose Java.
Note that with Java EE 6, especially the web profile, there is a lot of standard technologies included that can create very powerful web applications without having to code much. It is unfortunately not mainstream quite yet.
Note that this has changed somewhat recently with the Google Application Engine which allow you to deploy standard Java web applications (with a few restrictions) in the cloud for free for low to medium traffic sites.
Every time yet another Java team pisses me off, I blow off steam by looking up questions like this one. Let me reiterate. I am a client side dev and have been for close to 5 years now. I've worked on sites ranging from one-off mostly-content microsites, to sites as massive as Sears, to more sophisticated app-type sites where really deep UI expertise is needed. I have dealt with Rails, PHP, .net web forms (ew), .net MVC (much better) and a bouquet arrangement of Java solutions for web development accompanied by devs and teams that have all been complete disasters to deal with. I also write a bit of Python and am starting to dig Django.
My experience with Java teams has been universally awful. The tools are always a PITA. The devs never want to believe they did anything wrong and getting them to reinvestigate their own turf once you've ruled out a problem on your end is like pulling teeth. The first casualty of dealing with Java teams in my experience is development time converted to e-mail time writing multiple lengthy explanations of why the problem is definitely on their end. HTML is generally not their problem unless you actually want some control over it. Then everything is likely to go to hell on their end because you actually want to move some upper level divs around.
There are things about the language I dislike but I think the real problem is the culture and the fact that acceptance is so widespread, you have a ton of mediocrity in the middle. The culture I suspect springs from the way Java is marketed. Write once, deploy everywhere. Translation: "You only need to learn one thing!" People who find that appealing basically want to wield Java like one gigantic hammer for every nail with a minimum of actually honing of their craft in regards to web development.
So if you have devs who know Java and other languages but still actually prefer Java, I would say, yes, go ahead if it seems like the right solution. But if you have Java devs who know Java and everything else is just barely meeting the criteria to actually make it a bullet point on their resume, have them build a simple app with a variety of semi-complex pages on the HTML end and try this simple test. Break some HTML. Try to get them to figure out what's wrong. If the immediate problem they start to solve is diverting blame from themselves, keep them the !@#$ away from web development. Web dev is multidisciplinary and requires active interest in the field to be successful. It is not a place for people who only want to have to maintain knowledge of one language and are more horrified by problems than interested in solving them.
I'm not asserting that Java itself is the root of incompetence and I've heard Spring is good. I'm sure there's competent Java teams out there. I just haven't run into one yet and I don't think it's a coincidence. I think Sun has a lot to do with it. I also think running web teams like or under IT departments has a lot to do with it.
Java is perfectly fine for small web sites, You can get JSP pages working very quickly with a Java web server such as Tomcat, for example.
Although in my experience Java is more common for large websites where is there is a greater need for complex server-side processing - in this case you will find more sophisticated Java frameworks used such as JavaServer Faces (JSF).
It's important to note that a full Java installation historically wasn't available in many cheap web hosting setups, so that may explain the prevalence of other languages such as PHP in these environments.
The main reasons for using Java in web development boil down to the following:
If I was starting a web application, I would use Ruby on Rails and design in such a fashion that the hotspots could be swapped out when RoR hits its performance scaling limit.
Java has a definite odor of COBOL and "low-end coders use Java" hanging about it, and the Oracle fiascos are not helping the reputation. If you have the choice, choose a language that is attracting top devs.
It's simple: use Java when back end performance is a major concern. There is more overhead when coding but the code will execute in 1/200th to 1/500th of the time- literally. Php, Ruby, and other dynamically typed languages are always going to be way slower than java or .net servers.
Most solutions for the web won't need this. Twitter didn't abandon Rails until they started peaking in popularity for example.
Not any kind of expert on the alternatives, but if someone else can put forward one with the same kind of flexibility and breadth, happy to hear about it.
The main reason why I would choose java is if you need to use distributed transactions, which can be a big concern for many corporations. However you can still use your favorite scripting language for web development, and only delegate work over to java when you need speed/distributed transactions.
I believe it would be when your application is going to be very complex, with many people developing it, with a lot of complex modules, complex business logic and it has to communicate with many other enterprise applications.
Anyway, you could also develop in Grails, which provides a lot of nice features, eases development a lot and is maturing really fast.
Java is a statically typed language, and is cheaper than the other statically typed languages used for web development, namely C# and VB.net, if your company does not have an MSDN subscription. Statically typed languages are good for medium to big projects, complex domain rules, and a lot of back-end code, because you can organize better your classes and IDEs will help you to find errors in your code.
With dynamically typed languages, like PHP, Python, Ruby, your development will be much faster, but you will have to test your code much better. If you don't have much time and money and your requirements change very quickly and you don't have to do very complex calculations, dynamic languages are much better.
The main reason for large companies choosing Java over other solutions is because it is considered to be much more secure.
This is mainly because it is supported by such a large company (now oracle).
It should be taken into consideration that Java offers a very high level of security and excellent support and analysis (although it does come at a price).