8 ms·
Developing and running a Java EE Hello World application
- S4M 12y agoI don't do web apps with java, so I honestly don't know if it's the proper way to do it, a satire, or if there is a more straightforward way. Especially, I don't see why one has to write both the class HelloWorldServlet and HelloWorldBean; couldn't one just inherit from one class or implement one interface?
- coldtea 12y agoYou could just have the servlet write "Hello World" directly. The Bean is not really useful in the example -- it's mean as a stand in, to know how to write one for your business logic needs, e.g user or product bean etc. (Btw, beans are just lightweight classes used mostly as structs, with getters and setters).
- smtddr 12y ago>>You could just have the servlet write "Hello World" directly. It's been years since I've had to write a Java webapp, but from what I remember using the servlet code to directly write the webpage output was considered bad. That was the job of the jsp file. e.g., "views" in bottlepy and Rails: http://guides.rubyonrails.org/layouts_and_rendering.html http://guides.rubyonrails.org/layouts_and_rendering.html
- coldtea 12y agoYes, it was considered bad style because of separation of concerns etc, but nothing necessitated JSP, you could just use servlets and any of tons of template libraries. And for a hello world, a servlet would do just fine.
- maaaats 12y agoThis page sets up an entire framework / java stack containing JEE, with some exampleclasses for stuff that will be needed later. So it's much more than a simple Hello World. Compare it to setting up any other framework: A lot of files and boilerplate configuration.
- klez 12y agoIs the point of this saying that J2EE is bloated and that simple operations are made seemingly impossible? Of course you wouldn't write an "hello world" in j2ee, what would be the point? All that stuff makes it easier later to write more complex stuff, so I really don't see the point of this submission.
- lukaseder 12y ago> All that stuff makes it easier later to write more complex stuff I sincerely doubt that. I've seen E-Banking systems run on Jetty with JDBC directly. No fancy JSRs were needed. Btw: J2EE was indeed even more bloated than JavaEE. I don't think that anyone would defend J2EE nowadays, not even the folks behind JavaEE
- lmm 12y ago> I sincerely doubt that. I've seen E-Banking systems run on Jetty with JDBC directly. No fancy JSRs were needed. If you need distributed transactions (and sure, most people who think they do don't), you use the fancy JSRs or you will go out of business. That stuff is hard and it's the reason JEE is so horrible, but it solves problems you can't solve any other way.
- lukaseder 12y agoYep. I understand the use cases of JavaEE's JSRs. Yet, I personally don't see why I should install a complete 300MB application server (possibly with horrific licensing) just because I happen to need one of their JSRs in just one part of the application (that happens to need JMS because the customer's CIO was walked into buying expensive licenses from IBM), which is otherwise mostly just transforming data between the UI and the database. It's just a JSR and I'm glad to buy licenses from a commercial JSR implementor...
- lmm 12y agoMaking technical decisions for non-technical reasons is always bad, whether that's a decision to use a particular technology or a decision not to use a particular technology. I think many users do derive value from having an all-in-one platform that provides all the JSR implementations they need and they can then just forget about.
- renke1 12y agoI think the usual way would be to use JSF and CDI beans instead of using EJBs and Servlets though. The only thing that is quite annoying is creating the web.xml from scratch for the first time. The shown approach is rather bad for simple (and modern) Hello World.
- IndianAstronaut 12y agoI don't think the point here is to get simple web apps up and running quickly. It is to build large scale systems that are stable. So yes, there will be overhead and lots of boiler plate stuff. Even projects like Django still have this overhead.
- pearjuice 12y agoTaking a cheap jab at Java EE just because their "Hello World" introduction article is a bit lengthy is bad form. Judging by the insulting "kids" reference in your title, Java EE has a completely different mindset than you are used to and the target audience doesn't include you. That doesn't mean the millions of other developers and billions of other platforms running Java are inferior.
- lukaseder 12y agoAt a previous employer, we've migrated a complex J2EE (with EJB 2.0 and such) E-Banking system to use only Jetty and JDBC directly. No one in operations noticed the difference. But the developers did. Oh they were about 5x as productive afterwards. With no missing features. Perhaps I'm not included in the target audience. But if E-Banking can do it, what remains of the "target audience" ?
- thorin 12y agoAgreed. It's also possible to use frameworks such as Spring Data/Boot, Roo or Grails to get started really quickly - a bit like the django/rails crowd. Lots of interesting things happening in Java world at the moment. It seems like originally Java drew from the mega complex enterprise application world influenced by people building large scale C++ apps etc so were hardly aware of the complexity they were adding. Now there is a lot of influence from modern web frameworks to quickly developing and expanding an app. Touch to maintain some of those old Java apps though from 5-10 years ago in some cases.
- sesm 12y agoThe problem with Grails is, like you said, it focuses on getting started quickly, rather then producing a maintainable and performant codebase. I mean, Hibernate is very complex in itself, and adding another layer (GORM) on top of it won't make things better. If I were to start a new java project, I would probably choose Dropwizard (http://dropwizard.io/ http://dropwizard.io/), which is more a collection of libraries then a framework.
- metafex 12y agoAnd yes kids, enterprise applications at large companies are exactly as hard to maintain as you may have guessed (after this article). Old legacy codebases in Java are one of the worst things I've ever seen. (spiked with old stuff nobody maintains anymore and also nobody pays you to upgrade, such fun times)
- svckr 12y agoNext time, kids, we'll do the same without support from our fancy IDE! O wait, no. Let's _not_ do that.
- Terr_ 12y agoApples and oranges. Its not supposed to be a small app, it's a skeleton being built to support something much heavier.
- gexla 12y agoSetting up any web stack is a pain in the ass and probably just as long of a tutorial. For example, write out a tutorial which goes from base Ubuntu install to "hello world" on Rails, I bet it's just as long or longer. I suppose it depends on how much detail you want to include. There are just more "one click" install options for other stacks.
- smtddr 12y ago>>Setting up any web stack is a pain in the ass and probably just as long of a tutorial. I beg to differ. http://bottlepy.org/docs/dev/tutorial.html#quickstart-hello-world http://bottlepy.org/docs/dev/tutorial.html#quickstart-hello-... http://howtonode.org/hello-node http://howtonode.org/hello-node (In fairness, I do note that the above examples don't actually have a <button> element to click on before showing helloworld like the Java example)
- deleted 12y ago[deleted]
- deleted 12y ago[deleted]
- troels 12y agoHow about: apt-get install php5 apache echo "<html><body>Hello World</body></html>" > /var/www/index.php The end.
- raverbashing 12y agoAnd this is why the last time someone said to me they were building their startup in Java I laughed (internally) This is ridiculous and unjustifiable. Really. Yes, I've already though otherwise (not with Java, mind you) It's a circlejerk of "developers" patting themselves in the back for creating solutions to the problems they themselves created. Like XML (which is still better than Corba, yay!)
- makach 12y agoAt first I thought this was a big wtf but really there isn't much to it. It is a rather good, detailed step by step documentation of how to set up a hello world example. +1
- AndrewDucker 12y agoExcept that that's not just a "Hello Word" page. That's routing to the right page, transaction and session control, storing the text of the message in a separate class than the one that returns the response, and using a template to return the resulting HTML. Looking at the section with the actual example code in it, you could do it in about half that, if you wanted a simple version that just returned "Hello World". If you don't want routing, templating, separation of concerns, etc. then you wouldn't be using a framework like that, of course.
- yazaddaruvala 12y agoI think its satirical. We all know Java's Hello World is ~10 lines long. I think the point/joke is that Java EE devs don't keep things simple. Or rather, better put, Java EE devs always want "routing, templating, separation of concerns", because they consider it better, no matter the current problem at hand.
- raverbashing 12y agoThis does almost everything (and sending it to another class is pretty trivial): http://flask.pocoo.org/docs/0.10/quickstart/ http://flask.pocoo.org/docs/0.10/quickstart/
- AndrewDucker 12y agoYup. And by the time you've done all of that, it's not vastly smaller than the code in the original example. (Also, your setup is spread across every class registering itself, rather than in one central XML file that tells you all of your routing.)
- raverbashing 12y agoNo, it's usually done in a separate file containing all the routing (in most Python frameworks) And no unreadable and overcomplicated XML for configuration, thank you very much
- davidgerard 12y agoI used to joke that "hello world" in Java was twenty files and two security holes.
- Koziolek 12y agoAnd now kids let's build something little more complicated. App with distributed transactions in cluster (each step on different node). Full JEE stack is terrible if you would like to write sad CRUD applications. But if you need something more than simple access to DB it is very good solution.
- brianmcc 12y agoThis is not a simple Hello World app, it's a minimally viable end to end EE stack using one particular combination of many available technologies, intended to be deployed within an app server. And I am pretty sure OP knows it if he's deploying apps with "just Jetty and JDBC". Big deal; so what? Why the snarky post?
- kev6168 12y agoI laughed at the end. Reads like a badly written TV script, with so much buildup, tension and all kinds of weird characters in the beginning and middle of the show, then at the end comes a huge anticlimactic duh. "Hello Word!".
- fsloth 12y agoI'm a complete foreigner to web development and JVM. I've been dabbling in setting up Clojure projects a bit at home. It took a one command line call approximately (lein something-something) to get the more or less equivalent web stack up and running (to my understanding). After reading this, I suddenly understand how awesome that was.
- smegel 12y agoNot sure whether to laugh or cry.
- estefan 12y agoHa! What a load of crap! I can't see this "Java" catching on...
- realusername 12y agoI've also done some JEE quite a long time ago and I hated every second of it. I'm not sure however if my experience is representative of the the Java community. There is no problem with the language itself nor the VM which is also working quite fine (while taking a lot of RAM). But I really have a problem with the community, everything seems over-engineered and super complicated in Java, even with simple things. Nothing works by default, you always have to include stuff here and there, write one or two xml files before anything would work, I'm fine with configuration but I should at least work by default. Maven is a nightmare to use, it's so complicated I would generally not use it. I would just like a package manager which is only doing packages like any other language. The main problem with the Java community in my own opinion is they are building pyramids while other languages are building stuff out of bricks, it's the opposite of the UNIX philosophy.
- metafex 12y ago> they are building pyramids while other languages are building stuff out of bricks Pyramids are engineering feats, Java EE people are building stuff which look like works from M. C. Escher, it bends your mind when you try to understand the code :) Also a little anecdote to the complexity of enterprise stuff: at the company I worked before, they were writing an entire persistence framework from scratch (with annotations instead of xml) so they could get away from hibernate.
- Sven7 12y agoAlso well known as the Enterprise Software Engineer Employment Guarantee Scheme
- flavor8 12y ago> they were writing an entire persistence framework from scratch (with annotations instead of xml) so they could get away from hibernate. As opposed to using MyBatis or JDBI? What was their rationale for rolling their own, too many employees on the team?
- konradb 12y ago> Maven is a nightmare to use, it's so complicated I would generally not use it. I would just like a package manager which is only doing packages like any other language. Before Maven, generally I remember there being Ant. And I remember that if an application needed dependencies, unless one explicitly used a dependency manager like ivy, one had to go find the jars and download them, and ensure they were on the class path. Ant was simpler, in the sense that if you wanted something to happen, you would create an ant target and instruct ant on what was going to happen. Maven isn't simple in the same way, so it does require one to learn more about how it works in order for things to fit together, but I find it drastically simplifies working with java projects. The location of all dependencies are defined, they are downloaded, and there is default behaviour to be expected with each of the maven goals. Overridable properties enable one to have a build which works first time directly after checkout. I much prefer it to what was there before. If we look at what has come since - sbt, gradle, and leiningen all seem to use a similar mechanism to Maven for dependencies.
- jupake 12y agoThis looks like a deliberately anti-java post or something taken completely out of context.
- th3iedkid 12y agoi don't think the point of the article is to introduce JEE , its rather in the very first line : >>"This tutorial is intended to help you get started with developing applications for Java Platform, Enterprise Edition (Java EE) in IntelliJ IDEA. " They intend to show all JEE bells and whistles in one tutorial so that , people can look at this and know what they need to do to work on IntelliJ developing JEE application. Not starting out on JEE itself.Which to be honest might require more of a different learning curve ,
- laichzeit0 12y agoThe main problem with JavaEE is hardly the development part. It's the maintenance and support part. When relatively inexperienced programmers write complex applications (because it makes this easy) and then something goes "wrong" in this pyramid of abstractions and layers and layers of libraries / frameworks interacting with one another and the application servers. That is when it gets interesting. Yeah there are great production performance monitoring tools like Dynatrace but it's not a silver bullet.
- tulsidas 12y agoI flew an 747 last week to go to the store round the corner, didn't make sense either
- mangecoeur 12y agoLackey: "Boss! Boss! Our system is a hopelessly complicated, over-engineered monstrosity! The "Hello World" tutorial is 20 pages! Our business is doomed!" Boss: "Calm down Jenkins. Just write 'Enterprise' in front of everything, the suits will love it!"
- raverbashing 12y agoHeh it works for IBM
- lennartcl 12y agoAhh Enterprise. Protip for anyone applying for an enterprise job: just copy-paste https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpris... when they do the mandatory fizzbuzz test in the job interview. And then complain in the github issue tracker if you didn't get the job.
- zero-g 12y agoThere definitely should be some IoC container.
- deleted 12y ago[deleted]
- jpgvm 12y ago2/3rds of the page before you start writing code. -_- And people wonder why it's going extinct...
- ris 12y agoI think as much as anything this shows how using GUIs for complex things can just have the effect of making them exponentially more complex.
- assertnotnull 12y agoJava main feature: fast on JVM, not on the dev. I've worked for 5 months to make a 4 pages - 3 grid & upload form using GWT, Spring, SOAP.. seriously?? It's a different stack but still it's overkill. You know what is the best part? our app is not even scaled. Why are we bothering then? Do we crunch tons of data to justify the need of a JVM? No. Is speed really a concern? It seems not.. I didn't even hear we are doing caching. It's only transform database beans to DTO and modify for display. Java is not a technical requirement here. It's just a lazy business standardisation solution. To me It's like, the enterprise wants a flyswatter to kill a fly but you end up with a bazooka factory and the fly dies of age. But the bazooka factory is very efficient on the CPU. That's the important part you know..
- insin 12y agoAlternatively, here's Adam Bien's (JSON) version of Hello World with JEE: https://www.youtube.com/watch?v=zESNqWcY0pY https://www.youtube.com/watch?v=zESNqWcY0pY
- eskimo87 12y agoIt's way easier to run a Hello World web app with Netbeans!! In fact, a new web app project by default creates a project with default settings/xml with index web page saying "Hello world" - it can't get any simpler than that! give it a try :-)