Sitemap
Byung Min cho

Byung Min cho

Java vs Javascript

4 min readApr 18, 2019

--

Many people think that because the word Javascript contains the word “Java”, that the two programming languages will be very similar. During the early days of Netscape, the two languages did intersect for a short moment. However, the two languages took different paths shortly after that and serve a totally different purpose today. There is a joke that Java is to Javascript as ham is to hamster.

Get Byung Min cho’s stories in your inbox

Join Medium for free to get updates from this writer.

Java is a general purpose programming language and Javascript is a programming language used on websites to make them animated and responsive. Since the evolution of javascript, the comparison between the two did get a bit complicated. Still there are many similarities and differences between the two languages.

Differences

  • Java creates its own standalone application while Javascript does not. Javascript resides inside HTML documents and provides activities to web pages where you can not do with just simple HTML.
Press enter or click to view image in full size
  • Java is an Object Oriented Programming language and Javascript is an Object Oriented Scripting Language. All scripting languages are programming languages as well. However, the main difference between the two is that scripting languages do not require the compilation step and is instead interpreted. A Java program needs to be compiled into what is known as “machine language” before running, but a Javascript program does not and is all in text.
  • Java creates applications that run in a virtual machine or browser, but Javascript runs code only on the browser.
  • Java is a strongly typed language and variables must be declared first to use in the program. The type of a variable is checked at compile time. However, Javascript is a weakly typed language and has more relaxed syntax and rules.
  • The Declaration of variables for Java and Javascript are different.
Press enter or click to view image in full size
Press enter or click to view image in full size
  • Objects in Java are all class-based. We cannot make an object without creating a class and it is hard to create a program in Java without a class. Javascript is a prototype-based language where objects inherit features from one another by inheriting methods and properties. In Java, we use methods that are part of a class or object. Methods are like functions in Javascript. However in Javascript, functions do not need to be a part of a class and can just standalone. Classes were introduced for Javascript in ECMAscript 2015.
Java Program — Methods inside Test class
  • Java programs use more memory than Javascript programs. This is one of the reasons why it is more reasonable to use Javascript for web pages.

Similarities

Although there are a lot of differences of Java and Javascript, there are also similarities in the code.

  • The two languages both use { and } as code block delimiters.
  • They both use ; to end statements.
  • They both have a Math library. Ex: Math.pow
  • They both have if, do…while. They both have the same syntax.
  • They both have return statements.
  • They both can be used for building web applications.
Press enter or click to view image in full size
Hello World in Java
Hello World in Javascript

Conclusion

There are many uses for Java. You can use it for building android apps, server apps at financial industries, software tools, Scientific Applications and much more. Javascript is mainly used for web-based applications and web browsers.

--

--