34

When is Java a good choice for web development?

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

Jim G.
  • 8,006
  • 3
  • 35
  • 66
Gulshan
  • 9,402
  • 10
  • 58
  • 89
  • 5
    Can be asked like, which feature makes Java as my web development language? – Abimaran Kugathasan Jan 18 '11 at 08: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). – Martijn Verburg Jan 18 '11 at 08:57
  • Suddenly got 25 points from this question! – Gulshan Sep 30 '11 at 06:39
  • are we taking existing opensource software in account? – Jonathan DS Apr 12 '12 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 '13 at 16:58

14 Answers14

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
ThinkBonobo
  • 345
  • 3
  • 10
user281377
  • 28,352
  • 5
  • 75
  • 130
  • 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 '11 at 08:40
  • Gulshan: yes, you can put it that way – user281377 Jan 18 '11 at 08: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 03 '11 at 12:12
  • 1
    @Raynos so you recommend what instead? –  Sep 29 '11 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 02 '11 at 16:58
  • I'm going to second Raynos as a client-side-oriented dev on this one. I'm sure a highly competent Java team would be a pleasure to work with but Java and Java devs have always been a PITA to deal with on the front end in my experience. Unaccommodating, always in absurd numbers, and painfully inflexible. A small mid-level Django team could cover a lot more than a typical Java team in considerably less time and less expense. It's no accident that the Chicago Tribune's (the newspaper not the Tribune Properties) development team is all-Python. They have to turn things around quickly. – Erik Reppen Apr 30 '12 at 14:36
  • Erik: A tendency to make things complicated, bureaucratic and enterprisey is relatively common in the Java world. Anyway, there are excellent libs and frameworks for the JVM that can make one's life much easier. BTW, I prefer to program in Groovy. – user281377 Apr 30 '12 at 17:46
  • @ErikReppen You could have the same statement for any language out there. For example in my experience I've found a good chunk of PHP developers produce terrible spaghetti code with no mind to re-usability, scalability, or security. Doesn't mean I'd dissuade folks from using PHP if they need a web app that needs to present data dynamically, ins't terribility complex and needs to be developed quickly and have no issues finding qualified developers. – canadiancreed Mar 31 '13 at 15:42
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.

  • 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 02 '11 at 18:38
  • 1
    @saeed, not as such. Most people just go for the cheapest option and code accordingly. –  Jul 02 '11 at 18:42
  • Is jave far expensive than others for example? is there a shared hosting for java? – Goma Jul 02 '11 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. –  Jul 02 '11 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 02 '11 at 23:14
  • @Jonas, they have a local development environment that is based on Jetty running on your own pc. When you are ready you can then deploy to their servers, which run their own custom JVM, and web stack. –  Jul 02 '11 at 23:54
  • It looks like Google use a customized version of Jetty on the server too: http://www.infoq.com/news/2009/08/google-chose-jetty – Jonas Jul 03 '11 at 04:40
  • i don't think free is the right word, as no professional web developer will ever tell a costumer to use a free service. – Jonathan DS Apr 12 '12 at 19:04
  • @jonathan that -as always - depends on what the customer wants... –  Apr 12 '12 at 19:33
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?)

Sorantis
  • 2,720
  • 17
  • 24
  • 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 '11 at 15:59
  • 3
    Indeed, but I don't think they are as powerful as Hibernate, Spring Framework, BPEL frameworks are. – Sorantis Jan 18 '11 at 16:06
  • I really love Python, but please, don't compare SQLAlchemy (or JDBC) with Hibernate or any other mainstream Java ORM. Maybe in five years, but not now. – Eldelshell Jan 18 '11 at 17:20
  • 1
    What wrong with Java on non-UNIX/Windows. – Tom Hawtin - tackline Jan 18 '11 at 23:31
  • 2
    Nothing. But on Windows you have .NET – Sorantis Jan 19 '11 at 09:40
  • 2
    -1 Your making it sound like any of the alternatives don't have decent tools available. – Raynos Jul 03 '11 at 12:14
  • 1
    I'm not saying that the alternatives don't have decent tools. I'm saying that from all the alternatives Java has the biggest selection of mature tools, that are successfully used by enterprises. – Sorantis Jul 04 '11 at 08:21
  • @Sorantis: "I don't think they are as powerful..." Why not? Dependency injection is quite easy in dynamic languages; no need for a complex framework. – kevin cline Apr 20 '12 at 15:37
  • Two words that sets off a front end dev's alarm bells. "Java" and "Enterprise Solution." When used together it's more like a 5 alarm fire or an air-raid siren for an incoming nuke. WebSphere and 100 offshore devs? Set phasers to "shoot a hole in the wall and GTFO." – Erik Reppen Apr 30 '12 at 14:52
  • 1
    @kevin cline: True, but with dynamic languages you lose all the help that a compiler can provide with a static language. For large applications I feel much more comfortable with the help of a statically typed language. I remember spending quite some time looking for bugs caused by duck typing that a compiler would have caught if I had been using a statically typed language. I really think it is difficult to decide which of the two alternatives is better. – Giorgio Mar 30 '13 at 17:07
  • @Giorgio: there is no compile-time type safety connecting Java with web requests or a database. Using more powerful languages, those "large" Java applications suddenly aren't so large. – kevin cline Mar 30 '13 at 19:34
  • "There is no compile-time type safety connecting Java with web requests or a database": I am not sure I understand what you mean. – Giorgio Mar 30 '13 at 23:16
  • "Using more powerful languages, those "large" Java applications suddenly aren't so large": I did not mean large Java applications but large applications in general: there are projects that are inherently large, even if you use a language that is less verbose or has more powerful abstractions. – Giorgio Mar 31 '13 at 00:20
  • @Giorgio: Type mismatches between database schema and the associated Java properties cannot be detected at compile time. Nor can mismatches between web request data and Java variables be detected at compile time. – kevin cline Apr 02 '13 at 20:01
  • @kevin cline: "Type mismatches between database schema and the associated Java properties cannot be detected at compile time.": You mean if you cannot use type checking for part of your program logic (database schema) you should drop it completely? – Giorgio Apr 02 '13 at 20:32
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.

