Nowadays, Java and Javascript are both rather common in app development.
Having the opportunity to converse with technical architects on this subject matter, studying numerous technical journal/blogs online and with my hands-on coding experience, here is my take on the subject of java vs javascript which happens to be a commonly asked interview questions for java web frontend / full stack developer.
You can find the studied reference links after[below] this article.
Perspective | Java | JavaScript |
---|---|---|
Background /History | Java is an Object Oriented Programming (OOP) language created by James Gosling of Sun Microsystems. | JavaScript is a scripting language that was created by the fine people at Netscape and was originally known as LiveScript |
Environment | Compiled + interpreted language; Java code is fist compiled into class files containing byte code and than executed by JVM. Java is run inside JVM and needs JDK or JRE for running. | Code is directly executed by browse . One more difference which comes form this fact is that, , on there other hand JavaScript runs inside browser and browser commonly supports JavaScript. |
Variables & Values | Statically typed language. Variables are declared with type at compile time, and can only accept values permitted for that type. Generally,uses .equals() to compare the actual contained string value. ‘==’ compares reference value instead. Overriding Variable value storing is rigid.Example, To assign an integer to variable , it needs an int declaration from the start, assigning string value would cause compilation error. For function parameter, this is a convenience because the input checking type value is definitely known. Not forgiving to null pointer exception. |
Dynamic typed language.Variables are declared using vary keyword in JavaScript, and can accept different kinds of value e.g. String, numeric and boolean etc. Possible to use ‘==’ to compare equaled string value and ‘===’ to compare strict type check as well. Overriding variable value is flexible. Example, To assign an integer to variable , it needs an int declaration from the start, assigning string value along the way would not cause any error.For function parameter, this is a hassle because the input value checking type is not known definitely. Forgiving to null pointer as it considers another value ‘type’. |
Variables & Hoisting | would not happened | Can happen. Suggestion: use lint checker, and use strict checking. |
Platform independence & Result Rendering Gap | Code compiled to Bytecode Class file; makes it possible to run in any environment with same result, lower gap result in different environments. | Code compiled in browser; makes it impossilbe to run in any browser due to browser support and different render of stack browser. Gap is high in different browser stack[environment.] |
Platform independence & Result Rendering Gap | Code compiled in JRE to Bytecode class file; makes it possible to run in any environment with same result, lower gap running code in different environment. | Code compiled in browser; makes it impossilbe to run in any browser due to browser support and different render of stack browser. Gap is high in different browser stack[environment.] |
Constructors | Followed a specific rules like name must follow class, and no return type.. | Doesn’t follow any specific rules. Generally just another function that adapt to behave like constructor. |
References:
http://javarevisited.blogspot.my/2015/03/10-difference-between-java-and-javascript-programming.html
Leave a Reply