The story behind Java and JavaScript: what’s the difference?

This post was written by Elana Kopelevich, Software Engineering Resident 

Java ≠ JavaScript

When you’re first getting started with programming, your ears start to perk up at new words. You start catching familiar terms in a sea of foreign phrases. When you come across words that you’ve heard before, you may start making associations: object and object-oriented, function and functional, variable and constant.

This natural tendency may be why so many new developers think that Java and JavaScript are the same, similar, or related in any way at all, when in fact, their association is no closer than any other two languages chosen at random. The only story that these two distinct languages share is the one of a marketing gimmick.

Java Came First

The Java project—originally intended to be a solution for interactive television—was initially developed under the title Oak, named after an oak tree that stood outside a core developer’s office. Later, the project went by the name Green. Finally, perhaps influenced by a caffeine-fueled sprint, it was renamed Java, as in coffee. In retrospect, this seems like a pretty obvious naming decision for developers.

Sun Microsystems released the first implementation of Java in 1995. With the promise of its tagline, “Write Once, Run Anywhere”—meaning the same code base could be compiled for a variety of different platforms—as well as a familiar C-style syntax and its ability to run in browsers (with special mini-programs called applets), Java’s popularity grew quickly.

JavaScript in 10 Days

In the same year that Java 1.0 was unleashed on the world, a Netscape employee named Brendan Eich wrote an entirely new kind of language. Eich’s employer tasked him with creating a language that would run natively in the browser (unlike Java, which required encapsulated Java programs to be loaded) as well as appeal to nonprofessional programmers.

As Java was gaining popularity, Eich’s managers wanted something that “looked like Java.” Eich complied to some extent, but strayed in significant ways, largely because he was writing for an entirely different purpose. He was writing a client-side, multi-paradigm scripting language for non-professional developers—all the things that Java was not.

Still, the Netscape team was looking for a promotional edge. That’s probably why the JavaScript project started with the name Mocha. It was later changed to LiveScript, and, finally, to JavaScript. This was a marketing move. The Netscape team wanted to ride on Java’s coattails.

They are Different in Significant Ways

Sure, Java and JavaScript are both programming languages and you can use both of them to build applications, but the same could be said about any two choices in the grand lexicon of programming languages.

Again, Java is a general-purpose programming language that is compiled, concurrent, strongly-typed, class-based, and object-oriented. JavaScript, on the other hand, is primarily a web language* that is interpreted, single-threaded, loosely typed, prototype-based, and multi-paradigm.

The Takeaway

It would be false to say that Java and JavaScript share no similarities at all. They are both C-style languages. There are some similarities in the control flow of the code, and the truth is that Brendan Eich made some conscious incorporation of some of Java’s features when he was writing JavaScript. However, the underlying purposes of the languages are so different that the list of similarities ends there.

If you are wondering which language to learn first, it really depends on your goals. If you want to write for the web, start with JavaScript. If you’re focused on getting an enterprise application programming job, perhaps you should start with Java. The advantage of either choice is that knowing any programming language will give you a head start on learning another one. Just remember, particularly for your first developer interview, that Java and JavaScript are not the same things!

*Jeff Atwood wrote a prophetic maxim on his blog, Coding Horror in 2007. He coined it Atwood’s Law, and it states that any application that can be written in JavaScript will eventually be written in JavaScript. This prognosis is coming to life in the present day. JavaScript is now being used extensively for server-side applications and even hardware. With native wrappers such as Electron and Ionic, JavaScript developers are building standalone native-like applications as though it is no big deal. While Java still has its place in the stable world of enterprise software development, the line between web apps and standalone apps is getting fuzzy.

_____

To start learning, check out Hack Reactor Coding Bootcamps

We Hack the Future

Transform Tech from Within with Software Engineering Bootcamps

Not sure if a bootcamp is your next step? Sign up for an info session or schedule a 1:1 Q&A with an advisor to learn about our programming.