This blog post is a beginning of the series "Java for JavaScript Developers" and it describes my experience while learning Java programming language.
So, as many of you have already know from Twitter, due to my job specification I started to learn Java after being a web developer and using JavaScript for building projects. During a few years of using JavaScript and building projects mostly with React and other front-end frameworks, I have to dig myself into back-end.
That felt a bit weird I should say. Even though I used to learn new languages all the time (I speak 5 languages and finished linguistic university), it takes time to get used to new rules and new syntax.
Differences
After the first week of study I can already distinguish the main differences between 2 languages:
Java is static language and JS is dynamic language.
What this means is they check their data types on different stages.
Java checks types before run-time, each variable has to be associated with a type upon declaration.
JavaScript checks types on the fly, during execution and the type of variable is unknown until program compilation.Java is one-paradigm and JS is multi-paradigm
What this means is that:
Java is strictly object-oriented, meaning it solves programming problems based on the concept of objects and everything is built around objects.
JavaScript on the contrary can be used as object-oriented, procedural or scripting language (it is used mainly as scripting though).Java is stand-alone language and JS is co-dependant language
What that means is that:
Java can be used to build a fully-functional application by developer without any additional languages. It can run on multiple platforms.
JavaScript is depending on HTML and CSS and cannot be used as a stand-alone language to build a fully-functional application. Even though nowadays JS is widely used for back-end (Node.js), it still needs cooperation with additional languages.Java objects are class-based and JS objects are prototype-based
What that means is that:
Java uses classes as templates for objects creation. It allows a class to derive (inherit) the properties of another class. It also supports multiple inheritances i.e.; a class can derive properties from multiple classes.
JavaScript uses prototypes - special objects, to which additional properties can be attached, which will be shared across all the instances of their constructor function. It does not support multiple inheritance.Java supports multi-threading and JS doesn't.
This one says it all in one sentence :) JavaScript does not support multi-threading because the JavaScript interpreter in the browser is a single thread.
Similarities
BUT there are some similarities between the languages:
Object-Oriented Programming: Both languages have access to OOPs concepts such as abstraction, inheritance, and polymorphism.
Front-end Development: Java and JS both extend their applications in frontend development. JS can be embedded directly into HTML, which is implemented as a framework or a library; whereas, Java is used as Java Applet.
Back-end Development: Both languages offer server-side support. Java supports major backend technologies such as JBoss, Apache, and WebSphere. Node.js serve JavaScript-powered servers.
So, these are the main differences and similarities between Java and JavaScript and if you want to explore even more on this topic, take a look at this article
In my next blog post I will write about basics of Java language and compare them to basics of Java Script :)
Thank you for reading my blog. Feel free to connect on LinkedIn or Twitter :)
Top comments (3)
iThinkThereIsAnotherSimilarityRegardingCodeStyle... 🤔
A good article!
I didn't knew about java Applets before.
It's been helpful. Thanks