Erik Reppen
  • 6,243
  • 31
  • 34
  • 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? – Vitaly Olegovitch Apr 29 '12 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. – Erik Reppen Apr 30 '12 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 '13 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. – Erik Reppen Nov 05 '13 at 04: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.

mikera
  • 20,617
  • 5
  • 75
  • 80
  • 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 02 '11 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 02 '11 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.
Berin Loritsch
  • 45,784
  • 7
  • 87
  • 160
  • 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 '11 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. – Berin Loritsch Jan 18 '11 at 17:41
  • "C is probably the closest to write once deploy anywhere" I fixed that for you. – Raynos Jul 03 '11 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. – Berin Loritsch Jul 03 '11 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 03 '11 at 12:26
  • @Raynos, to be clear, there are no official C APIs that allow all these things to happen without any change to the source code. However, there are a few third party APIs that allow you to do something similar. The core C language purposely stayed out of attempting to do that, and for good reason. There are things you can do in C that you could never do in Java--such as create the OS to begin with. – Berin Loritsch Jul 04 '11 at 12:51
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.

Paul Nathan
  • 8,560
  • 1
  • 33
  • 41
  • "choose a language that is attracting top devs." Example? – Eldelshell Jan 18 '11 at 17:30
  • 1
    @Ubersoldat: Go, Ruby, Clojure, Haskell, Python all are languages that do that. – Paul Nathan Jan 18 '11 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. – Erik Reppen Apr 12 '12 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 '13 at 17:14
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

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.

Vitaly Olegovitch
  • 1,368
  • 12
  • 18
-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.

nomaderWhat
  • 139
  • 3
  • +1 for [jQuery](http://meta.stackexchange.com/questions/19478/the-many-memes-of-meta/19492#19492) : ) – abel Jan 18 '11 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 03 '11 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. – Erik Reppen Apr 30 '12 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.

Brian D.
  • 131
  • 3
-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.

Eldelshell
  • 301
  • 1
  • 2
  • 8
-1

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

kevin cline
  • 33,608
  • 3
  • 71
  • 142
  • 2
    "performance is not crucially important" when it is you should be writing in C and assembly not Java. – Raynos Jul 03 '11 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. – Erik Reppen Apr 12 '12 at 15:50
  • 2
    @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 '12 at 01: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).

mrwooster
  • 780
  • 4
  • 12
  • 7
    Uhh... and the security comes magically from the language itself or what? – Mchl Jan 18 '11 at 10:01
  • @Mchl Security flaws and bugs in the language are fixed much faster in Java than other languages, this is because it has such a large company behind it who prides themselves on a **solid and secure** product. Obviously you also need to write secure code, but that down to your developers. – mrwooster Jan 18 '11 at 10:24
  • 1
    You are aware that Oracle is NOT the only provider of Java servlet containers, aren't you? – Mchl Jan 18 '11 at 11:02
  • I am not specifically referring to servelts but Java as a platform. – mrwooster Jan 18 '11 at 11:22
  • i think PHP is the only case where the language itself was the source of security issues; but that was ancient history. – Javier Jan 18 '11 at 14:15
  • @mrwooster: Whatever you're referring to, Java applications can be run in virtual machines developed by a variety of providers. Ultimately it's up to these VMs how specific (byte)code will be executed. – Mchl Jan 18 '11 at 14:38
  • 6
    Holy War! Fight Fight! – abel Jan 18 '11 at 15:16
  • Yes, this is obviously correct, but I still stand by my statement that Java is a more secure platform. If a specific virtual machine introduces a security issue, this is the fault of the virtual machine, not of Java. – mrwooster Jan 18 '11 at 15:59
  • Ok.. there seems to be some misunderstanding here, but since abel seems to be mocking us, I'll let it die here. ;) Downvote was not by me BTW, chers :) – Mchl Jan 18 '11 at 16:02
  • 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 '11 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 '11 at 22:22
  • Frameworks can help you implement things securely by default but all it takes is one know-nothing nincompoop to do it wrong in any language. Having seen doSomething(i); i++; repeated over a dozen times in Java that tumbled out of broken JSP tags, I'm going to have to say that the more (in this case offshore sweatshop devs + !@#$ty management) cooks there are, the more you better watch out. This is not a scenario I've seen happen in other languages/toolsets for some reason. – Erik Reppen Apr 30 '12 at 14:11