75

I need to decide between jQuery and GWT for my new project.

I haven't programmed in JavaScript for a while, and I was looking into GWT for the last few days. It looks pretty awesome, generating all the different JS for different browsers and all, however:

  • developing in Java takes more time than the same thing using jQuery (at least for this project)
  • the documentation is poor (for example, how should I know which elements should I use when designing the page? -- there's not enough documentation for this)

I've been using jQuery for most of my projects and it's pretty good.

I want to convince the client that jQuery is better suited for this project and I need more arguments to support this.

Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192
BobiYo
  • 962
  • 1
  • 6
  • 11
  • 13
    gwt uses Java and generates html+javascript – BobiYo Jul 30 '09 at 08:54
  • 1
    I think he meant Java - writing code in Java which GWT will generate the appropriate JavaScript for the client. See http://code.google.com/webtoolkit/overview.html – Russ Cam Jul 30 '09 at 08:56
  • @Chris GWT makes the dev write code in Java and then when handling the request delivers the java in javascript for that particular browser type – AutomatedTester Jul 30 '09 at 09:02
  • Ok, sorry for jumping the gun on the Java/JavaScript comment. Boban, if you're using gwt to generate html+javascript I'm not sure that jQuery can be used as a replacement for gwt. Can someone correct me on this or am I missing the point? – Chris Nicol Jul 30 '09 at 09:21
  • It's true that both of them can't be compared because they both have different concept, I personally like to use jQuery for the project, but beside the argument that it will take twice as much time developing with gwt than with jQuery(100% sure for this project), I need to come up with more arguments :). Thanks for showing interest in this matter Chris. – BobiYo Jul 30 '09 at 10:45
  • This looks more or less primarily opinion based. Both are good technologies with they strong sides. – Audrius Meškauskas Aug 21 '14 at 19:03

14 Answers14

63

I would go with JQuery.

I once maintained a GWT project that eventually forced me to re-write it twice. First as a refactored GWT app, second in JQuery.

I haven't touched Javascript seriously for a very long time. The last time was about 2002. I'm a Java developer so my first impression of GWT was awesome. But that was just the impression.

Problems I found with GWT:

  1. It forces you to follow its client/server structure. In the end all I want is AJAX and those good widgets. GWT's widgets by itself don't seem that good-looking. Aesthetically, I prefer Adobe Flex! But to keep the comparison closer, JQuery's UI looks better than GWT's. In addition you have that wonderful Theme Roller support from JQuery.

  2. I've tried DWR. It's great. It's far easier to enable AJAX in your Java code using DWR than GWT.

  3. If you're using GWT, eventually you will be forced to learn JavaScript. Arjen of SpringSource once said about XML and SOAP (though not the exact quote): "How can you develop WebServices and not know XML? SOAP is XML. You can't avoid it". Same thing with GWT. It's still Javascript in the end.

  4. Realistically, Javascript isn't that hard to learn vs Java. More people know Javascript than Java. Even web designers know it. You're a programmer, and you're scared of Javascript?

  5. Back to the project I rewrote. When I rewrote our GWT application it took me almost two months to rewrite it. With JQuery it took me two weeks, and I was rusty with JavaScript.

  6. With JQuery you don't really write hardcorde JavaScript. That's why you use JQuery in the first place. Maintaining code with GWT is horrible. You wanna see the latest changes you did in the code... go compile... wait for GWT... 5 minutes... rinse... and repeat and hope it doesn't throw an error. If it does, you'll be recompiling again, and waiting for another 5 minutes. Rinse and repeat. With JQuery change a line, refresh your browser. Done.

