{"id":26787,"date":"2014-06-24T01:00:01","date_gmt":"2014-06-23T22:00:01","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=26787"},"modified":"2014-06-23T12:12:17","modified_gmt":"2014-06-23T09:12:17","slug":"javascript-for-java-developers","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2014\/06\/javascript-for-java-developers.html","title":{"rendered":"Javascript for Java Developers"},"content":{"rendered":"<p>This post will go over the Javascript language from the point of view of a Java developer, focusing on the differences between the two languages and the frequent pain points. We will go over the following:<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<\/p>\n<ul>\n<li>Objects Only, No Classes<\/li>\n<li>Functions are just Values<\/li>\n<li>The &#8216;this&#8217; Keyword<\/li>\n<li>Classic vs Prototypal Inheritance<\/li>\n<li>Constructors vs Constructor Functions<\/li>\n<li>Closures vs Lambdas<\/li>\n<li>Encapsulation and Modules<\/li>\n<li>Block Scope and Hoisting<\/li>\n<\/ul>\n<h2>Why Javascript in the Java World ?<\/h2>\n<p>A lot of Java frontend development work is done using Java\/XML based frameworks like JSF or GWT. The framework developers themselves need to know Javascript, but in principle the application developers don&#8217;t. However the reality is that:<\/p>\n<ul>\n<li>For doing custom component development in for example Primefaces (JSF), it&#8217;s important to know Javascript and jQuery.<\/li>\n<li>In GWT, integrating at least some third-party Javascript widgets is common and cost effective.<\/li>\n<\/ul>\n<p>The end result is that Javascript is usually needed to do at least the last 5 to 10% of frontend work, even using Java frameworks. Also it&#8217;s starting to get more and more used for polyglot enterprise development, alongside <a href=\"http:\/\/angularjs.org\">Angular<\/a> for example.<\/p>\n<p>The good news is that, besides a few gotchas that we will get into, Javascript is a very learneable language for a Java developer.<\/p>\n<h2>Objects Only &#8211; No Classes<\/h2>\n<p>One of the most surprising things about Javascript is that although it&#8217;s an object oriented language, there are no classes (although the <a href=\"http:\/\/wiki.ecmascript.org\/doku.php?id=harmony:classes\">new Ecmascript 6 version<\/a> will have them).<\/p>\n<p>Take for example this program, that initializes an empty object and set&#8217;s two properties:<\/p>\n<pre class=\" brush:java\">\/\/ create an empty object - no class was needed !!\r\nvar superhero = {};\r\n\r\nsuperhero.name = 'Superman';  \r\nsuperhero.strength = 100;<\/pre>\n<p>Javascript objects are just like a Java HashMap of related properties, where the keys are Strings only. The following would be the &#8216;equivalent&#8217; Java code:<\/p>\n<pre class=\" brush:java\">Map&lt;String,Object&gt; superhero = new HashMap&lt;&gt;();\r\n\r\nsuperhero.put(\"name\",\"Superman\");  \r\nsuperhero.put(\"strength\", 100);<\/pre>\n<p>This means that a Javascript object is just a multi-level &#8216;hash map&#8217; of key\/value pairs, with no class definition needed.<\/p>\n<h3>Functions Are Just Values<\/h3>\n<p>Functions in Javascript are just values of type <code>Function<\/code>, it&#8217;s a simple as that! Take for example:<\/p>\n<pre class=\" brush:java\">var flyFunction = function() {  \r\n    console.log('Flying like a bird!');\r\n};\r\n\r\nsuperhero.fly = flyFunction;<\/pre>\n<p>This creates a function (a value of type <code>Function<\/code>) and assigns it to a variable <code>flyFunction<\/code>. A new property named <code>fly<\/code> is then created in the superhero object, that can be invoked like this:<\/p>\n<pre class=\" brush:java\">\/\/ prints 'Flying like a bird!' to the console\r\nsuperhero.fly();<\/pre>\n<p>Java does <strong>not<\/strong> have the equivalent of the Javascript <code>Function<\/code> type, but almost. Take for example the <code>SuperHero<\/code> class that takes a <code>Power<\/code> function:<\/p>\n<pre class=\" brush:java\">public interface Power {  \r\n    void use();\r\n}\r\n\r\npublic class SuperHero {\r\n\r\n    private Power flyPower;\r\n\r\n    public void setFly(Power flyPower) {\r\n        this.flyPower = flyPower;\r\n    }\r\n\r\n    public void fly() {\r\n        flyPower.use();\r\n    }\r\n}<\/pre>\n<p>This is how to pass <code>SuperHero<\/code> a function in Java 7 and 8:<\/p>\n<pre class=\" brush:java\">\/\/ Java 7 equivalent\r\nPower flyFunction = new Power() {  \r\n    @Override\r\n    public void use() {\r\n        System.out.println(\"Flying like a bird ...\");\r\n    }\r\n};\r\n\r\n\/\/ Java 8 equivalent \r\nsuperman.setFly(  \r\n    ()-&gt;System.out.println(\"Flying like a bird ...\"));\r\n\r\nsuperman.fly();<\/pre>\n<p>So although a <code>Function<\/code> type does not exist in Java 8, this ends up not preventing a &#8216;Javascript-like&#8217; functional programming style.<\/p>\n<p>But if we pass functions around, what happens to the meaning of the <code>this<\/code> keyword?<\/p>\n<h2>The &#8216;this&#8217; Keyword Usage<\/h2>\n<p>What Javascript allows to do with <code>this<\/code> is quite surprising compared to the Java world. Let&#8217;s start with an example:<\/p>\n<pre class=\" brush:java\">var superman = {\r\n\r\n  heroName: 'Superman',  \r\n\r\n  sayHello: function() {\r\n      console.log(\"Hello, I'm \" + this.heroName );\r\n  }  \r\n};\r\n\r\nsuperman.sayHello();<\/pre>\n<p>This program creates an object <code>superman<\/code> with two properties: a String <code>heroName<\/code> and a <code>Function<\/code> named <code>sayHello<\/code>. Running this program outputs as expected <code>Hello, I'm Superman<\/code>.<\/p>\n<h3>What if we pass the function around?<\/h3>\n<p>By passing around <code>sayHello<\/code>, we can easily end up in a context where there is no <code>heroName<\/code> property:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\" brush:java\">var failThis = superman.sayHello;\r\n\r\nfailThis();<\/pre>\n<p>Running this snippet would give as output: <code>Hello, I'm undefined<\/code>.<\/p>\n<h3>Why does <code>this<\/code> not work anymore?<\/h3>\n<p>This is because the variable <code>hello<\/code> belongs to the global scope, which contains no member variable named <code>heroName<\/code>. To solve this:<\/p>\n<blockquote>\n<p>\nIn Javascript the value of the <code>this<\/code> keyword is completely overridable to be anything that we want!\n<\/p>\n<\/blockquote>\n<pre class=\" brush:java\">\/\/ overrides 'this' with superman\r\nhello.call(superman);<\/pre>\n<p>The snippet above would print again <code>Hello, I'm Superman<\/code>. This means that the value of <code>this<\/code> depends on both the context on which the function is called, and on <em>how<\/em> the function is called.<\/p>\n<h2>Classic vs Prototypal Inheritance<\/h2>\n<p>In Javascript, there is no class inheritance, instead objects can inherit directly from other objects. The way this works is that each object has an implicit property that points to a &#8216;parent&#8217; object.<\/p>\n<p>That property is called <code>__proto__<\/code>, and the parent object is called the object&#8217;s <strong>prototype<\/strong>, hence the name Prototypal Inheritance.<\/p>\n<h3>How does <code>prototype<\/code> work?<\/h3>\n<p>When looking up a property, Javascript will try to find the property in the object itself. If it does not find it then it tries in it&#8217;s prototype, and so on. For example:<\/p>\n<pre class=\" brush:java\">var avengersHero = {  \r\n    editor: 'Marvel'\r\n};\r\n\r\nvar ironMan = {};\r\n\r\nironMan.__proto__ = avengersHero;\r\n\r\nconsole.log('Iron Man is copyrighted by ' + ironMan.editor);<\/pre>\n<p>This snippet will output <code>Iron Man is copyrighted by Marvel<\/code>.<\/p>\n<p>As we can see, although the <code>ironMan<\/code> object is empty, it&#8217;s prototype does contain the property <code>editor<\/code>, which get&#8217;s found.<\/p>\n<h3>How does this compare with Java inheritance?<\/h3>\n<p>Let&#8217;s now say that the rights for the Avengers where bought by DC Comics:<\/p>\n<pre class=\" brush:java\">avengersHero.editor = 'DC Comics';<\/pre>\n<p>If we call <code>ironMan.editor<\/code> again, we now get <code>Iron Man is copyrighted by DC Comics<\/code>. All the existing object instances with the <code>avengersHero<\/code> prototype now see <code>DC Comics<\/code> <em>without<\/em> having to be recreated.<\/p>\n<p>This mechanism is very simple and very powerful. Anything that can be done with class inheritance can be done with prototypal inheritance. But what about constructors?<\/p>\n<h2>Constructors vs Constructor Functions<\/h2>\n<p>In Javascript an attempt was made to make object creation similar to languages like Java. Let&#8217;s take for example:<\/p>\n<pre class=\" brush:java\">function SuperHero(name, strength) {  \r\n    this.name = name;\r\n    this.strength = strength;\r\n}<\/pre>\n<p>Notice the capitalized name, indicating that it&#8217;s a constructor function. Let&#8217;s see how it can be used:<\/p>\n<pre class=\" brush:java\">var superman = new SuperHero('Superman', 100);\r\n\r\nconsole.log('Hello, my name is ' + superman.name);<\/pre>\n<p>This code snippet outputs <code>Hello, my name is Superman<\/code>.<\/p>\n<p>You might think that this looks just like Java, and that is exactly the point! What this <code>new<\/code> syntax really does is to it creates a new empty object, and then calls the constructor function by forcing <code>this<\/code> to be the newly created object.<\/p>\n<h3>Why is this syntax not recommended then?<\/h3>\n<p>Let&#8217;s say that we want to specify that all super heroes have a <code>sayHello<\/code> method. This could be done by putting the <code>sayHello<\/code> function in a common prototype object:<\/p>\n<pre class=\" brush:java\">function SuperHero(name, strength) {  \r\n    this.name = name;\r\n    this.strength = strength;\r\n}\r\n\r\nSuperHero.prototype.sayHello = function() {  \r\n    console.log('Hello, my name is ' + this.name);\r\n}\r\n\r\nvar superman = new SuperHero('Superman', 100);  \r\nsuperman.sayHello();<\/pre>\n<p>This would output <code>Hello, my name is Superman<\/code>.<\/p>\n<p>But the syntax <code>SuperHero.prototype.sayHello<\/code> looks anything but Java like! The <code>new<\/code> operator mechanism sort of half looks like Java but at the same time is completely different.<\/p>\n<h3>Is there a recommended alternative to <code>new<\/code>?<\/h3>\n<p>The recommended way to go is to ignore the Javascript <code>new<\/code> operator altogether and use <code>Object.create<\/code>:<\/p>\n<pre class=\" brush:java\">var superHeroPrototype = {  \r\n   sayHello: function() {\r\n        console.log('Hello, my name is ' + this.name);\r\n    } \r\n};\r\n\r\nvar superman = Object.create(superHeroPrototype);  \r\nsuperman.name = 'Superman';<\/pre>\n<p>Unlike the <code>new<\/code> operator, one thing that Javascript absolutely got right where Closures.<\/p>\n<h2>Closures vs Lambdas<\/h2>\n<p>Javascript Closures are not that different from Java anonymous inner classes used in a certain way. take for example the <code>FlyingHero<\/code> class:<\/p>\n<pre class=\" brush:java\">public interface FlyCommand {  \r\n    public void fly();\r\n}\r\n\r\npublic class FlyingHero {\r\n\r\n    private String name;\r\n\r\n    public FlyingHero(String name) {\r\n        this.name = name;\r\n    }\r\n\r\n    public void fly(FlyCommand flyCommand) {\r\n        flyCommand.fly();\r\n    }\r\n}<\/pre>\n<p>We can can pass it a fly command like this in Java 8:<\/p>\n<pre class=\" brush:java\">String destination = \"Mars\";  \r\nsuperMan.fly(() -&gt; System.out.println(\"Flying to \" +  \r\n    destination ));<\/pre>\n<p>The output of this snippet is <code>Flying to Mars<\/code>. Notice that the <code>FlyCommand<\/code> lambda had to &#8216;remember&#8217; the variable <code>destination<\/code>, because it needs it for executing the <code>fly<\/code> method later.<\/p>\n<p>This notion of a function that remembers about variables outside it&#8217;s block scope for later use is called a <strong>Closure<\/strong> in Javascript. For further details, have a look at this blog post <a href=\"http:\/\/blog.jhades.org\/really-understanding-javascript-closures\/\">Really Understanding Javascript Closures<\/a>.<\/p>\n<h3>What is the main difference between Lambdas and Closures?<\/h3>\n<p>In Javascript a closure looks like this:<\/p>\n<pre class=\" brush:java\">var destination = 'Mars';\r\n\r\nvar fly = function() {  \r\n    console.log('Fly to ' + destination);\r\n}\r\n\r\nfly();<\/pre>\n<p>The Javascript closure, unlike the Java Lambda does not have the constraint that the <code>destination<\/code> variable must be immutable (or effectively immutable since Java 8).<\/p>\n<p>This seemingly innocuous difference is actually a &#8216;killer&#8217; feature of Javascript closures, because it allows them to be used for creating encapsulated modules.<\/p>\n<h2>Modules and Encapsulation<\/h2>\n<p>There are no classes in Javascript and no <code>public<\/code>\/ <code>private<\/code> modifiers, but then again take a look at this:<\/p>\n<pre class=\" brush:java\">function createHero(heroName) {\r\n\r\n    var name = heroName;\r\n\r\n    return  {\r\n        fly: function(destination) {\r\n          console.log(name + ' flying to ' + destination);\r\n        }\r\n    }; \r\n}<\/pre>\n<p>Here a function <code>createHero<\/code> is being defined, which returns an object which has a function <code>fly<\/code>. The <code>fly<\/code> function &#8216;remembers&#8217; <code>name<\/code> when needed.<\/p>\n<h3>How do Closures relate to Encapsulation?<\/h3>\n<p>When the <code>createHero<\/code> function returns, noone else will ever be able to directly access <code>name<\/code>, except via <code>fly<\/code>. Let&#8217;s try this out:<\/p>\n<pre class=\" brush:java\">var superman = createHero('SuperMan');\r\n\r\nsuperman.fly('The Moon');<\/pre>\n<p>The output of this snippet is <code>SuperMan flying to The Moon<\/code>. But happens if we try to access <code>name<\/code> directly ?<\/p>\n<pre class=\" brush:java\">console.log('Hero name = ' + superman.name);<\/pre>\n<p>The result is <code>Hero name = undefined<\/code>. The function <code>createHero<\/code> is said to a be a Javascript encapsulated <strong>module<\/strong>, with closed &#8216;private&#8217; member variables and a &#8216;public&#8217; interface returned as an object with functions.<\/p>\n<h2>Block Scope and Hoisting<\/h2>\n<p>Understanding block scope in Javascript is simple: there is no block scope! Take a look at this example:<\/p>\n<pre class=\" brush:java\">function counterLoop() {\r\n\r\n    console.log('counter before declaration = ' + i); \r\n\r\n    for (var i = 0; i &lt; 3 ; i++) {\r\n        console.log('counter = ' + i); \r\n    }\r\n\r\n    console.log('counter after loop = ' + i); \r\n}\r\n\r\ncounterLoop();<\/pre>\n<p>By looking at this coming from Java, you might expect:<\/p>\n<ul>\n<li>error at line 3: &#8216;variable i does not exist&#8217;<\/li>\n<li>values 0, 1, 2 are printed<\/li>\n<li>error at line 9: &#8216;variable i does not exist&#8217;<\/li>\n<\/ul>\n<p>It turns out that only one of these three things is true, and the output is actually this:<\/p>\n<pre class=\" brush:java\">counter before declaration = undefined  \r\ncounter = 0 \r\ncounter = 1 \r\ncounter = 2 \r\ncounter after loop = 3<\/pre>\n<p>Because there is no block scope, the loop variable i is visible for the <strong>whole<\/strong> function. This means:<\/p>\n<ul>\n<li>line 3 sees the variable declared but not initialized<\/li>\n<li>line 9 sees i after the loop has terminated<\/li>\n<\/ul>\n<p>What might be the most puzzling is that line 3 actually sees the variable declared but undefined, instead of throwing <code>i is not defined<\/code>.<\/p>\n<p>This is because the Javascript interpreter first scans the function for a list of variables, and then goes back to interpret the function code lines one by one.<\/p>\n<p>The end result is that it&#8217;s like the variable i was <strong>hoisted<\/strong> to the top, and this is what the Javascript runtime actually &#8216;sees&#8217;:<\/p>\n<pre class=\" brush:java\">function counterLoop() {\r\n\r\n    var i; \/\/ i is 'seen' as if declared here! \r\n\r\n    console.log('counter before declaration = ' + i); \r\n\r\n    for (i = 0; i &lt; 3 ; i++) {\r\n        console.log('counter = ' + i); \r\n    }\r\n\r\n    console.log('counter after loop:  ' + i); \r\n}<\/pre>\n<p>To prevent surprises caused by hoisting and lack of block scoping, it&#8217;s a recommended practice to declare variables always at the top of functions.<\/p>\n<p>This makes hoisting explicit and visible by the developer, and helps to avoid bugs. The next version of Javascript (Ecmascript 6) will include a <a href=\"http:\/\/wiki.ecmascript.org\/doku.php?id=harmony:let\">new keyword &#8216;let&#8217; to allow block scoping<\/a>.<\/p>\n<h2>Conclusion<\/h2>\n<p>The Javascript language shares a lot of similarities with Java, but also some huge differences. Some of the differences like inheritance and constructor functions are important, but much less than one would expect for day to day programming.<\/p>\n<p>Some of these features are needed mostly by library developers, and not necessarily for day to day application programming. This is unlike some of their Java counterparts which are needed every day.<\/p>\n<p>So if you are hesitant to give it a try, don&#8217;t let some of these features prevent you from going further into the language.<\/p>\n<p>One thing is for sure, at least <em>some<\/em> Javascript is more or less inevitable when doing Java frontend development, so it&#8217;s really worth to give it a try.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"http:\/\/blog.jhades.org\/javascript-for-java-developers\/\">Javascript for Java Developers<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Aleksey Novik at the <a href=\"http:\/\/blog.jhades.org\/\">The JHades Blog<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This post will go over the Javascript language from the point of view of a Java developer, focusing on the differences between the two languages and the frequent pain points. We will go over the following: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Objects Only, No Classes Functions are just Values The &#8216;this&#8217; Keyword &hellip;<\/p>\n","protected":false},"author":568,"featured_media":2386,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[803],"class_list":["post-26787","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-development","tag-javascript"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Javascript for Java Developers<\/title>\n<meta name=\"description\" content=\"This post will go over the Javascript language from the point of view of a Java developer, focusing on the differences between the two languages and the\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2014\/06\/javascript-for-java-developers.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Javascript for Java Developers\" \/>\n<meta property=\"og:description\" content=\"This post will go over the Javascript language from the point of view of a Java developer, focusing on the differences between the two languages and the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2014\/06\/javascript-for-java-developers.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2014-06-23T22:00:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/software-development-2-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Aleksey Novik\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/JhadesDev\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Aleksey Novik\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/06\\\/javascript-for-java-developers.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/06\\\/javascript-for-java-developers.html\"},\"author\":{\"name\":\"Aleksey Novik\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/7d67bcfba8c4c2dc66f64696fd43a7c6\"},\"headline\":\"Javascript for Java Developers\",\"datePublished\":\"2014-06-23T22:00:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/06\\\/javascript-for-java-developers.html\"},\"wordCount\":1583,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/06\\\/javascript-for-java-developers.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/software-development-2-logo.jpg\",\"keywords\":[\"JavaScript\"],\"articleSection\":[\"Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/06\\\/javascript-for-java-developers.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/06\\\/javascript-for-java-developers.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/06\\\/javascript-for-java-developers.html\",\"name\":\"Javascript for Java Developers\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/06\\\/javascript-for-java-developers.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/06\\\/javascript-for-java-developers.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/software-development-2-logo.jpg\",\"datePublished\":\"2014-06-23T22:00:01+00:00\",\"description\":\"This post will go over the Javascript language from the point of view of a Java developer, focusing on the differences between the two languages and the\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/06\\\/javascript-for-java-developers.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/06\\\/javascript-for-java-developers.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/06\\\/javascript-for-java-developers.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/software-development-2-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/software-development-2-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/06\\\/javascript-for-java-developers.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Software Development\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/software-development\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Javascript for Java Developers\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/7d67bcfba8c4c2dc66f64696fd43a7c6\",\"name\":\"Aleksey Novik\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fdd3c156085cc7c72b32afe338e88a3a3c4979223e6a66abc62a37f99eb65056?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fdd3c156085cc7c72b32afe338e88a3a3c4979223e6a66abc62a37f99eb65056?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fdd3c156085cc7c72b32afe338e88a3a3c4979223e6a66abc62a37f99eb65056?s=96&d=mm&r=g\",\"caption\":\"Aleksey Novik\"},\"description\":\"Software developer, Likes to learn new technologies, hang out on stackoverflow and blog on tips and tricks on Java\\\/Javascript polyglot enterprise development.\",\"sameAs\":[\"http:\\\/\\\/blog.jhades.org\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/JhadesDev\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/aleksey-novik\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Javascript for Java Developers","description":"This post will go over the Javascript language from the point of view of a Java developer, focusing on the differences between the two languages and the","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2014\/06\/javascript-for-java-developers.html","og_locale":"en_US","og_type":"article","og_title":"Javascript for Java Developers","og_description":"This post will go over the Javascript language from the point of view of a Java developer, focusing on the differences between the two languages and the","og_url":"https:\/\/www.javacodegeeks.com\/2014\/06\/javascript-for-java-developers.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2014-06-23T22:00:01+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/software-development-2-logo.jpg","type":"image\/jpeg"}],"author":"Aleksey Novik","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/JhadesDev","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Aleksey Novik","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2014\/06\/javascript-for-java-developers.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/06\/javascript-for-java-developers.html"},"author":{"name":"Aleksey Novik","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/7d67bcfba8c4c2dc66f64696fd43a7c6"},"headline":"Javascript for Java Developers","datePublished":"2014-06-23T22:00:01+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/06\/javascript-for-java-developers.html"},"wordCount":1583,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/06\/javascript-for-java-developers.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/software-development-2-logo.jpg","keywords":["JavaScript"],"articleSection":["Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2014\/06\/javascript-for-java-developers.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2014\/06\/javascript-for-java-developers.html","url":"https:\/\/www.javacodegeeks.com\/2014\/06\/javascript-for-java-developers.html","name":"Javascript for Java Developers","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/06\/javascript-for-java-developers.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/06\/javascript-for-java-developers.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/software-development-2-logo.jpg","datePublished":"2014-06-23T22:00:01+00:00","description":"This post will go over the Javascript language from the point of view of a Java developer, focusing on the differences between the two languages and the","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/06\/javascript-for-java-developers.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2014\/06\/javascript-for-java-developers.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2014\/06\/javascript-for-java-developers.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/software-development-2-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/software-development-2-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2014\/06\/javascript-for-java-developers.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Software Development","item":"https:\/\/www.javacodegeeks.com\/category\/software-development"},{"@type":"ListItem","position":3,"name":"Javascript for Java Developers"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/7d67bcfba8c4c2dc66f64696fd43a7c6","name":"Aleksey Novik","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/fdd3c156085cc7c72b32afe338e88a3a3c4979223e6a66abc62a37f99eb65056?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/fdd3c156085cc7c72b32afe338e88a3a3c4979223e6a66abc62a37f99eb65056?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/fdd3c156085cc7c72b32afe338e88a3a3c4979223e6a66abc62a37f99eb65056?s=96&d=mm&r=g","caption":"Aleksey Novik"},"description":"Software developer, Likes to learn new technologies, hang out on stackoverflow and blog on tips and tricks on Java\/Javascript polyglot enterprise development.","sameAs":["http:\/\/blog.jhades.org\/","https:\/\/x.com\/https:\/\/twitter.com\/JhadesDev"],"url":"https:\/\/www.javacodegeeks.com\/author\/aleksey-novik"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/26787","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/568"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=26787"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/26787\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/2386"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=26787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=26787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=26787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}