The Differences Between Java v.s. JavaScript

Java and JavaScript are different, just like ham and hamster are different too.

Java is an object-oriented programming language that performs tasks based on the relationship between objects that executes in a Java virtual machine, while JavaScript is an object-oriented scripting language that does not require a compiler, it runs on a web browser instead.

JavaScript is mainly used in web development both front-end and back-end using Node.js. Java is more widely used in desktop application development, android development, server-side, etc.

The significant difference between Java and JavaScript I think is the strictness of data types.

For instance, I can just declare a variable without indicating its data type in JavaScript, as we can just say “let x = 1;” which “let” is a keyword means the value of the variable can be updated, and the declaration requires no data type indication. I can just simply create variables without worrying about its data type, “let y = “hello”; let z = true.” On the other hand, if we want to declare the same variable in Java, we have to indicate its data type like “int x = 1;” which “int” means this data type is an integer. Whenever I declare a variable, I have to indicate the type, “String y = “hello”, boolean z = true.”

The same rule can be applied to an Array/ArrayList where I can use any type of data in an array by using JavaScript, but I have to stick with the same data type when creating an array in Java.

Another thing I have noticed is the use of quotations. In JavaScript, you can use both single quotation and double quotation; for example, let x = ‘hello’; let y= ‘’; let z= ‘world’; you just have to be consistent either using a double quotation or using the single quotation. However, in Java, when you use a single quotation mark, it is usually for a char, a single character, char x=’h’; char y=’e’. Double quotation in Java is for strings, String x = “hello”; String y = “world”. Speaking of space, int ‘ ‘= 32 (32 ASCII value for space), whereas the “ “ is the space for string.

For creating methods in Java, we declare the scope for the method, like a public or private, either it returns a value with a void or without void if it returns a value, it needs to indicate the data type, and either direct access with static or without static.

public class hello{    public static void main (String[] args) {        System.out.println("Hello World");    }    public int onePlusOne() {        int value = 1 + 1;        return value;    }}

When creating methods in JavaScript, it is called a “function”, and we can declare the function starting with the keyword “function”.

Function hello() {    console.log(‘Hello World');};

Based on my research, both languages, Java and JavaScript are popular and are in demand in the market.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store