Ask HN: Why are there so few apps being built with JSP?
It seems to me that lots of small to medium webapps are built either in php or in ruby on rails. I'm wondering why there seem to be only a small minority of webapps (at least not enterprise ones) being built using JSP technology.
Most articles and posts I see on HN seem to be webapps built with other technologies but Java.
JSP web apps can be built quickly as well. Eg. you have the JSTL tag library, and orm frameworks such as MyBatis or Hibernate. And there are also other things for simplifying, decoupling and modularizing a webapp like the Tiles framework, Struts, Spring MVC frameworks etc.
Now, I know for a fact that there are some other advantages php or rails apps have, particularly the lower price of hosting and possibly smaller memory requirements, but I'm wondering if there are any other reasons that JSP/Servlets/Java based small webapps are such a small minority and why adoption seems to be rather low for small to medium web 2.0 apps.
106 comments
[ 5.0 ms ] story [ 163 ms ] threadAlso, to be fair, other platforms have "caught up" to what were some of the early advantages of Java. For example, at one time I would have cited JMS and the easy accessibility of async messaging from Java as a big advantage. But now there are a bazillion messaging systems and most (if not all) of the major ones have easy to use client libraries in Perl, Python, Ruby, etc.
OTOH, Groovy/Grails brings a lot of the advantages of a RoR type framework to a JVM based ecosystem, as does Rails on JRuby, so more and more things are evolving to where the various platforms are approaching parity.
In the end it came down to picking a language I was comfortable in and could start moving forward the fastest with.
When you start your java app you pre-allocate all the memory you're going to need for the process' lifetime. This could be 512MB, this could be 2GB+, but it's never small. And this is unaffected by your initial traffic volume. It's the same for 0.001 hits/sec or 5 hits/sec.
On the other hand, if you drop a bunch of PHP scripts on a server, Apache only uses the memory it needs. Sure, you may have some pain scaling it later, but to get up and running you can get a cheap server and run your code.
Also, while I have your attention, have you ever tried installing an enterprise java webapp? It's not like you can pile a bunch of them into one JVM on a machine. I run confluence/jira/bamboo. Each has it's own requirements and basically need to run in their own tomcat servers tuned with their own settings. It's a huge PITA and eats up a ton of memory.
I am much more worried about memory consumption of RoR. Never really launched it in production, but wasn't it the case that you have to load balance between several Mongrels, each consuming > 100MB of RAM?
Java is just unpleasant to use - other than that, it is very fast and memory consumption is ok.
I host several projects on that one server (incubation...).
If you load lots of data in your app, it will use lots of memory. Doesn't matter what language it's in. It's a poor measurement of Java's memory requirement.
Without frameworks, it is probably OK if you already have a working web.xml. I used to just copy my working web.xml and modify it. Good luck if you want to create a working web.xml from scratch, though. The specification for a proper web.xml is a PDF with several 100 pages (last time I looked, a couple of years ago), and to parse it you basically need a scanner for XML specification files in your brain.
That is only for creating the working web.xml. Specifications for JSP and JSTL are several hundred pages on top of that.
Stripes looks to solve both of these problems while making it (actually) fun to do Java development. There's extremely little XML config setup.
There's not a single person I know that's familiar with Struts (1 or 2) and/or Spring MVC (or any other Java framework for that matter) that's tried Stripes, learned it in a day or two, and not really liked it.
Daoud also has a great book, "Stripes: ...and Java Web Development Is Fun Again" that's a great resource for starting out. In addition, the Stripes community is small enough that you can access the code contributors on a daily basis through IRC or the mail lists.
With Stripes-Reload and Stripersist, you can get a CRUD app up and running in under a few minutes--I think that's on par with RoR, isn't it?
IMHO, it's worth looking at.
Actually the web.xml spec got much worse somewhere in the increasing version numbers of Java Servlets. I rememeber just thinking "WTF" when I realized it was several 100 pages now. It definitely doesn't need to be that long, but I guess they wrote the documentation "enterprise style". It's just off-putting, who cares if the documentation could be simpler? They didn't make it simple, so I don't like it. Especially since the job of a Java developer is essentially digging through the mountain of specifications.
In my companies library there is a book "Handbook Of Java Development" with 1300 pages in small print. I think somebody left it there as a cruel joke.
Managing that stuff should be left the IDE, that's the sort of thing that XML was originally meant for, at least.
Anyway, if you are fine with Java, more power to you. The question was "why do few people here use Java" not "why nobody should use Java".
Simply collecting all of your Java libraries, frameworks, dependencies, etc and getting them running in your app server can take days. Minor changes like adding a db column can end up touching nearly every layer.
All these costs do have benefits. Java ORMs generate much more efficient queries than ActiveRecord, have more flexible querying, and better fit into existing schemas; JSP engines can render tens of thousands of pages per second; Java app servers are easily clustered; and much more. But most of that isn't something small or medium web apps use, so why pay the price?
I'm a senior engineer who codes for pleasure, so maybe I'm faster than average --- but if it's taking you days to get your libraries together and minor db changes touch every layer, you're doing something wrong.
It's unlikely you can do all that in minutes, so you're probably talking about copying an existing app template.
Adding a db column requires modifying the entity itself, DTOs, form beans, and of course the relevant JSP/templates. With Rails conventions you'd only modify the pages.
The JSTL is not a factor in speeding up development. A lot of people even prefer a Velocity or Freemarker template engine when they are using Java. And I've never worked with MyBatis but have done plenty of projects with Hibernate/JPA and let me tell you: I've often come at a point in a project where I was wondering how much time I had saved by not writing the easy SQL queries and how much time I had lost by trying to work around some random restriction in the Hibernate API. For all the "hate" Django's ORM gets, I've never run into the same obstacles.
With all that said, the Play! framework addresses a lot of these issues and is a lot more fun to work with.
It's difficult to quantify the increase in productivity using Django - since I never wrote the same project twice and a lot depends on the Java frameworks you use and the type of apps you write - but I certainly feel more productive and: happier! A lot can be explained by the fact that I'm basically forced to do the whole compile-war-deploy cycle on my current Java project and that Python allows me to write real generic code.
Be sure to first check out the tutorials in the Django docs because setting up a project for the first time can be a bit intimidating. Totally worth it, though ;)
OTOH, if you do all that heavy lifting in the JSP side, depending on your choice of server, you get a stack trace...either without a line number, or with a line number of the JSP which was compiled and turned into a Java program on the fly.
And we all know what machine-generated Java looks like, right? Like a big plate of pain with some extra pain on top. Good luck bug-hunting that one.
If the logs show an exception on org.apache.jsp.mypage_jsp._jspService(mypage_jsp.java:NNNN), you can find the generated Java class on TOMCAT_HOME/work/Catalina/localhost/myapp and it's rather straightforward from there.
I do this on a daily basis to maintain a legacy app. Not sexy but, not hard either.
IMHO deployment on the Java stack is not as fun. Time spent configuring Tomcat, Ant, and compiling code adds-up, especially for a basic web app or prototype. The Java stack also has a larger learning curve for beginners.
However, if you work on "enterprise" applications, especially ERP, finance and banking, Java is currently the lingua franca.
Second, real reasons: Java is verbose and statically typed, and therefore it takes more work to make changes - it is slower to develop in and less flexible/agile. These things really count when you want to try out an idea; and when you need to adapt it. There's also a community effect, where all those early adopters are working with Ruby/Python, that's the platform cool stuff gets developed for (eg. sinatra, github, haml).
Technically, it's possible to write a sinatra in Java (I have; using annotations for urls); but who would use it? I actually love Java myself, including its static typing, and use it in my startup. But when I've played with Ruby - even as a novice without knowing the tricks - I found it much quicker to develop in, and the code easier to understand because less cluttered. It's probably not as reliable; and the code doesn't run as fast; but these things just don't matter for prototypes and early versions.
Personally I find Java one of the easiest languages to make functionality changes in just because of the excellent refactoring tools that are available. People always claim to feel restricted by the language when they use Java. If they're using emacs or Textmate to edit it then sure, I can see that. Personally, whenever I'm writing something other than Java I feel desperately restricted by the tools - editors that don't have semantic knowledge of the program structure and just treat it all as text seem unbelievably primitive to me now after years of using IntelliJ.
Functionality changes require expressiveness, something Java lacks, due to its superfluous ceremony. Functionality changes require an ability to clearly see where and how things are done, and this is obscured by the extra noise of Java.
Java 5/6 went a fair ways to mitigating this... somewhat. And IDEs can help reduce extraneous noise (like IntelliJ's <~> for generics). But it's not eliminated, and it's not enough.
Java still has an impoverished model of abstraction and OO, it forces me to repeat myself continually (and having an IDE do the grunt work of repetition doesn't help--nothing should have to do it), and that both slows me down, and obfuscates meaning.
The tooling is the only thing that makes Java even remotely palatable.
My last class at Uni 2 years ago was a survey of web dev technologies. We built sites using ASP.NET, Perl, PHP and JSP. Java and asp.net were tied for worst experience ever. Setup and configuration of the Java stack was 2/3rds of the project. And, that's after taking 2 years of Java in school. Setting up a Java stack on a Ubuntu or a Windows box was equally as painful for me at the time.
My experience at school as made me loathe to try anything Java related. And, while I love the idea of the jvm, I have a pretty visceral emotional reaction to anything java related. I know it's wrong, but I can't even bring myself to do the installation required to mess around with Clojure or Scala.
I get the same vibe from a number of young developers I come across at Hackers and Founders SV meetups that have recently graduated from school. Someone mentions Java at our meetups and everyone at the table groans.
Python and Ruby are essentially lingua franca here in Silicon Valley startup culture, with C and C++ mixed in for speed. I've settled on Python/Django for day to day dev work.
In my case, even though Clojure and Scala look really sexy. The thought of installing a jvm based development environment makes me break out into a cold sweat. If I'm going to play around with a "sexy" language to learn stuff I'm going to play with Haskell, Erlang, or O'Caml, just to avoid using the jvm.
Another problem is the 5 to 15 minute compile, deploy, restart the server cycle.
And the nasty use of XML to integrate the half dozen frameworks which are never consistent from client to client. All of this is a huge blow to productivity.
I've had no more issues with configuring a grails stack than configuring a rails or django stack, are you referring to some other kind of java framework here?
Maybe it's the lack of a README concept that offers a high level intro to the library.
edit: maybe it's the font too. I have slogged through javadoc a few times when I've had to use java for something, but overall it's fairly high friction / annoying to learn an API via javadoc.
a) php b) rails c) Java + JSP/Servlets/JSTL/Tiles/Struts/Spring/JSF/Play/Wicket/GWT/Stripes/Tapestry/WebObjects
When using java, you will not use JSP, JSTL, JSF, Play, Wicket, STripes, Tapestry, etc, all at the same time. Unless you are crazy.
The same way, in Ruby, you will not use ERB, Haml, Erector, Markaby, or the other (at least) 19 template engines out there (http://www.hokstad.com/mini-reviews-of-19-ruby-template-engi...)
But this comparison is not actually fair, because you mixxed template engines with frameworks. To be fair, you'd have to add Sinatra, Camping, Rails, Merb, Ramaze, Padrino and Hobo to the Ruby list, and CakePhp, Zend and Symfony (at least) to the Php list.
It is not which language has the most options of framework/template engines, but which has the best optins. JSP is one of the worst template engines on Java land, and this is why it is not used as much (well, there is also the fact that it has a very bad reputation, and JSF is considered its successor, but it is worse nonetheless).
I love Python and work in it almost entirely now, but previously worked with Java (yes I know the joke about them being the same with the whitespace re-arranged).
GAE gets rid of most of the configuration and scaling pain. Plus it's free to get started. There are some limitations, but essentially it makes deploying Java web apps a snap.
http://code.google.com/appengine/docs/java/overview.html
For personal projects: I am a Grails guy. I love it. Dynamic methods on Model classes, no need of DAO's per say, GSP tags are great.
I have also developed using Python and Django. And loved it. Grails gives me that only in Groovy/Java which is awesome!
My 2 cents.
Now the basic servlet idea is pretty damn nice, and once you have your code written final deployment isn't that bad.
If you take away the rest of the stack and are just using JSPs... why bother? I have found a certain comfort zone using Django and I’m not going to switch to a different framework or language just because it’s possible; I would want to know why that alternative gives me a significant advantage over what I’m doing now.
Basically, it seems to me like Java web development uses XML as a dynamic programming language when they're trying to do something Java's not well-suited for. The issue is that XML has absolutely no type-checking at all, and so you end up with errors that make absolutely no sense when the only issues you have are simple typos.
The problem is even worse because you seem to end up having to specify the same information in so many different places, and having mistakes in just one of those will prevent anything from working.
I am sure there are ways around this, but the whole point is that if you're using a framework like Rails, you don't need to deal with any of this. It all just works, and having wasted months of time on Java web dev, I want to deal with a system that just works, not a system that requires ten or twenty kludgey three- and four-letter band-aids to get it to behave intelligently.
1. The memory footprint of the JVM is significantly larger for a similar app vs. PHP. Also, it requires a lot of tricky JVM option tweaking to get it to work in anything less than about 512mb.
2. The build environment is really heavy weight and complicated. Maven seemed crazy at first though working with it for a while finally got me used to it. It's still crazy complicated compared to rails/python.
3. Lack of code reloading when you hit refresh. JavaRebel fixes this, for a price.
4. Java code is really verbose. You have to become an expert at a lot of IDE features before you can get decent productivity. You absolutely cannot use a simple text editor or anything less than one of the big 3 IDEs (Eclipse, Net Beans, Intellij) and get anywhere.
The future is bright though for the JVM. I have started to work more with Scala/Lift lately and I am really blown away at how fast and powerful it is compared to traditional Java development.
2. It doesn't have to be complicated - it's the developers who make it so.
3. it depends on your server and configuration. Every server supports class reloading and jsp recompiling.
4. You don't have to - eclipse and netbeans are free and very powerful. Notepad for simple tweaks if you have to.
- The verbosity of Java wears on me very quickly.
- I can't stand working in an IDE.
- Documentation is abysmal.
- I'm not familiar with the ecosystem (so I don't know what to use and when -- What's 'Struts'? What's 'Tiles'?) and there doesn't seem to be a place to learn.
Are you saying this because you mostly work with smaller web apps, or other reasons? For larger projects I find IDE's (especially Eclipse for JAVA indispensable).
The reason I don't like them is that I don't want 90% of what it gives me. My 'IDE' is 1 gvim per project and a terminal app with a couple tabs. I can't think of anything an IDE gives me that I don't a) want or b) already have.
java and its frameworks are too bureaucratic. getting things done requires too much. in an enterprise environment with lots of developers, this is good. in an agile, rapid development type of environment with a small handful of people, this is bad.
the closest thing that i've come across that made me want to consider java apps development is grails.
For me part of the lure of JSP apps was that I really liked Tomcat as a development and deployment platform. For apps that needed a lot of background processing, I started work threads in servlet init methods, and liked having everything in one JVM.
I had one app running without restart for several years until my customer's admins let the server run out of free disk space. I am not at all confident of a Rails app running for 3 to 4 years with no restarts.
To answer your question: I might still choose JSP for high volume web apps. For apps with a modest number of users, Rails makes more sense for me.
To an outsider, it feels like there is a mountain of material to wade through before you can really get going with a Java webapp; for Python and Ruby, the perceived barrier to entry is much lower.
To be fair, the picture on Python isn't totally clear either. You can choose from Django, Pylons (my preference, btw), Turbogears and possibly others... and you have the choice between SQLAlchemy and the Django ORM, etc. Picking Python definitely does not alleviate the need to make some evaluations and decisions.
Java brings that kind of thing to the server, and I want no part of it.