GWT – Pros and Cons

I love JavaScript. With the advent of jQuery and Mootools, my love for JavaScript has only increased plenty-fold. Given a choice I would use either of the aforementioned frameworks for any web application I develop. But being in the service industry, time and again I have to succumb to the client’s pressure and work in their choice of technology – whether or not it is the right one (The one who pays the piper calls the tune. Isn’t it?). One such client exposed me to the world of GWT.

I have given GWT a shot couple of years back on the day it was released. I didn’t like it that much then, so I dismissed it and never returned back. But, over the past six months working on this project I have a slightly different impression on this framework. I still cannot say that GWT is the next big thing since sliced bread, but at least it is not as bad as I thought it was. I have just documented my observations, both good and bad during the course of this project and thought some fellow developer might find it useful while evaluating GWT.

Pros:

  1. If you are a Java veteran with experience in Swing or AWT, then choosing GWT should be a no-brainer. The learning curve is the least with this background.
  2. Even if you are not experienced in Java GUI development, the experience in working on server-side Java for years will come in handy while developing GWT apps
  3. You can create highly responsive web applications with heavy lifting on the client-side and reduced chattiness with the server-side
  4. Although there are numerous JavaScript libraries out in the wild and most of them are worth their salt, many conventional developers don’t understand its true power. Remember, a powerful language like JavaScript is a double-edged sword. If you don’t know how to use it, even you won’t be able to clean the mess you create
  5. You can migrate from a typical web application to a GWT application iteratively. It is not an all or nothing proposition. You can use a clever trick called JSNI to interact with loads of JavaScript functions you already possess. But it is always better to move them to GWT sooner rather than later
  6. The IDE support for GWT cannot be better. Java IDEs have matured over the past decade to be one of the best in the world and GWT can take direct advantage of it
  7. The integrated debugging beauty is something you can kill for. The excellent debugging support offered by the mature Java IDEs is one feature that could sway anybody’s decision in favor of GWT
  8. The built-in IDE support to refactor Java code can directly be put to good use to maintain a simple design at all times. Doing this in JavaScript is not for the faint at heart
  9. The IDE syntax highlighting, error checking, code completion shortcuts etc are overwhelming – to say the least
  10. GWT is being actively developed by Google. We know that the project is not going to die off anytime soon. Until now their commitment towards the project says a lot about its future in the industry.
  11. The community behind the project is also a big PLUS. Discussions take place daily in Stack overflow, discussion forums, wikis and personal blogs. A simple search with the right keyword could point you in the right direction
  12. GWT is a well thought-out API; not something that was put together in a hurry. This helps you as a developer to quickly comprehend the abstractions and makes it really intuitive to use
  13. You can use GWT’s built-in protocol to transfer data between the client and the server without any additional knowledge of how the data is packaged and sent. If you prefer more control, you can always use XML, JSON or another proprietary format of your choice. Even in that case, while using JSON, you don’t have to use an non-intuitive java JSON library. You can use JSNI to ‘eval’ the JSON using straight javascript. Cool huh!
  14. You have the advantage of being able to use standard Java static code analyzers like FindBugs, CheckStyle, Detangler, PMD etc to monitor code and design quality. This is very important when you are working in a big team with varying experience.
  15. You can use JUnit or Test NG for unit testing and JMock or another mock library for mocking dependencies. Following TDD is straight-forward if you already practice it. Although there are JavaScript based unit testing frameworks like jsunit and qunit, come on tell me how many people already know that or are itching to use that.
  16. The GWT compiler generates cross-browser JavaScript code. Today, any marketing person who says this will probably be beaten. It has now become a basic necessity, not a luxury
  17. The GWT compiler optimizes the generated code, removes dead code and even obfuscates the JavaScript for you all in one shot
  18. Although the compilation process takes hell a lot of time, you don’t have to go through that during development. There is a special hosted mode that uses a browser plug-in and direct java byte-code to produce output. That is one of the main reasons you are able to use a Java debugger to debug client side code.
  19. Rich third-party controls are available through quite a few projects like Smart GWT, Ext GWT etc. They are well designed, easy to use and theme-able. So, if you have a requirement where existing controls don’t just cut it, you should be looking into one of these projects. There is a really fat chance that one of those components will work out. Even if that doesn’t work out, you can always roll out your own.
  20. GWT emphasizes the concept of a stateful client and a stateless server. This results in extremely less load on the server where many users have to co-exist and high load on the client where only one user is working
  21. I18N and L10N are pretty straight-forward with GWT. In fact locale based compilation is taken care by the GWT compiler itself. The same cannot be said about regular client-only frameworks
  22. GWT comes built-in with browser back button support even while using AJAX. If you are an AJAX developer, I can almost feel your relief. This is priceless.

Cons:

  1. GWT is a fast developing project. So, there are a lot of versions floating around. Many functions, interfaces and events get deprecated and keeping up with their pace is not too much fun when you have other work to do
  2. There were quite a few GWT books during the beginning. Not so much these days. For example, I haven’t found many books on the 2.0 version of GWT. This leaves us only with Google’s documentation. I agree that the documentation is good and all, but nothing can beat a well written book
  3. GWT is not fun to work with. After all it is Java and Java is not a fun language to work with. If you add the fact that entire layouts and custom controls should be created in java, you can easily make a grown programmer cry. With the introduction of UI binder starting version 2.0, that problem is kind of solved, but now you have a new syntax to learn.
  4. The Java to JavaScript compilation is fairly slow, which is a significant con if you choose GWT.
  5. I personally prefer defining structure in HTML and styling it using CSS. The concepts used in HTML are clean and straight-forward and I have years of experience doing just that. But in GWT, I am kind of forced to use proprietary methods to do the same. That combined with the fact that GWT doesn’t solve the styling and alignment incompatibilies for me compounds the problem. So, writing layout code in GWT is something I despice. But with UI Binder and HTMLLayout from version 2.0 onwards, I feel I am back in my own territory
  6. It requires some serious commitment levels to get into GWT, coz, after that, a change in client side technology could require a complete rewrite of your app, as it is a radically different approach than other client side frameworks
  7. There is not a defined way to approach an application development using GWT. Should we use only module per app or one module per page or somewhere in between. These design patterns are slowly evolving only now. So, typically people tend to develop all in one module until the module size goes beyond being acceptable and then they refactor it into multiple modules. But if it is too late, then refactoring could not be that easy either
  8. Mixing presentation and code doesn’t sound right although typical desktop GUI applications does just that. But these days, even desktop application frameworks like Flex and Silverlight have taken an XML based declarative approach to separate presentation from logic. I think GWT 1.x version had this disadvantage. With the introduction of UI Binder starting from version 2.0, I think this disadvantage can be written off although it is yet another painful XML language to learn
  9. You would often be punching in 3X to 5X more code than you would with other client libraries – like jQuery – to get simple things done
  10. You should also remember that with GWT, the abstraction away from HTML isn’t complete. You’ll still need to understand the DOM structure your app is generating in order to style it, and GWT can make it harder to see this structure in the code.
  11. GWT is an advantage only for Java developers. Developers with .NET or PHP background won’t gain anything here
  12. If you have tasted the power of JavaScript and know how to properly utilize it to your advantage, then you will feel crippled with an unexpressive language like Java

I am sure many of you will have differences of opinion. Difference is good. So, if you think otherwise, feel free to leave a comment. We’ll discuss…

References:  GWT – Pros and Cons from our JCG partner Ganeshji Marwaha at the Ganesh blog.

Related Whitepaper:

Functional Programming in Java: Harnessing the Power of Java 8 Lambda Expressions

Get ready to program in a whole new way!

Functional Programming in Java will help you quickly get on top of the new, essential Java 8 language features and the functional style that will change and improve your code. This short, targeted book will help you make the paradigm shift from the old imperative way to a less error-prone, more elegant, and concise coding style that’s also a breeze to parallelize. You’ll explore the syntax and semantics of lambda expressions, method and constructor references, and functional interfaces. You’ll design and write applications better using the new standards in Java 8 and the JDK.

Get it Now!  

30 Responses to "GWT – Pros and Cons"

  1. Emilio Bravo says:

    About Cons:
    1 “Many functions, interfaces and events get deprecated”, as in any other framework or toolkit
    2 ok, but the documentation is quite worked
    3 and 5, uibinder, xml layout (you can use html layout).
    4 which version of GWT you tried it?, the compilation is only required at the end of development process.
    6 ok
    7 which version of GWT you tried it? you can use MVP.
    8 uibinder, xml layout
    9 to simple things, use jquery.
    10 uibinder, xml layout.
    11 y 12 Gwt compiler generates optimized javascript for all web browsers including mobile. The javascript code has no dependencies on external libraries that have to be downloaded

  2. Vijay Nathani says:

    A new language Dart is available (at least in beta form). It removes browser incompatibilities. It allows us to continue using HTML and CSS. The language is familiar to Java and C# developers. I hope someone does a detailed comparison between GWT and Dart.

    • Steve Paul says:

      In terms of using GWT, I like the idea that AJAX is used and that entirely new html pages are not ‘published’ on the server-side. This is not only much more performant, but obliges less html coding and avoids the complexity of MVC frameworks. The only reason MVC emerged is because developers are being forced to communicate with a user by publishing and posting new server pages. This is little better than paging through a book. What actually should be happening is that the server should be communicating to the interface, and the interface should be responsible for rendering the response. Unfortunately this requires client side run-time.

      Is Dart a client side runtime? If it is, it should take note that Adobe AIR’s device-footprint is growing smaller and smaller (it recently dropped support for Android).

      That’s where GWT comes in. It simulates the client side interface as described above. The developer has an easier time responding to the user without publishing html content, and the user only has to get used to 1 interface which is far less disorienting.

  3. kamoliddinov says:

    If someone .net or php even they can use gwt, gwt is js, i created projects with gwt and php. Gwt asks php server to get data and represents it in html. 

  4. Andre Dölger says:

    “GWT is being actively developed by Google.” – I’m not really sure if this is true. It seems to me that a lot of GWT developers of Google moved to project “Dart”.

  5. Adisesha Reddy Gaddam says:

    Java developer for 9 years and used GWT for 2 years.Recently we started the project in GWT and rewrote everything in JavaScript after 3 months of work.As you mentioned, it is good for Java developers who do not want to get into non senses of JavaScript or not learn other language. Remember the native language of browser is JavaScript and learn to communicate  in that language. If your life depends on it, do you use Google Translate to communicate or learn the language?

     1. It is a myth that you do not need to know JavaScript if you do it in GWT. Most of the libraries are just wrappers over their JavaScript counter parts for example, SmartGWT. You must know the JavaScript in order to debug them.Also how do you know if it is not a bug in GWT generated js? Most of the Java developers do not have any idea of what the ultimate generated code will be. I have seen code where components and panels are added, on top of each other, recklessly which resulted in bloated generated code and slow start up times. When it comes to fixing them, they have no idea where to start.

    2.  Availability of good open source library that play well with native GWT is hard to find. You do not find same quality of plugins, you find in JavaScript. Ext-GWT is commercial and SmartGWT does not play well with GWT(it’s their way or high way). Are there any other good libraries?

    3. The commitment from the community is poor, I still remember Sencha’s license switch with Ext-GWT. How many libraries are there which are actively maintained now? Compare that with number of JavaScript libraries available for doing any single task.

    4. As a Java developer, it may be easy to start with GWT but once you become comfortable with js you will be spending less time for develop-compile-deploy and less lines of code. On top of that your code will be expressive. My experience.

    • Emilio Bravo says:

      “Recently we started the project in GWT and rewrote everything in JavaScript after 3 months of work”, Why did you have to rewrite the code?
      ” You must know the JavaScript in order to debug them.Also how do you know if it is not a bug in GWT generated js?”, How do you know if there is an error in the javascript implementation of the browser or java bytecode or even in assembler code?, gwt compiler generates optimized code for each browser and abstracts you from many problems in javascript.”I have seen code where components and panels are added, on top of each other”, Well imagine that would have started directly in js.”The commitment from the community is poor”,  visiti http://code.google.com/p/google-web-toolkit/ and http://groups.google.com/group/google-web-toolkit-contributors”As a Java developer, it may be easy to start with GWT but once you become comfortable with js you will be spending less time for develop-compile-deploy and less lines of code”,  For small I agree, when the project grows and several people working on the same code, properly use gwt is an advantage.

      • Adisesha Reddy Gaddam says:

        @google-f4c273255cbecc45ebe2de2005d3c401:disqus   ‘Why did you have to rewrite the code?’ 
        I think this blog and the points I mentioned already answers that. Now we do not have this scenario, http://xkcd.com/303/

        ‘How do you know if there is an error in the javascript implementation of the browser or java bytecode or even in assembler code?, gwt compiler generates optimized code for each browser and abstracts you from many problems in javascript

        I know somebody will come back with this point. It depends on your trust level and number of active users. More the number of user, more easy to find solution. I do not know if you looked at js world,there are libraries which does that.

        ‘Well imagine that would have started directly in js’
        I did and the results are better in js. 

        ‘”The commitment from the community is poor”,  visiti http://code.google.com/p/googl… and http://groups.google.com/group…”‘
        I meant it from libraries perspective. For the record, http://adij.wordpress.com/2007/12/05/gwt-is-cool-but-not-complete/, this was written by me in 2007. I referred to this just to let you know that I am not some one who picked GWT few months back. I feel that lack of comprehensive libraries is a big minus for  GWT. 
         
        ‘when the project grows and several people working on the same code, properly use gwt is an advantage.’
        I feel it’s other way around, when you use GWT, your code base automatically grows. As I said, I worked on GWT exclusively for 2 years and fallen in love with js in recent months.I see  the amount of code you need to write, to achieve a task, is very less when compared to GWT. Java is my bread and butter but  I believe in right tool for the right job. If GWT is such an angel, why Dart?

        You seems to follow GWT closely, can you let me know if there are any good GWT widget libraries? 

        • Emilio Bravo says:

          “You seems to follow GWT closely, can you let me know if there are any good GWT widget libraries?” so far we have not needed to use libraries of widgets, we uses Html + CSS layout. I know developers who are using gxt smoothly . The license is very affordableSince 2007 things have changed a lot.”.I see  the amount of code you need to write, to achieve a task, is very less when compared to GWT”, With uibinder and html + css layout, the amount of code required is less. Using proper implementation of the MVP architecture help when the project grows”If GWT is such an angel, why Dart?”There are no silver bullets:-D.Dart is an evolution in the development of RIA. Dart is not to replace GWT and Closure. The problem with GWT is that Google can not control the specification of Java. With Dart, Google makes the specification and implementation. If you see Dart code is very similar to java or javascript. Going to have to JavaScript compiler and a VM in chrome.https://plus.google.com/u/0/117487419861992917007/posts/6YWpsHpqMqZ This speculation is a possible integration of the 3 javascript compilers (GWT, Closure and Dart), at the moment is just an idea.

          • Adisesha Reddy Gaddam says:


            we uses Html + CSS layout’
            We generate UI at client side using meta information from server. 

            ‘Since 2007 things have changed a lot’
            I can see that but not enough for us to move to it.

            On amount of code, lets agree to disagree :) 

            Thanks for info on Dart. 

        • Dmitry Matyukhin says:

          ExtGWT, GWTExt, SmartGWT to mention just a few

  6. alex craciun says:

    I agree with most of the cons and pros from the article. GWT seems like a good proposition for Java developers, but it becomes soon too complicated for what you really need. Our project STJS (http://st-js.sourceforge.net) takes an approach that tries to benefit from the impressive IDE support for Java (compared to Javascript), while taking advantage from existing Javascript frameworks, like jQuery. Also it’s much easier to learn and master.

  7. Dapeng Liu says:

    UiBinder solves most of the problems with GWT

    java codes are exclusively for event handling, logic processing

    rest of the work is left to UiBinder, the good old HTML+CSS combo still works 

    most of the time my ui.xml is 

      

       …
       …

     

  8. Antonio Petrelli says:

    About number 8 con, notice that MVP and the Editor framework can significantly remove much of logic code from the presentation layer.

  9. Agree with most, if not all of your pros and cons regarding GWT. I’ve worked with the technology for about 4 years now and, while initially very excited about it (being a person with more of a Swing background than a JS/HTML background), I am not so sure now.

    Now, one can use GWT as a supporting technology to add additional rich functionality to their existing web page (and it is a perfectly fine solution), but the main use is a more or less pure GWT app. And in this regard, I have doubts now about how friendly this technology is. It is certainly much easier with UIBinder than before, but lets face it, writing the UI in Java is more complicated than simply whipping up some HTML and then gradually adding interactivity – especially with a separate UI designer person who knows nothing about programming. And again, I say this as a person with a Swing background.

    If I had to decide when to use GWT and when to not, I think I would consider how complicated my server-side data model is. If I already have a pretty sophisticated entity layer with lots of business logic going on in Java classes, I guess using GWT and reusing quite a bit of my existing code on the client-side may simply be much easier than duplicating everything in JavaScript. On the other hand, if what I am creating is, in the end, just a glorified website with some AJAX bells and whistles (even if it has an enterprise-y looking UI), I don’t think using GWT is the best solution and it could end up like using a wrench to pull out a nail. Sure it can work, but is the effort worth it?


  10. The Java to JavaScript compilation is fairly slow”

    That’s my ONLY gripe with GWT. It’s not fairly slow. It’s horrendously slow, and they’ve said it’s unlikely to change because of the way the optimizer work.

    And devmode is too slow for many tasks, so frequent compiles are sometimes required.

    • Federico Pugnali says:

      devmode is slow if you’re using the plugin in Chrome. Try the plugin in Firefox, is very fast. We use very heavy client code and everything works pretty fast.

  11. spnewmex64 says:

    I’d rather have a root canal without anesthetics than write ANYTHING in javascript.

  12. KevinCho says:

    From Day 1, I face palmed on GWT.  If you’re a web developer, you should know at least 3 things

    HTML/CSS/Javascript

    I honestly believe GWT was inspired by someone who thinks Java is the solution to ALL problems.  He must said something like “I hate Javascript, let there be Java”.  Anyone who TRULY believes that GWT requires 0 Javascript is a fool.  If there’s a bug, then you’re going to see Javascript *gasp*.  I rather debug my own code than auto generated GWT crap that only Java communist can understand. If you place yourself on Javascript developers, you’ll understand better. Imagine there’s a Javascript that generates Java. What would you think? Actually, it’s sort of done in JRuby. A scripting language that runs on JVM… now do you use JRuby or Java?

  13. We used GWT to build a mid-size web application. It met our requirements except that the the download size is too big. Loading time could be as long as 10 seconds. We have tried many techniques to reduced the size but it didn’t help much. We are going to switch to jquery for our next project.

  14. Troy Borja says:

    Our small dev team uses GWT 2.4 (Uibinder, RequestFactories, Activities and Places, Custom Widgets, Code Splitting, GAE or CloudSQL) to build cloud based web and Facebook applications. With very minimal code change we are able to run the same web applications on a local server using MySQL if the original was written in CloudSQL. App runs well on a browser, mobile phone or tablet. We do not use any widget that is not from Google. Currently we are testing the use of the same RequestFactories used on the web for use in Android apps. We are also testing using GWT HTML5 capability to get offline functionality from mobile devices so we do not have to code in Android. All this coded in Java using the Eclipse IDE. We have not paid for any dev tools. Why wouldn’t you want this?

    • Isn't Man says:

      This shall convince me I have made a right decision making a cloud application using GWT. to launch it within 8 months ahead. I am quite confidence with GWT and of course, it’s from Google.

  15. porkchop says:

    Javascript is FAAAR more suitable to event based coding (I.e. browser apps or scalable server apps). Plus it is truly a much much better language than Java.

  16. Harry Keller says:

    Having written massive amounts of Java and vast quantities of JavaScript, my view is very simple. Use JavaScript when you must — as in cross-browser UI. Use Java mostly because it’s a true programming language with strong variable typing.

    I’m just now getting into GWT. My team has just transitioned from an HTML/CSS/JS + Java applets and servlets system to a 100% Java application to avoid browser dependencies. In order to provide mobile solutions (and Chromebook), we are working on changing our system (50,000+ lines of Java) into GWT. This is not something we do lightly.

    The Java application plus servlet combination is fast, efficient, and bug-free (no known bugs) and in use by tens of thousands of students from grades 5 through college. It’s easy to maintain, build, and deploy — via JWS.

    This system could never have been written in JS and maintained and updated. Besides, its performance would have stunk.

    For the Java purists and the JS purists, I say, “Get a life!” Javascript is not “powerful.” That’s a better description of Java, the most popular programming language in the world. Javascript is not to be avoided at all costs (e.g. root canal) because it solves problems that are not solvable in the real world in any other way. Get over it. HTML5 requires JS.

    So, we’ll be delivering two solutions. I hate having more than one, but it’s lots better than three or four. And, importantly, much of the code remains unchanged. We’ll only have to rewrite a few thousand lines. Sigh! :O

  17. Bobby says:

    I’ve been a MS developer my whole life – latest silverlight frontend with .net backend. it took about a month worth of work but finally we implemented a smooth process to develop single page GWT apps in Eclipse, using .NET backend/web services developed in visual studio 2010. On the .NET side we receive/transfer all objects in JSON rather than XML. On the GWT side we use overlay types.

    We wrote an app which generates code (from the .NET app) and automatically writes it to our GWT project – it generates all classes that we need and also writes functions for easy calls to the web services. On top of this, we were able to get the .NET web services functioning while we run the app in GWT, which makes it WAY easy to debug. then when we are done with project changes, we compile to javascript/html – copy that to visual studio, and deploy our project. couldn’t be simpler.

    It took a lot of work to figure all this out, but was TOTALLY worth it once we did since we are a straight microsoft shop with SQL server backend and IIS windows servers. Silverlight was great, but now we are moving to the point where staff are getting pads and need to run apps on their phones as well.

    We use UIBinder for the interface. Love the GUI designer/xml declarative layout, and modularity. Can still use any HTML/CSS we want by having the UiBinder HTML panels in the UI. The uiBinder designer even recognizes CSS3 tags and renders them better than IE9 does.

    GWT was a great solution, and Java was very easy to learn coming from a C# background.

  18. Erwin says:

    I have some opinions, that I consider, are not concerned in this post.

    GWT is cool if it’s habitual for you to use the Google PLs or APIs, many of them are pretty nice, but keep in mind that that some functionalities turn free into payment. So, don’t develope projects seeing long term if you are not considering that reality.

    I know many friends who got dissapointed when the API of Google Traslate turn into payment. Many projects and good biz had to recalculate their existence.

    Books?, well are not necesary today, and that’s why I recommed beginner programers to learn by themselves, because books about promgramming are not at the same velocity of the new changes in coding.

    Well, I just always recommend that our project has to have a vision in the future and avoid non-forescated-costs.

    Erwin

  19. Mike says:

    First I would like to thank Ganeshji Marwaha. Excellent article, and the responses are equally helpful. I first started using GWT because I wasn’t a javascript wizard. Later, I became a little more adept at javascript using JQuery, and then angularJS (another framework developed by google). The one thing I like about GWT is that setting up UIs for mutiple devices/cross platforms is quite nice. MGWT written by Daniel Kurka and along with the google team did a wonderful job. However you do feel like you are handing over a little control when you use GWT. If you don’t have the CSS – javascript artist on your team, GWT is pretty good choice. They have some nice themes just like JQuery.

Leave a Reply


+ six = 10



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.

Sign up for our Newsletter

20,709 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books