
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference Between Java and JavaScript
As we know, both Java and JavaScript are programming languages and are used in application development. But there are significant differences between the languages, which we will discuss below.
Java
Java is a high-level language that is also a platform-independent language. It is mainly used in the development of web applications, mobile applications, games, etc. Java is a statically typed language, which means that the code must be checked for errors before it runs.
JavaScript
whereas JavaScript is a dynamically typed language, which means that the code is checked for errors while it runs. JavaScript is a client-server-side language, which means we write the code for the client side as well as the server side. It is used for creating interactive web pages. The following are the important differences between Java and JavaScript.
Sr. No. | Key | Java | JavaScript |
---|---|---|---|
1 | Language Type | Java is primarily an object-oriented programming language that requires a virtual machine platform for its execution. | JavaScript is a lightweight programming language("scripting language") and is used to make web pages that do not require such a virtual environment for their execution. |
2 | Syntax and semantics | Java is a type of language where the compiler reports exceptions in case the syntax does not meet the requirement, or we can say that type and code semantics are checked at compile time. | On the other hand, JavaScript is a weakly typed language and has more relaxed syntax and rules. |
3 | Oops Concept | Java is a pure object-oriented programming language. | JavaScript, on the other hand, is an object-based scripting language. |
4 | JVM requirement | Java requires a JVM in order to create a virtual environment for its code execution. | On the other hand code of JavaScript runs on the browser only, so no such JVM is required for code execution. |
5 | File extension | One difference between them is that the extension of the file in which Java code is saved is ".java". | While the code of JavaScript gets saved in a file which has an extension of ".js" |
6 | Performance and memory consumption | As we know, Java requires a JVM, which makes it consume more memory and slower in the performance of code execution. Each time we need to deploy the code to reflect the code change in Java. | On the other hand, JavaScript code gets compiled and runs on the browser only and thus consumes less memory and is faster in performance. Each time we do not need to deploy the code to reflect the code change in JavaScript. |
These are the important differences between Java and JavaScript.
Example
Let's see an example to understand the difference between Java and JavaScript.
Following is the Java program -
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); } }
Following is the Java program -
document.write("Hello, World");
Here we created a simple program that prints Hello World, as we can see the difference between both is syntax and semantics.