34

When is Java a good choice for web development?

Please do not say "When you have a development team that knows only Java."

5
  • 5
    Can be asked like, which feature makes Java as my web development language? Jan 18, 2011 at 8:27
  • 1
    A slight downside to using Java is a lack of a defacto dominant framework in the market. No Java based framework has really risen to the top of the pile yet (like Struts had back in the day). Personally I lean towards Spring MVC if I'm working with a Spring app or Grails for anything else (as you can call out to Java anytime). Jan 18, 2011 at 8:57
  • Suddenly got 25 points from this question!
    – Gulshan
    Sep 30, 2011 at 6:39
  • are we taking existing opensource software in account? Apr 12, 2012 at 19:07
  • 2
    "like Struts had back in the day": What is wrong with using struts today (other than it is not fashionable any more)?
    – Giorgio
    Mar 30, 2013 at 16:58

14 Answers 14

35

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:

  • as a pure MS shop, you probably prefer to do it the .net way
  • if you need the cheapest possible webhoster, you probably only have PHP as your choice
  • if you want to do it as rapid as possible, Ruby on Rails, Grails or Django are probably better suited for your needs
  • if your development team only knows XYZ, where XYZ != Java, you better use XYZ
8
  • 7
    So, we use Java if we are not an MS shop, have intension to spend money for hosting, have enough time for developing using Java and have Java developers. Is it OK?
    – Gulshan
    Jan 18, 2011 at 8:40
  • Gulshan: yes, you can put it that way
    – user281377
    Jan 18, 2011 at 8:47
  • 3
    There are plenty of other reasons like It's bloated, enterprisey and it's Java (the last can be ignored if you use Scala or something else for the JVM).
    – Raynos
    Jul 3, 2011 at 12:12
  • 1
    @Raynos so you recommend what instead?
    – user1249
    Sep 29, 2011 at 11:22
  • 2
    @ThorbjørnRavnAndersen really depends what the requirements are. If the requirements are generic (non-niche) then use whatever platform is most convenient to your developers and servers.
    – Raynos
    Oct 2, 2011 at 16:58
19

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.

9
  • In all cases I will not host my website in a free web hosting. But the question is there a probelm with the paid java web hosting? Is it very expensive for example?
    – Goma
    Jul 2, 2011 at 18:38
  • 1
    @saeed, not as such. Most people just go for the cheapest option and code accordingly.
    – user1249
    Jul 2, 2011 at 18:42
  • Is jave far expensive than others for example? is there a shared hosting for java?
    – Goma
    Jul 2, 2011 at 18:48
  • @Saeed, there are some technical reasons that you cannot group as many JVM's on a single Linux og Windows box as you can create shared LAMP instances, which implicitly mean that a hosted JVM is more expensive than a hosted LAMP. Google use a different JVM meaning they can offer it for free.
    – user1249
    Jul 2, 2011 at 19:57
  • @Thorbjörn: Do you have any links about how Google does it? I have heard that they use Jetty, but I don't know much more about their solution.
    – Jonas
    Jul 2, 2011 at 23:14
12

