What’s The Difference Between Java and JavaScript?

Apr 25, 2023
Andy Collins
Java is to JavaScript as ham is to hamburger.

There’s ambiguity in every kind of job. Things that seem perfectly reasonable to those already steeped in the language of the profession are wildly confusing for anyone on the outside. The field of computer programming is no different. We’ve got a lot of ambiguity - from tons of seemingly unnecessary synonyms, to outright misusing terms in a way that requires context clues and years of experience to decipher. Volumes could be written on the subject of ambiguity in software, but since we’ve found casual blog readers aren’t willing to spend weeks on a single post, today I’ll focus on one particular ambiguity: Java vs. JavaScript.

Not completely different

A web search of the differences between Java and JavaScript will reveal a lot of “humorous” commentary about the subject. You’ll find quips such as “it’s like the difference between car and carpet.” In truth however these claims are too extreme and usually targeted toward people who already know the difference and are in on the “joke.”

The fact is Java and JavaScript have quite a few similarities. Fundamentally they are both programming languages - they can each be used to instruct a computer on how to do … computer stuff. You can use either to write apps for a mobile phone, build games or run multi-billion-dollar back-end services.

Java and JavaScript are also extremely popular languages. Although it’s notoriously difficult to quantify the popularity of programming languages, the many organizations that try always put both languages at or near the top of the list. (ex TIOBE, Stack Overflow, JetBrains, HackerRank)

Both Java and JavaScript were created around the same time. In the mid 1990s as the World Wide Web was being born, quite a few languages were being developed or rediscovered. Java and JavaScript were among those languages. Each of them was released in 1995 and each had a goal of making the World Wide Web more dynamic and interactive.

Visually Java and JavaScript look very similar. They are part of a family of languages that share a syntactic style similar to the C programming language. Here is an example from each language. The code below will print the numbers 0 through 9 to the computer screen.

Java

for (int i=0; i<10; i++) {
    System.out.println(i);
}

JavaScript

for (let i=0; i<10; i++) {
    console.log(i);
}


But they aren’t the same though, right?

There is a tendency to think that JavaScript is some kind of “light” version of Java. This is definitely not the case. They are each “full” languages. And, while they do have similarities, they are very different from one another.

Those differences between Java and JavaScript date back to their creation. They have dramatically different origin stories.

Java was released in May of 1995 by Sun Microsystems after years of development by a team lead by James Gosling. Java was targeted toward professional software developers with the promise that it would be easier to write than existing languages and could be used to build applications that were more flexible and maintainable than those built with other technologies.

JavaScript was released by Netscape in December 1995. The first version was completed in 10 days by a single developer, Brendan Eich. Originally JavaScript could only be run in the Netscape Navigator web browser and had the sole purpose of making web pages more dynamic. Due to the broad nature of the web, the language was intended to be used by anyone with a website whether they had previous coding experience or not.

So why are their names so similar?

There’s a bit of controversy about how Java got its name, but essentially it was named by a committee with the oversight of Sun's legal team. They needed a catchy name that had not already been claimed by anyone else.

The story of naming JavaScript, on the other hand, is well known in the software development world. By the end of 1995 Java had made a huge splash in the industry. Its popularity was a marvel of timing, marketing and luck. Sun was a major (and well-funded) technology company and had done an impressive job of getting the word out. Java’s notoriety was so large and so far-reaching that nontechnical business executives were talking about it in board meetings. Netscape, however, was a small startup without the ability to do extensive marketing, so they decided to hitch their wagon to Java’s star. They decided they could ride the Java wave if they made a language that, at least on the surface, seemed similar. This is the reason that JavaScript looks so much like Java and it’s the reason JavaScript is named JavaScript.

A closer look at Java

Java is a compiled, statically typed, class-based, object-oriented programming language. Java’s original claim to fame was the idea that an application could be written once and run anywhere. This is markedly different from other languages that had to be recompiled for each device and operating system they were run on. Java did this by way of compiling to bytecode that is run on a virtual machine. It’s important to note that Java did not invent this concept but it brought it into the mainstream in a big way.

Way back in the 1990s Sun intended that one of the places Java would be run was on the web in the form of Java Applets. However, applets never took off due to performance, accessibility and security issues. But in every other platform it aimed for - including desktop applications, embedded systems, backend services and eventually mobile apps - Java hit its mark.

Java has a strong commitment to stability and consistency. Although the language has evolved over time, a program written in the late 1990s would still be recognizable to a modern Java developer. And a time-traveling Java programmer from a couple decades ago would - with maybe just a little help - be able to make sense of Java code that was written today. Programs written in Java are built to last. Not only will they continue to run, but the constraints of the language help ensure they can be updated and maintained over time.

A closer look at JavaScript

JavaScript is an interpreted, dynamically typed, event-driven programming language that can be written in a “prototypical” object-oriented style, but is also influenced by functional programming concepts.

As previously mentioned, JavaScript was created to be the language of web browsers, and that’s still where most JavaScript is executed today. However, since the 1990s JavaScript has expanded its reach to include many of the same types of applications that can also be written in Java.

From the very beginning JavaScript has had an emphasis on productivity and ease of use, and as tools, technologies and language preferences have evolved, so has JavaScript. This has led to significant changes to the language over time. JavaScript written to run on a GeoCities website in 1997 is vastly different from JavaScript written today. Although, impressively, the code written for that GeoCities website would almost certainly still run in a current web browser, it would be considered very antiquated and possibly unreadable by a modern JavaScript developer. Similarly a time-traveling JavaScript programmer would be very confused if confronted with today’s code.

Which language is better?

The history of programming languages arguably dates back to the 1800s - long before electronic computers existed. Today there are literally hundreds (if not more) of programming languages in existence. While many of these languages are esoteric, outdated or extremely specialized, there are a few dozen in general use today. Of those, Java and JavaScript are only two. So, the choice of which language is right for a particular job is not simple and is certainly not something this blog post can speak to. In short, Java and JavaScript are both capable, popular languages in a pool that also contains many others.

Wrapping up

The goal of this post has been to let you know that despite the names and the superficial “look” of the languages, Java and JavaScript are not the same, and they do not have a special relationship with one another. Hopefully you now have a better understanding of some of those differences and are maybe just a little closer to deciding which language you might want to explore.

Topics: Learning, Technology Insights, Web Development, Software Engineering