I know I'm not being objective here, but I'm just sharing my experience :) The moral is don't be scared of Javascript. Google uses Javascript anyway

Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192
chris
  • 3,820
  • 6
  • 36
  • 36
  • 1
    i just need to compile it once and keep refreshing the webpage if i have any update :D – Chan Le Aug 11 '11 at 19:37
  • 3
    Chris - have you looked at GWT 2.*? Would this version make a lot of what you mentioned better? – Ray Sep 15 '11 at 09:46
  • Fair points. Waiting for 5 minutes for a small change is really a killer. – Rafal Rusin Oct 02 '11 at 10:24
  • 2
    Regardless of the language choice, you may feel the need to rewrite any application (it's hard to blame that on GWT). There are Java applications or even web applications that I've seen that I would love to rewrite just because they are poorly written, not just because it's Java. This doesn't mean that Java is to blame - it was the original writer(s) of that Java code. I do agree with the compile time issue taking up too much time. Also, writing a lot of JavaScript can lead to code that is just as unmaintainable if your developers aren't disciplined. – Lo-Tan Oct 10 '11 at 23:20
  • 9
    I use GWT with Maven, which enables me to only compile the server side of the application when I make changes on the server side. And when I make changes only on the client-side, the GWT debugger immediately reflects those changes.. so the only time I have to wait 5 minutes for the GWT compiler to finish running is when I make modifications that affect both client-side and server-side, such as adding new RPC services, which is something only likely to happen in the very beginning of development and very sporadically after that. So I can say that debugging GWT is nothing like you're describing. – Renato Dec 28 '11 at 12:26
  • GWT does not require a server, and you can use REST from GWT just fine. – Lincoln Sep 29 '12 at 19:58
  • OMG, well, ... just forget GWT for me. – neoedmund Nov 08 '12 at 08:58
  • The quality of widgets shouldn't really be a point here. With GWT or jQuery you can take or leave the widgets that come out of the box. – fungus1487 Jan 25 '13 at 09:44
  • 1
    For JAVA developers sometimes it seems good choice , compiling time is sucks in GWT , on the other hand debug in Java code and find error is a great thing in GWT, currently we are suing GWT is one of our project and it works for us nicely still , such as complex GRID, is helping us , but specific structure is not comfortable for developers at all , some GWT widgets are not powerful at all, we mixed GXT with GWT for better look , GWT look is not convincing at all , so we workout with mixing GXT + GWT + Smart GWT, but i think this will lead us to problematic code maintainability – Asraful Apr 17 '13 at 05:53
56

I would suggest using GWT for teams with people who don't understand JavaScript but are (perhaps) more comfortable with Java. With GWT, you're likely to save yourself days if not weeks in compatibility testing, and will avoid a lot of common JavaScript pitfalls that people new to the language smash into. GWT also has great packaging features for CSS sprites, embedded data, and more.

However, if you know and understand JavaScript, I would use JavaScript, whatever your library of choice may be. Although I haven't had a chance to inspect GWT's generated code too closely, I saw some examples at Google I/O, and while it looked all candy and sparkles, you're likely create more elegant JavaScript code doing it the ol' fashioned way.

Community
  • 1
  • 1
Justin Johnson
  • 30,978
  • 7
  • 65
  • 89
  • 1
    I recently posted on the subject: http://phiz.posterous.com/gwt-its-not-you-its-me – AlexJReid Jul 30 '09 at 21:50
  • 22
    You do not debug Javascript code, you debug Java code. – Alberto Zaccagni Jan 01 '10 at 23:38
  • It's nice not to be bound to a frameworks javascript implementation. Had a problem with this in wicket, where some of the javascript didn't work with IE8 for instance. Had to override it and wait for the next release. – Espen Schulstad Aug 02 '10 at 22:26
  • 1
    @Alberto, I don't think Justin meant it like the way you point it. He meant "debug" in a more general meaning. – chris Dec 19 '10 at 14:23
  • 1
    i had a relatively complex GWT project and had it up and running without ever touching javascript. This is a credit to both Google and to GXT. – Jorel Jan 13 '11 at 16:42
  • 1
    @Espen You're still bound to something, except now it's GWT (which is neither necessarily bad nor good). – Justin Johnson Feb 01 '11 at 22:45
  • GWT performs [many optimisations](http://buzdin.blogspot.com/2011/02/gwt-compiler-optimizations.html) when compiling client-side Java into JavaScript. It is unlikely that hand-written JavaScript can be so efficient. – Rok Strniša Nov 22 '11 at 19:17
  • -1 for not mentioning jQuery, which was what the OP was about. – Matt Fenwick Feb 04 '12 at 15:30
  • 1
    @Matt Don't be ridiculous. It's perfectly valid to provide information about only part of the question. – Justin Johnson Feb 09 '12 at 23:17
18

If your group is most familiar with Java and you're planning on doing significant amounts of client-side functionality then you should at least evaluate GWT. The type safety, Eclipse debugging and shared code between the server-side/client-side will feel comfortable to your Java development team.

However, if your team is used to JavaScript programming with jQuery or another JavaScript library then it may be easier to stick to a technology that is pure JavaScript. GWT has a way of taking over large sections of the page, which is unfamiliar to most JavaScript developers. By take over the page I mean that typical GWT code likes to create its own DOM Elements instead of adding functionality to existing Elements on the page. This is why many GWT apps have a "loading..." screen when the page first loads. This isn't necessary, but it's the most common style of GWT development.

The fact that generated code comes out of GWT is less relevant for most GWT developers. GWT allows you to compile Java into something equivalent a normal java *.class file but in a JavaScript syntax that the web browser understands how to interpret. GWT acts much more like a compiler than a template-driven code generator. There are times that you will need to inspect the generated code but for the most part your debugging will be in Java via your Java debugger.

Another thing to think about is that regardless of the client-side technology you choose, your development team will need to be familiar with HTML, JavaScript, CSS and browser programming in general. GWT lets you write client-side code in a familiar Java environment but it doesn't hide the fact that you're working from within a browser.

15

First of all comparing GWT with jQuery doesn't make much sense. While jQuery was build to make cross browser working with the DOM much easier, GWT is build to create large web applications.

So if you a bunch of static sides with some independent widgets, like calendar, slider and so on, jQuery is enough. If you want to build single page app, maybe with a large team, GWT is the better way. GWT has a lot well design architecture under the hood, especially the build in MVP pattern, UI-Binder templating system, i18n support etc.

So as JavaScript developer working more than year on a large GWT app, I would recommend never ever build a single page app only with jquery cause it wasn't build for. If you wanna use JavaScript take a look at backbone, spine, knockout or dojo.

Btw, as good the GWT architecture is build, you will have a lot of JAVA overhead. So if you project is growing, the time to compile your css and i18n properties will come annoying.

Andreas Köberle
  • 106,652
  • 57
  • 273
  • 297
  • 1
    A nice JS framework for building applications is [Enyo](http://enyojs.com), that is somehow more comprehensive than backbone oder knockout. – inta Sep 06 '13 at 21:34
10

The answer is not easy. The answer is "it depends":

GWT:

  • if you know and like Java
  • if your server code is also written in Java, writing client code in Java makes it possible to use the same code on client and server
  • if you like things provided by strongly-typed languages: compile-time type checking, automated refactoring, automated code generation (Ctrl+1 in Eclipse), code completion (Ctrl+Space)
  • if you like component-oriented programming (eg MenuBar creates a menu)
  • if complexity of GWT (compared to jQuery) is not problem for you
  • if big generated code is not a problem for you

jQuery:

  • if you know and like JavaScript
  • you don't need to use the same code on client and server (eg. client - JS, server - Java or PHP)
  • if you don't need compile-time type checking, automated refactoring, etc
  • if you don't need component-oriented programming (to create a complex component in jQuery you need to create a series of divs, and call $("those divs").makeXXXXControl())
  • if you like simplicity (jQuery is simpler than GWT)
  • if you need very small code (eg to make website loading faster)

Personally I would recommend GWT for most projects, but jQuery also has pros and some people may prefer jQuery.

iirekm
  • 8,890
  • 5
  • 36
  • 46
10

"Horses for Courses"

Pick whichever one makes the most sense for the project. Some things to consider

  • Tight timescales and more familiar with one over the other
  • Speed and maintainability for other developers to use the chosen tool. Prevalence of one over the other may have implications here too
  • Have any code that could be used already in the project e.g. plugins, utility functions, etc.

Without knowing specifics about what the project is about, what your experience is and how open the client is to using different technologies/frameworks, there will be no decisive answer here.

Make that list of compelling arguments for one over the other, as I have started here and then discuss with others involved on the project to come to a conclusion.

Russ Cam
  • 124,184
  • 33
  • 204
  • 266
3

I agree with Russ Cam that it depends on what your team is familiar with. When I am doing work for my personal business apps, I much prefer GWT. I find javascript, even with jquery, to have annoying object oriented syntax. If you have an app with 10,000 lines of UI code, jquery strikes me as something that would lead to a mess of hard to maintain code with poor reuse.

Does anyone know of a large scale project done in jquery?

I think if you are trying to squeeze every last byte out of the resulting filesize, don't use any library and write the javascript from scratch (ie: google homepage fade effect).

Something to think about regarding javascript/jquery versus gwt. If you use common object oriented principles and design patterns, you will likely get better performing code with gwt. Why?

Let's take the example of polymorphism. If you write an app that uses heavy polymorphism in javascript, you will get the benefit of maintanability and code reuse this provides. However, your code will also get the performance hit of using polymorphism.

Now, if you used gwt, you will also get the benefit of maintanability and code reuse this provides, BUT the gwt compiler will optimize away the polymorphism into concrete class usage, hence increasing performance.

davidjnelson
  • 1,111
  • 12
  • 22
  • 3
    Some huge projects that use jQuery/Vanilla Javascript: Gmail, Google Reader, Google Maps, Grupon, Shopify, Facebook... The problem is just to know how to use Javascript. And you should compare Backbone/Knockout/Angular with GWT, not GWT with jQuery. – Celso Dantas Mar 28 '13 at 04:55
3

I think GWT is too much abstraction. Javascript is in fact a powerful language. You can write object oriented code and use namespaces. With a library like jQuery you won't have to worry about browser compatibility issues for most of what you do. With all the great browser developer tools available (like Firebug) in all major browsers now a days it is very easy to work with javascript. When a javascript error occurs I can easily pinpoint where it happened in my code. I can watch variables and know all that is going on in detail because I am working against code I wrote (unlike GWT).

David
  • 47
  • 1
3

The main problems I see with GWT vs. a native Javascript solution (jQuery or others) are:

  • There is an additional process that separates you from your final product. You develop your app in Java and you debug the Java code, yet you release a machine translated version of this code. For a decently sized app I can't imagine that you won't need to debug the actual code running on the browser at times, and this is going to be a headache, since it isn't your code.

  • Since you write your code in Java you are limited to use Java libraries. If you find some JS library that you like it would be awfully difficult to add it to your GWT project, you may need to write a Java wrapper for it. If you are developing native JS you can just add it to your project.

  • JS is an awesome language in its own right, with a solid object model that is different than Java's. I have developed a few apps in native JS for HP webOS and was surprised to find that many of the preconceptions I had about the language were not true. You can write clean, efficient and maintainable code in JS as much as you can in Java, and if you take the time to understand the JS object model you won't even need to use a support library to mimic a more typical class/object model like those of Java and C++ on top of JS. Javascript's prototypes are pretty cool.

  • If you may ever consider releasing your app on mobile platforms, then a native JS app can easily be wrapped inside phonegap and have access to several mobile platforms, without additional effort. There is a GWT wrapper for phonegap as well, but going back to my first item, if you have the choice to work with the real thing then why choose a solution that requires translation/emulation?

Good luck.

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152
2

All the great tips and no one spoke about JSNI! A feature in GWT that allows you to use javascript if you wish.

https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsJSNI

Sib
  • 21
  • 1
2

jQuery = low-level understanding

Aside from the normal one javascript and the other is java explanation, Jquery has a closer one-to-one mapping with javascript while GWT is more abstracted away. So if you prefer to have a deeper understanding of what's happening with your code at the low-level (javascript) then jquery is the right way.

GWT = abstraction understanding = functional guarantee

GWT offers the advantage of compiler generated code so it may offer more of guarantee that your website will function normally. However like any large scale API you need to take the time to understand what this class does and what that class does and whether or not it is compatible with this API or nor.

low-level understanding may be more useful

Personally I get much more satisfaction from coding the low-level myself. I have built some web applications at work from pure javascript that functioned flawlessly. Once wrote javascript code that took data from a database and generated a complete microsoft word research report. The complexity of this project demanded a lower-level grasp of javascript. I'm not sure this could have been done easily with a java based solution.

GWT reassures managers but costly

But then again java and asp.net tend be preferred by larger companies b/c there is greater technical support (i.e. Oracle and Microsoft) and uptight on-the-edge managers tend to get better sleep at night when they know they can solve problem A by simply paying x amount of dollars for support. So after adopting the system they soon start realizing that technical support costs too much and it's cheaper to pay more for better developers. Hence a java or .net career will usually put food on the table.

Maintainability

Also API's like GWT are easier to maintain. I could only imagine the horror that someone would go through if they had to debug my javascript code. But that was before I became a better and cleaner programmer and since I knew every aspect of the code there is nothing to debug b/c there was never a problem with it.

Low-level coding gives you almost a 100% understanding of what is happening, however with API's you spend time playing bug detective on google and posting questions on sites like StackOverflow. But managers don't understand this b/c most aren't programmers.

oHo
  • 51,447
  • 27
  • 165
  • 200
1

GWT is a compiler (Java to JavaScript) and jQuery is a framework. You don't have to choose one over the other. You can use one of them, both or neither.

For instance you can code in Java if you want to or have existing source code and then use jQuery for other stuff. There are available wrappers, but GWT can call JavaScript (and vice versa) see http://svenbuschbeck.net/wordpress/2012/06/how-to-use-jquery-in-gwt/

liftarn
  • 429
  • 3
  • 21
0

my personal opinion would be for jQuery but thats because I never use Java and really like using the jQuery plugins.

AutomatedTester
  • 22,188
  • 7
  • 49
  • 62
0

Active user group and recent gaining popularity clearly indicates jQuery is the winner.

rajakvk
  • 9,775
  • 17
  • 46
  • 49
  • 1
    it depends on what you are doing - there is no one size fits all library out there. jQuery is great for progressive enhancement of an existing marked up page, while gwt is meant for building complex, large scale application UI in the browser. You'd probably find it hard to make the google Wave client UI using jquery. – Chii Jul 31 '09 at 02:44
  • 7
    Php is also a winner too but that doesn't mean we should use it – Roch Jan 12 '10 at 15:32
  • 1
    then PHP must be the best thing in the world – Jaroslav Záruba Jun 09 '12 at 14:31
  • it depends on specific situation – Asraful Apr 17 '13 at 05:55