What is Java and why do we need it?

If it were a language like C++, we would have to compile it for the desired hardware or operating system. To compile, that is to convert the code we understand into instructions understandable to a processor. Since there are many processors, we would have to compile in different ways. There are many processors, and different operating systems have different components, buttons, networking, and so on. Before compiling, you have to modify the program to suit these features.

The power of Java is in the JVM (Java Virtual Machine). It is a program which translates human-readable Java code into code understood by the processor. To make the code universal the developers have made virtual machines for each operating system and processor. These machines take into account all the peculiarities of their platform architecture and know how to process any Java command. This means that one and the same Java-code can be run on the phone, computer or anywhere else.

Especially for programmers: we’ve intentionally simplified the principles of JRE and JVM and don’t talk about bytecode, compilation, and so on. Instead, we’ve focused on principles that help you understand the very essence of how Java works. If you think there’s something important we haven’t covered because of simplicity, tell us about it in the comments.
Where you can run Java code
So you can run Java code everywhere that the JVM, that is, the Java Virtual Machine, has already been developed for. For example:

Ultra-powerful servers,
computers,
smart phones,
push-button phones,
robots and microcontrollers like Arduino, Raspberry Pi and many others,
fitness bracelets,
GPS trackers,
smart watches,
smart TVs, refrigerators, microwave ovens, kettles and other home gadgets,
smart cards for indoor access.
Imagine the following situation: you wrote a Java program that monitors the free space on the disk, and as soon as it becomes less than 20% – it displays a message saying “Delete unnecessary files”. Now you can run this program everywhere you have a JVM. It will sort out the code itself, see what processor it is doing it for, and run your program. As a result, the same code will keep track of available space on your computer, push-button phone, smartphone, tablet, smart microwave, or home alarm system.

Advantages of Java programming
Architecture and platform independence. You write code without thinking about the peculiarities of the operating system or processor. All this is taken care of by a virtual machine, and you only write the logic of the work.

Object-oriented programming. OOP is the modern standard for programming in commercial and industrial systems. In the case of Java, it works itself out: the fact is that, like Ruby, Java is a pure OOP language. In it, even functions have turned into methods and can only exist inside a class.

Working with memory. The programmer does not need to keep track of how much memory his program uses and how to free it when a variable is no longer needed. For this purpose automatic memory management is implemented in Java: Java does not allow its leaks and growth of size, and after program’s termination frees all resources.

Security. The virtual machine itself makes sure that the program doesn’t get access to anything that goes beyond its authority. For example, a Java program can’t read the contents of the rest of the RAM, or contact another computer, unless the original access rights provided for it.

Large community and support. Java is the third most popular programming language in the world. There are thousands of sites on the web, which tell about this language, help to understand the code or contain ready-made solutions.

The standard in corporate programming. Large companies want programs to be reliable, stable, and maintainable for a long time. The combination of OOP, memory management, and architecture independence makes Java the perfect solution for this.

Disadvantages of Java
This all sounds good, but Java has disadvantages, quite significant.

Not the highest performance. C and C++ only have a compiler that translates the program into machine code. Java does not have such a compiler, and everything is done by a virtual machine. This means that to execute Java code you have to do double work: the processor runs the JVM and the JVM executes the code itself. Because of this approach Java programs are one and a half to two times slower than the same code written in C++.

Paid license. As of 2019, Oracle, which owns the Java license, has divided it into two parts: paid and free. If you need long-term support of the development environment and stable operation of programs – take the paid license, sometimes stability is more important. If you do not need support, and you can install each new free build yourself – no need to give money.

Bulky code. The developers of Java aimed to simplify C++ programming, and they succeeded. The price they had to pay for this was large and long constructs in the language, which often interfere with understanding the essence of what’s going on. Compare the code that draws a pyramid of stars in Java and Python:

Who uses Java and for what
First, a list of companies and technologies that use Java as their primary programming language:

Amazon,
LinkedIn,
eBay,
Yahoo!
OpenOffice,
IBM, Intel, and Oracle.
Android development. Java is still the main mobile development language for this operating system, despite the growing popularity of Kotlin. Android Studio is the official Java development environment, recognized by Google.What android developers do

Terminals and payment systems. Thanks to the virtual machine, Java code can work on the hardware, which is in the payment terminals and ATMs.

Working with finances. If you need a simple and reliable site for payment processing or money transfer – use Java. Built-in security systems will help to avoid unauthorized program actions.