Java vs JavaScript: what's the difference?
Java and JavaScript are two different programming languages with similar names. JavaScript runs in every web browser and makes pages react. Java is widely used for Android apps and large business systems.
Last updated
What each one means
- Java
- Java is a programming language used to build Android apps, large business systems and server software. It runs outside the browser.
- JavaScript
- JavaScript is the code that makes a web page react: opening menus, updating a basket or checking a form as you type.
Side by side
| Java | JavaScript | |
|---|---|---|
| Where it runs | On servers, Android phones and computers, outside the browser | In every web browser, and on servers too |
| Typical uses | Android apps, banking and other business systems | Interactive websites: menus, forms and shopping baskets |
| Needs installing? | Yes. Programs need Java's runtime, often bundled with the app. | No. Every browser already runs it. |
| How code is run | Compiled first into a form the computer runs | Sent to your browser as text and run straight away |
| Where it came from | Sun Microsystems, 1995 | Netscape, 1995, named partly to ride Java's popularity |
| On a website | Sometimes powers the backend | Powers the frontend, and sometimes the backend |
An example: checking your bank balance
When you check your balance on a bank's website, JavaScript in your browser makes the page react as you click. The bank's systems behind it, which look up your account and move money, are often written in Java. Same task, two different languages, working on opposite sides.
See JavaScript at work
Press Add to basket on the toy bakery page and the count goes up: that's JavaScript. Switch JavaScript off and the button still looks the same, but nothing happens. Java plays no part here, because browsers don't run Java.
Switches
Fresh bread, baked at 6am
Order by 10am, collect after lunch.
Sourdough loaf
£4.00
Cinnamon bun
£2.50
Lemon cake
£3.00
The code behind it (simplified)
HTML: what's on the page
<h1>Fresh bread, baked at 6am</h1>
<p>Order by 10am, collect after lunch.</p>
<li class="card">
<img src="sourdough.svg" alt="Sourdough loaf">
<h2>Sourdough loaf</h2>
<p>£4.00</p>
<button>Add to basket</button>
</li>CSS: how it looks
.card {
border: 2px solid navy;
border-radius: 20px;
}
button {
background: yellow;
font-weight: bold;
}JavaScript: how it reacts
button.onclick = () => {
basket = basket + 1;
showBasketCount(basket);
};Press Add to basket, then switch JavaScript off and press it again.
Common questions
Why do Java and JavaScript have such similar names?
Mostly marketing. Java was the exciting new language in 1995, and Netscape renamed its browser language JavaScript to ride that wave. They were never the same language.
Which should a beginner learn first?
If you want to build websites, JavaScript, because every browser runs it and you see results straight away. Java makes more sense if you're aiming at Android apps or big company systems.
Is Java still used?
Yes. It's widely used for business software and Android, though many new Android apps now use a newer language called Kotlin.