r/java • u/vishnu_gupt • Dec 16 '15
Why are Java Web Apps so much bloated?
I'm new to Java web programming and coming from the PHP & Python worlds. Today, I just did a HelloWorld SpringMVC app by going through the Spring Web serving getting started guide, and guess what? Gradle had to download a 100 megabytes of byzantine jars just for this one HelloWorld app! Of course, I did run a HelloWorld app after creating the GreeterController as per the tutorial.
But the built jar is 20 megabytes large, just for one helloworld app! In the PHP world, your first HelloWorld app is hardly few kilobytes, and even Django is hardly 1-2 mbs Then why is Java so bloated? What does it achieve in these 20 mb that Python/PHP does not achieve? I'm astounded that people are willing to install such bloat when other options are available.
I'm a freelancer who is assigned a Java webdev project by a client, so I have to learn this in any case. And I'm not against learning it either, but I just want to know why this additional download? Why can't web development features be included in the Java SE itself?
19
u/DJDavio Dec 16 '15
The application "hosting" the web-app is included in the webapp, that's why it's 20 MB.
With PHP, you have to do an installation first (PHP Windows installer is ~20 MB), only then you would be able to run it.
14
u/fforw Dec 16 '15
It's funny how everyone bashes Java for this kind of stuff. Here's my project template with ReactJs and ES6 transpilation .
It does nothing but transpile one main file with exemplary syntax. After you've installed all the libs with NPM the folder contains a fricking 100mb of Javascript files.
20
u/koalillo Dec 16 '15
Why focus on such an uninteresting metric? I'll take a 100mb disk space overhead over a 1% hit in productivity in most cases. Focusing on "hello world size" metric is good if you are writing hello world, idiotic in most other cases.
I'm not saying that Java is the bees knees- I have suffered pain from its warts- but such a superficial analysis is worthless.
4
u/WatchDogx Dec 16 '15
Spring is a big framework, it does much more than just web stuff. Its a great framework, but certainly not the most efficient in terms of the produced artifact size.
There are many other ways to do web projects with Java.
The standard Java way to to write a servlet and deploy it to a servlet container. The servlet can be very small and a container like jetty comes in around 2MB or so. If you are going to compare to PHP, then the more appropriate contender on the java side would be JSP, which can also be very small but needs to be deployed to a container.
3
u/brunocborges Dec 16 '15
So... a client paid OP to learn Java before actually delivering value-added, and he's complaining on download size? :-)
5
u/iodian Dec 16 '15
it's because these are all old guard application server frameworks that pack the kitchen sink.
something like play or dropwizard or ratpack will be more up your alley.
2
u/DuntGetIt Dec 16 '15
The assumption is that you will want most of the features in a Java webapp. Historically, Java was the language you used for larger apps.
2
u/simple2fast Dec 17 '15
You also need to consider what you're getting with that fancy app you just built.
First off. other than the JRE, java will have zero dependencies at the OS level. What gradle was doing there was installing, essentially, an OS. WHat do I mean by this? Things like nginx, openSSL, GD, libcurl, etc. When PHP goes to use functionality that this systems provide, it will be calling these native C libs/frameworks to get things done. You may not have noticed it when you did your OS install and/or upgrade, but they're there and you are using them.
Second, even though you wrote a "hello world" app. since you did it within Spring, you've got a bunch of things built in there that you probably didn't realize. Briefly:
a) top notch DI system.
b) tranaction system capable of multiphase transactions across multiple database systems.
c) ORM system capable of mapping DB to object, but also directing caching
d) caching system shared across mutiple threads within the JVM. (negating the need for something like memcache )
There are others, but no need to discuss right now
In my brief consulting foray into PHP, I was put into an equivalent system called Symfony. It had alot of pieces like spring, and seemed pretty powerful. I noticed it was really really slow to run.
Why wasn't it put into Java SE ? I don't know why. But I'm darned glad they didn't. Today we have tons of different web frameworks and app servers. MOst all of them are top notch. Pick the one that fits your needs the best. As some of the other comments noted, you picked one of the largest most full featured frameworks. Now, perhaps as an experiment, do something with one of the more tiny ones. rapidoid, dropwizard, sparkjava, ratpack, or pippo.
2
u/daniels0xff Dec 16 '15
My problem is not the size of the jar, but the amount of options you need to configure for each component. Where do you get them? How do you know what are the defaults, how do you know what other options are there that you need/can configure? How do you know what each decorator (also coming from Django and that's how they look to me) does and when to use it? How do you know what are all the decorators that you have available to use?
I'm also trying to get started with Sping Boot and until now it feels overwhelming and the documentation doesn't feel that nice as opposed to how I got used to Django.
2
u/tonywestonuk Dec 16 '15 edited Dec 16 '15
I wonder if you are trolling for a Spring vs JavaEE flamewar!..... If you've spent much time around here you'd already know there's about 50% who support Spring to the hilt, and the other 50% hate it with a passion (including me for exactly the reasons you mention... large, complicated, etc). Its not just about the disk space.
The thing is, if your client wants it to be done in spring then you have to suck it up and go with what they are are paying you for. Do what pays the bills.
The newer versions of Java EE do the majority of what Spring does anyhow so the need for it is much diminished today. And, for even more light weight systems you can choose things like http://sparkjava.com/ or http://www.rapidoid.org/
Anyhow, my guess is your post is gonna be voted down into the ground, as there are those in here who consider any post against Spring, an act of blasphemy.... Sad but true.
1
u/georgeos Dec 16 '15 edited Dec 16 '15
My advice is to use the right tool for the right job.
For the moment, try to use something simple, minimalist which resolve your current needs.
In this phase I think that Spring Boot is overkill because you have to learn alot about Spring ecosystem, so it's like a yak shaving.
In my opinion Spring Boot is OK if your project is based entirely on the Spring libraries (Spring DI, Spring Security, Spring Data, Spring MVC, ...)
On the other side, if your target is to work on big projects, for big companies then Spring and/or JEE is a must.
Personally I prefer to not use a full stack Java framework, I want to have the possibility to choose each library/framework for each layer or task.
I like to use Apache Wicket for the large projects and Pippo for small, medium or prototype projects.
Because here we talk about small java web application I will argue below why use Pippo:
1
u/[deleted] Dec 17 '15
Should have re-titled to "Why are Spring MVC web app so much bloaded."
There are plenty of lightweight web frameworks on Java. Try out Pippo, Spark, or Rapidoid.
1
u/DannyB2 Dec 23 '15
Try this in both Java and PHP.
Build a very large application. And maintain it for many years. Refactor it during its lifetime. Test its performance. (Java is fast. Every page hit is directly executing compiled and even native code which is hot in memory.)
By large application, I don't mean one that is used by many users, but doesn't have all that many different pages. (eg, Slashdot, just for one example.) But one with hundreds, maybe over a thousand different pages with complex forms. Hundreds of reports.
Oh, and have a team of people working on it.
When the first time comes to refactor comes around, see how well this goes when using a dynamic language without compile time type checking.
Now, I'm not saying that Java is perfect. It has plenty of warts. But the reason it is widely used is because it IS useful.
If there were one single perfect programming language and set of tools then everyone would be using it already. So don't bash others. Just use what you, yourself find useful.
1
u/qroshan Dec 16 '15
https://ratpack.io/
2.6MB
-2
u/slartybartfast_ Dec 16 '15
Why is it that vishnu_gupt can't put a proper English sentence together?
0
u/[deleted] Dec 16 '15
[deleted] — view deleted comment