When your platform is UNIX/Linux and you need rich set of tools, such as Object/Relational Mapping, Security, Complex orchestration of Web Services, etc .
(We aren't talking about simple websites, are we?)

15
  • 1
    You can get this stuff from scripting languages as well - look at Python and SQLAlchemy. Even Rails uses an ORM (ActiveRecord) and has good security.
    – Brian D.
    Jan 18, 2011 at 15:59
  • 3
    Indeed, but I don't think they are as powerful as Hibernate, Spring Framework, BPEL frameworks are.
    – Sorantis
    Jan 18, 2011 at 16:06
  • 1
    What wrong with Java on non-UNIX/Windows. Jan 18, 2011 at 23:31
  • 2
    Nothing. But on Windows you have .NET
    – Sorantis
    Jan 19, 2011 at 9:40
  • 2
    -1 Your making it sound like any of the alternatives don't have decent tools available.
    – Raynos
    Jul 3, 2011 at 12:14
9

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.

4
  • 1
    I have the same problems that you describe, but never thought that it could depend on the programming language. Do you think that people who programs in, say, PHP, is more open minded and flexible? Apr 29, 2012 at 21:44
  • PHP is 100% about the developer and less about a culture surrounding it. I don't love its lack of consistency at the core, but I would trust the work of a mid-level PHP team for web development in a way I wouldn't trust a Java team. It helps that an experienced PHP dev is unlikely to have worked with anything but the web and s/he likely got hired for experience over degrees/credentials. The Java problem might be in part due to the language's inherent rigidity but I honestly think it's more about the nature of how Java devs are trained, Java solutions are adopted, and Java devs are hired. Apr 30, 2012 at 14:02
  • 1
    @Erik Reppen: I think you are overgeneralising your experience: I do not think Java teams are worse than teams that work in other languages or, at least, not worse than the average. I know two very good shops who work heavily with Java. The first, does projects in Java and in Ruby (about 50% each). The second works mainly in Java but has done individual projects in Scala and in Common Lisp.
    – Giorgio
    Mar 30, 2013 at 17:11
  • @Giorgio I missed this but I have worked with other people handling the back-end via .NET, Rails, Java and PHP. I'm not counting one-time experiences with other languages and crappy devs certainly aren't unique to Java. Also, as I said I am 100% certain there are very competent Java teams out there. Somebody has to not suck at it but IMO, I'm not overgeneralizing. There is a problem with Java devs at the median level. It's a cultural phenomenon in my experience. Such a nasty one that I've stopped taking work with Java shops unless I know the devs in question. Nov 5, 2013 at 4:14
5

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.

2
  • Is this mean hosting java web applications is too expensive? or is it not as cheap as PHP for example? can you give me a good weh host link for java so I can see the prices? I did a search but I don't know which one have the standard prices so I can have a big picture about it.
    – Goma
    Jul 2, 2011 at 18:57
  • 1
    hosting Java web applications isn't expensive, you just need a hosting provider that lets you run Java applications. Any Linux hosting environment where you get a login account to the machine will be fine - I personally use Ubuntu on Amazon Web Services for my Java hosting.
    – mikera
    Jul 2, 2011 at 20:03
2

The main reasons for using Java in web development boil down to the following:

  • Client demands it. For better or worse, some clients have "accepted technology lists", and if you propose something not on that list you'd better have a really good explanation why--and why something on the list couldn't be used.
  • Develop on Windows, deploy on Unix. Most development machines are Windows, some are Mac, and very few are Linux--just as you would expect with regular client machines. However on the server, you're just as likely to see some form of Unix as you are a Windows server. Java is probably the closest to write once deploy anywhere (it's not perfect, but better than some alternatives).
  • Management choice. Let's face it, choosing Java over another language will have more to do with being able to find programmers and replace team members who leave the project than being based purely on the merits of the language.
6
  • About #2: please configure your IDE correctly. Eclipse has this stupid idea of defaulting to some Windowish file encoding which can bring havoc in a Linux server.
    – Eldelshell
    Jan 18, 2011 at 17:23
  • I was actually referring to assumptions about where certain files live, and any time you have to interact with the operating system. Jan 18, 2011 at 17:41
  • "C is probably the closest to write once deploy anywhere" I fixed that for you.
    – Raynos
    Jul 3, 2011 at 12:15
  • @Raynos, if only that were true. Unfortunately, unless you have the same standard libraries on all platforms, that cannot hold true. The core C language is very portable, I give you that. However, anything that is OS specific (like creating a thread, opening a socket, or creating a UI element) has something in the API that cannot be ported with a simple recompile. With Java, no recompile is necessary, much less changing the code to use the new system API. Jul 3, 2011 at 12:24
  • @BerinLoritsch you mean to say that after 40 years we don't have generic APIs for OS-specific stuff that just works cross-platform with a simple re-compilation? I can imagine it being true in the 80s though.
    – Raynos
    Jul 3, 2011 at 12:26
2

Technically speaking:

  • If you can define a architecture that is amenable to the hot-spot optimizer.
  • If you anticipate the need for the massive OO overhead Java imposes.

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.

