Why programmers continue to use verbose Java, although there is concise Python

Original author: Bobby
  • Transfer


From a translator: this article is an attempt by the author to show the advantages (not disadvantages) of the Python and Java programming languages, as well as demonstrate the duality of any comparisons. Something that seems an advantage may turn out to be a disadvantage, and vice versa. Perhaps some points may seem controversial, but this is for the best - in the comments you can discuss everything by correctly substantiating your point of view. The article is suitable for both beginners and programmers with experience.

Java and Python are equally popular programming languages. However, Python is more productive: it has less code needed to solve the problem. Why are programmers still working with Java where you can use Python? Let's get it right.

We remind you: for all readers of “Habr” - a discount of 10,000 rubles when registering for any Skillbox course using the “Habr” promo code.

Skillbox recommends: The on-line educational course "Profession Java-developer" .

Performance comparison


First, let's discuss why Python is more efficient and saves time when developing a web application.

Dynamically Typed

One of the main reasons Python is a more productive language is dynamic typing. This means that we do not need to declare anything - we just give the variable a name and assign a value. Python independently determines its type according to the assigned value.

But Java is a statically typed language. All types of variables here must be declared. If you make a mistake, the program will not work or will, but with problems.

Brevity

Python is a very concise language: only a few words can be used in a few lines. But Java is verbose, it uses a lot without direct need. An example is the “Hello, World” program, written in both languages.

Java:

public class HelloWorld{
    public static void main (String[] args){
        System.out.println("Hello, World!");
    }
}

Python 2:

print "Hello, world!"

Moreover, in Python there are other functions that allow you to make the code small in volume. Here are some more examples.

Java:

int x = 5;
int y = 6;
int temp;
temp = x; // temp has the value of 5
x = y; // x has the value of 6
y = temp; // y has the value of 5

Python 2:

y, x = x, y

Fewer Boilerplate code than in Java

Python contains much less Boilerplate code than Java, which simplifies development. Java, where there is a lot of Boilerplate code due to the verbosity of the language, sometimes baffles newcomers (and not only them), since it takes a lot of effort to solve a simple problem.

Ease of Learning

There are few programming languages ​​that are easier to learn than Python. The dynamically typed nature of the language and its laconicism, rationality make the language accessible to many. Java is a more difficult language to learn.

Why use Java?


Well, now let's see why Java is still widely used, despite the fact that working with it requires more effort than with Python.

Statically Typed Statically typed

languages ​​have flaws, most of which have been described above. But they also have advantages, which are also many. So, for example, Java provides type safety, which catches all potential errors at compile time, and not at runtime, like Python. Thus, the likelihood of errors is reduced. Ultimately, all this simplifies the management of large applications. Runtime errors (which appear when developing web applications such as Python) are more difficult to identify and fix than errors during compilation.

In addition, analyzing Java code is much easier than Python code, which is useful in situations where a team of programmers is working on the same project. Java programmers will quickly understand each other's code, since everything is declared explicitly, but Python programmers may encounter several problems when reading web application code. The fact is that everything is determined or displayed during the execution of the application when variables or signatures become known.

Performance and speed

Actually, neither Java nor Python are the best option for creating highly loaded applications, but the first language has solid advantages compared to the second. All this thanks to JIT (Just-in-Time Compiler), which converts regular code into machine language. As a result, the performance of Java applications is approximately equal to the performance of what is written in C / C ++.

Python developers can use Cython and Jython to write C / C ++ modules and Java code for Python. But this does not greatly improve the overall speed of applications. Python is much slower than Java.

Porting and cross-platform.

Both languages ​​are platform independent. However, Java has slightly better cross-platform support.

Because Python is slower than Java, Python developers often need to delegate certain tasks to libraries written in other languages, such as C ++ or Fortran. Consequently, companies that use Python may need staff, tools, and infrastructure to develop modules, such as in C or to use existing C / C ++ libraries. This way you can lose the platform independence that pure Python promises. But in the case of Java, nothing of the kind is needed - the developers work only with Java.

Concurrency vs. Parallelism

Java provides full support for concurrency from the start. In addition, there are several great features for concurrency and multithreading. Java also supports parallel programming better than Python. Due to the GIL (Global Interpreter Lock), which restricts Python to a single processor, this language cannot offer the same.

Ecosystem

Both Python and Java have a lot of great libraries and frameworks. But Java is preferable for developing enterprise applications due to the variety of libraries and environments focused on creating highly loaded applications in this area. They are supported by a large community of developers from large companies. Consequently, programming enterprise applications becomes much easier. A powerful and extensive ecosystem is the reason that so many languages ​​are JVM oriented: Scala, Kotlin, Clojure, Groovy, etc. Additionally, Java has powerful dependency management tools such as Gradle and Maven.

Mobile development

Both languages ​​are used in almost all areas of IT, including desktop systems, web, artificial intelligence, scientific computing and analytics. Yes, Python has more advantages in the field of analytics. But mobile devices are a niche where Java dominates.

It is noteworthy that Java is one of the official programming languages ​​for Android, competing only with Kotlin. Most applications running on Android devices, including smartphones or tablets, are developed in Java. The language is successfully used in embedded systems.

Although we can develop mobile applications in Python using the Kiwi library, this is not the best way.

Database

Java has a clear advantage here thanks to JDBC (Java DataBase Connectivity). This is a platform-independent industry standard for the interaction of Java applications with various DBMSs, implemented as the java.sql package that is part of Java SE. JDBC is based on the concept of so-called drivers, allowing you to get a connection to the database at a specially described URL.

In conclusion


Java and Python are great, powerful languages. Each has its own niche, and, as we see, both have clear advantages in one or another sphere, so there is no point in arguing about which one is better. They just have a different philosophy. While Java was created in order to reduce the likelihood of errors, Python was designed so that the programmer could quickly achieve his goal.

Skillbox recommends:


Also popular now: