Over a million developers have joined DZone.
Platinum Partner

DZone Top Articles of 2011: Why Java Developers Hate JavaScript

· Java Zone

The Java Zone is brought to you in partnership with ZeroTurnaround. Discover how you can skip the build and redeploy process by using JRebel by ZeroTurnaround.

This is the first entry in DZone's series that will revisit the top articles of 2011 throughout the month of January 2012. 

As a Java developer, I used to hate JavaScript. At one time I used to say “friends don’t let friends use JavaScript”.

In recent years, JavaScript has become required for a flexible & feature rich user experience. WIth the advent of tools such as JQuery and GWT many of these issues have been minimized. Also, I took the time to read more about JavaScript. The book that really opened my eyes is JavaScript: The Good Parts.

So… What do Java developers hate?

  • JavaScript may look like Java, smell like Java and even taste a little like Java, but it does not behave like Java
  • Variables are global in scope
  • “this” has different meaning based on the invocation type (learn this for your own sake)
  • Braces do NOT guarantee scope
  • Functions are first class citizens, not classes (avoid classes, you will set yourself up for disappointment)
  • Functions are objects, not simply methods to a class
  • Variables are dynamically typed objects
  • JavaScript often fails silently (this is for user experience)
  • Difficult to debug (use FireFox & Firebug addon)
  • Semicolons are optional (bad idea, put them where you want them)
  • Functions always return values, a value or “undefined”
  • “new” has some specific assumptions, not simply creating an Object
  • Cross browser compatibility (use jQuery or GWT to address most issues)

What should you understand about JavaScript?

  • Functions – First class citizens, the primary object in JavaScript
  • prototype system – Object.prototoype, object linkage, delegation, hasOwnProperty() method, etc.
  • closures
  • currying
  • the 4 invocation types: method, function, constructor & apply
  • dynamic languages such as groovy, ruby, etc. they share many similarities

What should you forget when using JavaScript?

  • Classes
  • Scope using braces
  • Strong typing

In summary, it is an entirely different language with many syntactical similarities. JavaScript is very power and flexible once you understand how it behaves. I highly recommend the O’Reilly book (mentioned above), its a short read and packed with awesome facts.

The Java Zone is brought to you in partnership with ZeroTurnaround. Discover how you can skip the build and redeploy process by using JRebel by ZeroTurnaround.


Published at DZone with permission of Gordon Dickens , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}