JavaScript vs Java
Published: 2020-09-17 15:00:07

Since "JavaScript" includes the word "Java", it is a common misconception that JavaScript is based on Java.  This has confused many since JavaScript came into existence, and it continues to confuse people after 25 years.  Some believe that since Java was the popular programming language when JavaScript was created, Netscape was trying to leverage that popularity by including Java in their creation's name as a clever marketing scheme.

#What is JavaScript?

JavaScript is a scripting language that was born as a result of Netscape's desire to load dynamic web pages in their Navigator browser.  Their first attempt was to incorporate Java for which Brendan Eich was initially hired.  However, Netscape decided that it would be best to create a new language similar to Java.  The new language was called LiveScript, but the name was changes to JavaScript three months later.

#What is Java?

Java is a class-based, object-oriented programming language whose intention is to allow developers to "write once, run anywhere" (WORA).  Once compiled, it can run on all platforms that support Java without the need for recompilation with the use of the Java Virtual Machine (JVM). Java was created by a group of Sun Microsystem engineers called the "Green Team".  Unlike the ten days it took to develop JavaScript, Java took almost four years.  It was initially called Oak, and then it was known as Green.  Finally, it was renamed Java after the Indonesian coffee.  Java is currently owned by Oracle.

#What are the similarities?

Both languages have a syntax similar to C.  Since Netscape's projected initially started with Java, JavaScript uses similar naming conventions used by Java.  Java wanted to keep the leraning curve low for programmers that were accustomes to C and C++.

Both languages can be used front-end development.  JavaScript can be embedded directly into HTML, and it can be implemented as a framework or library.  Java can run in the browser as a Java applet, and it too uses libraries.  

Both languages can be used on the server.  JavaScript was bale to run on the server with the introduction of Node.js.  Java has been running on servers for longer with technologies like Apache and WebSphere. 

Both are influenced by the programming community.  They both have a large programming community following.  Java's standard is controlled through the Java Community Process (JCP).  Anyone can become a JCP member by simply filling out a form at their website.

Both have libraries and frameworks.

#What are the differences?

JavaScript is an interpreted programming language while Java is a compiled programming language.  JavaScript is interpreted directly by a browser, and Java runs on a virtual machine.

JavaScript uses dynamic typing; the data type is then determined at runtime.  Java uses static type checking, so the programmer must specify the data type of all created variables.  Dynamic typing has the advantage that the programmer is free to assign any data type to variables.  Static typing has the advantage that type errors are caught early in development.  

JavaScript is a single-threaded.  To handle concurrency, a system queue called the event loop was introduced.  Java is multi-threaded, so it can perform tasks in parallel.  Both work fine in most cases; however, Java is generally faster.

#Applications of JavaScript

JavaScript should be considered for:
* Dynamic single page applications (SPA)
* Client technology
* Server technology
* Mobile app

#Applications of Java

Java should be considered for:
* Android apps
* Enterprise software
* Scientific computing
* Big data analytics
* Hardware programming
* Server-side technologies

#Hello World!

Hello World in JavaScript:

```javascript
console.log("Hello, World!");
```

Hello World in Java:

```java
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
```

# . . . Which one is better?

Neither programming language is better than the other.  Each one is useful, and each has strengths over the other.  They are both used by programmers for a variety of tasks.