4
  • "choose a language that is attracting top devs." Example?
    – Eldelshell
    Jan 18, 2011 at 17:30
  • 1
    @Ubersoldat: Go, Ruby, Clojure, Haskell, Python all are languages that do that. Jan 18, 2011 at 17:33
  • Python is nice because it actually succeeds at a lot of the things Java pretends to. And it's not hard to make it play well with others when you must solve a problem with some other language. I don't know about Ruby, but Rails devs are something of a crapshoot in my experience. It's the JQuery effect. People who know what they're doing like it because it's fast and effective in the right hands. People who don't know what they're doing like it because they don't have to know as much. Apr 12, 2012 at 15:56
  • @Erik Reppen: On the other hand, Ruby as a language has a nicer and more consistent design than Python. I really think these language comparison are often a matter of taste and one tends to favour the languages they are more familiar with.
    – Giorgio
    Mar 30, 2013 at 17:14
0

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.

0

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.

-1

Not the only reason, but with the increasing popularity of building websites with sophisticated application-like front ends while still having logic doing 'stuff' back on the server - no reason should be necessary to explain why Java is at least the equal of any other option on the server end. But at the client end, if any javascript is going to quickly turn into a code maintenance nightmare and by making use of GWT to keep that stuff at arms length so you can code in Java, you can have the best of both worlds with your server doing the heavy lifting and a client's processor giving them the 'experience'. Learn to integrate it with something like jQuery and you can have all the eye candy you want too.

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.

3
  • +1 for jQuery : )
    – abel
    Jan 18, 2011 at 15:14
  • 2
    -1 for "javascript turns into code maintenance nightmare", This is merely a side-effect of letting you Java devs write javascript without any training or learning JavaScript. and the major disadvantage of GWT is that it's a leaky abstraction, good luck getting it to perform well on mobile devices.
    – Raynos
    Jul 3, 2011 at 12:17
  • The problem with Java's rigidity, IMO, is that you end up with a lot of devs who don't understand why their code is forcibly organized the way it is in the first place. When everything must look like OOP, sometimes the inevitable result is that nothing actually is. Apr 30, 2012 at 14:20
-1

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.

-1

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.

-1

Java is ok, but if performance is not crucially important, you can get the same results with less effort in other languages.

3
  • 2
    "performance is not crucially important" when it is you should be writing in C and assembly not Java.
    – Raynos
    Jul 3, 2011 at 12:20
  • Benchmarks vs. experience, Java sites have hands down been the worst performers in my experience as a client side dev. That may be a median talent level issue more than a language thing though. Apr 12, 2012 at 15:50
  • 3
    @ErikReppen: Definitely a talent thing. Java speed on a server is second only to C/C++. PHP or Rails just cannot compare. But Java's libraries and some of the tools make it too easy to lose all that speed doing uselessly complicated things.
    – Zan Lynx
    Apr 13, 2012 at 1:08
-2

Security

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).

12
  • 7
    Uhh... and the security comes magically from the language itself or what?
    – Mchl
    Jan 18, 2011 at 10:01
  • 1
    You are aware that Oracle is NOT the only provider of Java servlet containers, aren't you?
    – Mchl
    Jan 18, 2011 at 11:02
  • 6
    Holy War! Fight Fight!
    – abel
    Jan 18, 2011 at 15:16
  • 2
    @Mchl Some of it comes from the language or rather from its VM. How many times have you seen buffer overrun hacks aimed at Java app servers? It's just not worth the effort. Having said that, Java is considered more secure by "the industry" than it is, and a false sense of security can bite back hard.
    – biziclop
    Jan 18, 2011 at 17:40
  • 1
    My point here was that you need to diffrentiate between Java as a language, and Java runtime environments. There's nothing that makes Java language more or less secure than any other language. JVMs on the other hand are designed (among other things) to 'sandbox' Java bytecode execution, but their security depends on the specific implementation. Good point on false sense of security though.
    – Mchl
    Jan 18, 2011 at 22:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.