Java vs. JavaScript

Java vs JavaScript

Assuming you know Java pretty well and know a little bit about JavaScript, how are you going to answer the interview question "What is the difference between Java and JavaScript"?

You may have used JavaScript in different situations, but do not have deep understanding of the language. This question could be hard. The following lists some points you can talk about to show your knowledge of programming languages in general. It may also show that you can quickly pick up the language, even if you don't know much about it.

1. Key Differences in High Level

Java is an OOP programming language while JavaScript is an OOP scripting language. Java creates applications that run in a virtual machine or browser, while JavaScript code is run on a browser only. Java code needs to be compiled while JavaScript code does not. JavaScript does not create any stand-alone applications. In its most common form, it resides inside HTML and provide levels of interactivity to web pages that are not achievable with simple HTML.

2. Inheritance

In Java, there are classes, and instances, as separate concepts. In order to do inheritance, you have to use the base class to create a new class, which can then be used to produce derived instances.

Like Java, JavaScript is also an object oriented language, but JavaScript does not use classes.
In JavaScript you don't define classes and create objects from these classes. JavaScript is prototype based, not class based. To do inheritance, you can use any object instance as a prototype. The following example gives a taste of JavaScript Inheritance.


// define the Person Class
function Person() {}
Person.prototype.sayHello = function(){
    alert ('Hello!');
// define the Student class
function Student() {}
// inherit Person
Student.prototype = new Person();
// replace the sayHello method
Student.prototype.sayHello = function(){
    alert('Hello, I am a student!');
// add a new method
Student.prototype.sayGoodbye = function(){
var student = new Student();
// check inheritance
alert(student instanceof Person); // true
alert(student instanceof Student); // true

3. Other Fun Facts

Java and Javascript are similar like Car and Carpet are similar.

Two-Stage vs. Runtime-only Debugging

Both Have Libraries and Frameworks.

4. What Else Is INTERESTING to Mention?

There are so many thing we can say, but saying something important and interesting would be the best.

1. Prototype-based vs. Class-based Inheritance
2. Most Frequently Asked Questions about JavaScript
3. Introduction to Object Oriented JavaScript

Category >> JavaScript  
If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example:
String foo = "bar";

  1. LG Optimusv on 2014-2-27

    “while JavaScript code is run on a browser only … JavaScript does not create any stand-alone applications”: I think javascript code runs in a javascript engine. That’s why we have node.js.
    Not very informative.

  2. Kunal on 2014-3-3

    JavaScript uses Closures which are like classes. Read:

  3. gonpinnie on 2014-8-26

    Java is a finger while Javascript is fingerlings. Totally different and unrelated – only the first 2 syllables are the same.

  4. Romain Caisse on 2016-8-29

    Hey, that is an interesting article that you have posted. Looking forward to more of them! Also, I found this article which is equally interesting; you might want to take a look:

  5. George K on 2017-3-29

    Javascript is used for both browser and the server now, and can do many more amazing things than it used to. And if you’d like to learn it come and check our Javascript full-stack bootcamp in Barcelona Code School at 🙂

  6. Christian Rubiales on 2017-5-30

Leave a comment