As we already mentioned in one of our previous articles, according to the Oracle data more than 3 billion devices in the world run on Java. So why is Java so popular? There are four main reasons for it:
1. „Write once, run anywhere” (cross-platform)
The main advantage of Java language is that the same code will work, for example:
- on Windows
- on Linux
- on MacOS
At the same time if you use another programming language you would need to write not one, but three different codes – for Windows, Linux and MacOs. This feature of Java (“write once, run anywhere”) is called cross-platform. Surely now you are curious, how does this cross-platform of Java work? Let’s look at the picture below.
- While writing code on Java you will always save each program as a separate file. Moreover, the extension of this file will always be .java. Let’s say – Program.java. If, for example, your colleagues would want to look through such a file, they will be able to read the code easily, rewrite it or add something if necessary. This is possible because the code is so to say “readable for humans”.
- Further, when you launch the compiler (to be specific it’s called javac compiler) your code from “readable for humans” turns into so-called “bytecode” (i.e. in the form of different combinations of 0 and 1) and the code becomes readable only by machines. After this process you will have one more file with the .class extension. In our case – Program.class.
- Now JVM executes the bytecode.
2. User-friendly syntax
The developers of Java didn’t try to reinvent the wheel. Instead they, roughly speaking:
- took all the best from the best wheel model, which was C++ programming language;
- discarded all needless and less than successful things from C and C++;
- implemented innovations in the new Java programming language.
And they benefited from their approach. Considering the fact, that C++ language is at the very core of Java syntax, it was much easier for programmers to transfer to the new language. After all, it was not necessary to learn everything absolutely from scratch, because many constructions were familiar to them. It also contributed to the rapid growth in popularity of Java among programmers.
3. Object-oriented language
We will try to explain the essence of object-oriented language in a few bullet points. Later we will publish a whole article dedicated to this topic in our Java OOP section. In the meantime, this explanation should be enough for you.
OOP is a programming by means of classes and objects. To begin with we need to understand what is object, and then we will come over to understanding of idea of classes.
Everything around us is an object. For example,
- Car is an object
- Human being is an object
- Cat is an object
- Dog is an object
- Table is an object
- and so on
Each object has its own characteristics. For example, characteristics of a car are model, color, size, etc.
Each object has methods, i.e. actions, which an object can perform. For example, methods of a car are to slowdown or to speed up.
As we already mentioned, OOP is a programming by means of classes and objects. So what is a class?
Class is a ready template. Here are a few examples of classes:
All cats are different:
- with short hair
- with long hair
- without hair, etc.
At the same time, all the cats have much in common. Well, then if we identify these common features as a separate class Cat, then we can use this class as a basis every time when we need to create a cat. In this case, the class would work as a template. And then we would specify additional features, i.e. characteristics of each particular cat.
All cars are different:
- passenger cars
- Entry level cars
- Executive cars
However, all cars have much in common. So if we identify these common features as a separate class Car, then we can use this class as a basis every time when we need to create a car. In this case, the class would work as a template. And then we would specify additional features, i.e. characteristics of each particular car.
It is to be recalled that OOP (Object-oriented programming) is programming by means of classes and objects. However, we will talk about OOP in details when we reach OOP Java level. In the meantime, this information will be more than enough