Java vs JavaScript
July 2016
JavaScript was developed by Brendan Eich in 1995 with the purpose of allowing developers to add functionality to the Netscape browser (Savage, 2014). It is one of the most popular languages in the world, dominant in the browser, but also found on mobile devices and the server. It is currently ranked seventh on the popular TIOBE index (TIOBE index, 2016).
JavaScript has similarities in name to Java, leading many people to believe that the languages are similar, but apart from some superficial similarities they differ greatly. According to Crockford (2008), JavaScript is more similar to Lisp and Scheme than Java.
JavaScript is the language of the Web, natively understood by all major browsers. Java’s greatest area of success, on the other hand, is on the server, according to Nan and Kai-Kuang (2004).
Both Java and JavaScript support the Object-Oriented paradigm of development, but the way they achieve this differs. Java makes use of class definitions to define objects. JavaScript uses prototypal inheritance where “objects inherit properties directly from other objects” in a “class-free object system” (Crockford, 2008).
Both Java and JavaScript support the Functional paradigm. JavaScript supports first-class, high order functions (Atencio, 2015). Both Java and JavaScript support Lambda expressions.
Java is statically typed, whilst JavaScript is dynamically typed. According to Savage (2014), static typing can help find bugs that would otherwise have remained undiscovered for a very long time. Crockford (2008) argues that using a strongly typed language does not free you performing in depth testing, and that he is unconcerned with the type of bugs found by static typing. In my own experience using a strongly typed language does have advantages, particularly when it comes to developer productivity.
Java has block scoping, whilst JavaScript has function scoping. This means that in Java variables are scoped to the containing curly braces block in which they are defined. In the case of JavaScript, variables are scoped to the outer function in which they are defined. The new “let” keyword defined in ES 6 introduces the option of block scoping variables in JavaScript.
JavaScript is typically interpreted (in the browser), but can also be Just-In-Time compiled on the Node.js server platform. Java is typically compiled into bytecode and run on the JVM.
Apart from the underlying differences described above Java and JavaScript do have some things in common. Like JavaScript, Java is also an immensely popular language, ranked first on the TIOBE index (TIOBE index, 2016). According to Goodman, Morrison, Novitski (2010) both languages share a syntax similar to C, including dot notation, curly braces and some key words. Like JavaScript, Java was announced in 1995.
References
Atencio, L., (2015) Functional Programming in Javascript, Manning Publications
Crockford, D., (2008), JavaScript: The Good Parts. Sebastopol, CA: O’Reilly Media, Inc.
Goodman, D., Morrison, M., & Novitski, P., (2010), Bible : JavaScript Bible (7), Wiley, Hoboken, US. Available from: ProQuest ebrary. 4 September 2016.
Nan C., Kai-Kuang M., (2004) “Java’s futures: challenge and opportunity,” in IT Professional, vol. 6, no. 4, pp. 19-26
Savage, N., (2014), ‘Gradual Evolution’, Communications Of The ACM, 57, 10, pp. 16-18, Business Source Complete, EBSCOhost, viewed 4 September 2016.
TIOBE Index for July 2016, Available At: http://www.tiobe.com/tiobe-index/, (Accessed 4 September 2016)