By the end of this article you will be

  • Learn about the controversy surrounding Java as one of the most popular languages
  • Learn about the Java ecosystem and future

1. Introduction

Why Java Is Perfectly Alive — A response to “Why Java Is Dying”

The original address: betterprogramming. Pub/according to Java – is…

By Ivan Khodyrev

Note: All images in the article are from the original

The world of programming languages has been abuzzlingly lively, with scorn chains and war of words, and Java, one of the most popular languages of all time, not immune to controversy. Today we’ll take a look at how this 1800-liked article makes the case for Java from the perspective of a foreign author.

2. The body

I wrote this lengthy review in response to the article “Why Java is Dying.” My comments at the bottom of this article are at the top and I think I should write a comprehensive analysis article.

The best short answer to the original author’s article is Coder:76, which has hundreds of likes.

For bloggers seeking attention, Java has been dying or dead for 15 years.

I couldn’t agree more.

2.1 What’s wrong with saying “Java is dying “?

The article, “Why Java is Dying,” received more than 70 comments, most of them critical, and dozens or hundreds of likes each. Why are so many people commenting so negatively? The reason is simple. This article is provocative and contains many controversial claims that are far from the reality of the situation for Java users. Let’s take a look at some of them.

“For example, Spring has configured bean injections, which is understandable, but where is Lombok in the application environment and how is messaging coordinated between the two?”

To the people who use the technology, that looks wrong. Lombok is a compile-time library and Spring is a runtime library. They work at different levels at different times in the application life cycle and do not interact directly. Author’s question “Where does Lombok fit into the application environment?” The correct answer to “no place” is “no place”.

“Java still seems to focus on silly rules that dictate what class names should be, what packages they should be in, and whether variables should be private or protected. Really, who cares?”

People who work on large, long-term projects care. The rules are not silly to them.

“By contrast, ‘We’re all adults’ is simply Python’s official response to the lack of access specifiers in the language.”

There’s nothing wrong with someone on the team assuming that someone else isn’t an adult — it’s an obvious idea. The problem is that large projects with long duration and large teams need rules; Otherwise, they will fail.

A big project is like a big city. It requires building foundations, planning, separation of concerns, private and public areas. If a skilled programmer divides language structures into public and private, they are likely to create “streets” that steer others in the right direction, save them time, and hide auxiliary infrastructure “underground” so that no one gets lost there.

There are many more controversial claims in the article “Why Java is Dying,” but my goal here is not to go into detail. What I’d like to do is take this opportunity to talk about the state of Java today.

For years, Java was one of the programming languages of choice and the target of critics. Not because it’s bad, but because it’s a high-profile target, and if you want to get more attention for yourself, you have to say something against it and pray that someone notices. From this perspective, Java is a good target.

But what about now? Is Java still hot stuff? Or “dying,” as some have put it? Let’s clear this up by discussing the most important and controversial topics.

2.2 grammar

In general, Java’s syntax is criticized the most: “not concise,” “outdated,” “too many templates,” and so on. The only correct answer to these “arguments” is to show the code. I won’t discuss specific syntactic features here; there are plenty of detailed guides that cover all the nuances of Java syntax. Instead, I’ve chosen five snippets just to give you an idea of how Java works today in different real-world tasks.

import static spark.Spark.*; public class HelloWorld { public static void main(String[] args) { port(80); get("/hello", (request, response) -> "Hello World"); }}Copy the code

You’ve probably heard of the “good” days when a simple Java web server required hundreds of lines of code and configuration to run? Forget them now.

This code uses Spark Java to start a simple web server on port 80 with the HTTP GET method and/Hello context path that returns a constant string on request. Very direct and concise, isn’t it?

. OrderRepository orders; QOrder qorder = QOrder.order; DateTimeFormatter yyyyMMdd = DateTimeFormatter.ofPattern("yyyy-MM-dd"); public Iterable<Order> getShopOrdersByDate(ShopId id, ZonedDateTime date){ return orders.findAll( qorder.shopId.eq(id).and(qorder.date.eq(yyyyMMdd.format(date))) ); }...Copy the code

Some people say, “Java wasn’t built for database manipulation.” They must be joking.

This code uses a combination of Querydsl and Spring Data to get information from an SQL database. It all looks simple enough: the getShopOrdersByDate method returns an order from a particular store on a particular date, with additional date formatting.

Interestingly, there is no SQL, only Java structures, which are later translated into secure SQL in the library. This means that the query itself is type-safe and will be checked reliably at compile time, rather than randomly at run time. In addition, the IDE helps you automate, just like any other Java code, making your job easier.

There are plenty of databases out of the box, like PostgreSQL, MySQL, Oracle, and even MongoDB. Plus, if you want to try them all out, you don’t have to change the query code.

import java.nio.file.Files;
import java.util.stream.Stream;
import static java.nio.file.Paths.get;
import static java.util.stream.Collectors.*;

public class Example {
     public static void main(String[] args) throws Exception {
        List<String> fileLines = Files.readAllLines(get("huge.txt"));
        String fileStats = fileLines.parallelStream()
                .flatMap(line -> Stream.of(line.split("\\s+")))
                .filter(word -> !"dumb".equalsIgnoreCase(word))
                .collect(groupingBy(word -> word.charAt(0), counting()))
                .entrySet().parallelStream()
                .map(letterStats -> letterStats.getKey() + ":" + letterStats.getValue())
                .collect(joining("\n"));
        System.out.println(fileStats);
    }
}
Copy the code

Never wanted to do a simple data analysis in Java? I suggest you try it.

There are no additional libraries, just pure Java.

Read all the lines from the big file, divide them into separate words, filter out dumb words to make sure the result is what you want, group the words by their first letter, count how many words are in each group, create a string representation of the result grouping and counting, and print the result.

This is a fairly readable and maintainable process. Of course, everything is done in parallel threads to achieve the right amount of acceleration so that your 16-core machine can live up to its cost.

On my quad-core laptop with Java 15, this code took an average of six seconds to execute for a 1.2GB text file filled with random words. This is not bad for such large files and straightforward unoptimized code.

. public MultiLayerNetwork createModel() { return new MultiLayerNetwork(new NeuralNetConfiguration.Builder() Regularization (true), l2 (0.001). The learningRate (0.01). The weightInit (weightInit. XAVIER). Activation (activation. RELU) .stochastic_gradient_descent.updater(New Nesterovs(0.9)).list().layer(convolution(5, 25).nIn(3).build()) .layer(maxPooling(2).build()) .layer(convolution(3, 50).build()) .layer(maxPooling(2).build()) .layer(convolution(3, 100). The build ()). Layer (maxPooling (2). The build ()). The layer (dense (200). DropOut (0.5). The build ()) E. (200). Layer (dense dropOut (0.5). The build ()). The layer (outputClassification (10)). SetInputType (convolutionalFlat (28, 28, 3)) .backprop(true).pretrain(false) .build()); } ConvolutionLayer.Builder convolution(int filterSize, int filterCount) { return new ConvolutionLayer.Builder(filterSize, filterSize) .activation(IDENTITY).nOut(filterCount); } SubsamplingLayer.Builder maxPooling(int size) { return new SubsamplingLayer.Builder(PoolingType.MAX) .kernelSize(size,  size).stride(size, size); } DenseLayer.Builder dense(int size) { return new DenseLayer.Builder().nOut(size); } OutputLayer outputClassification(int numOfClasses) { return new OutputLayer.Builder(LossFunction.MCXENT) .nOut(numOfClasses).activation(SOFTMAX).build(); }...Copy the code

They said, “You can’t do deep learning in Java.” Yes, you can.

This simple example shows how to prepare the neural network structure phase before the learning phase, which uses Dl4j. Those in the field of deep learning will recognize many familiar words.

It’s no big deal. Yes, you can also do deep learning and machine learning in Java.

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class User {
    String name;
    String surName;
    List<ContactInfo> contacts;
}
Copy the code

Lombok (Lombok and Java both take their names from the Indonesian islands) is an island adjacent to Java. They are so close that you can even lump them together.

You hate templates? Use Lombok. This code snippet shows a fully functional data class that includes all the fields getters, Setters, equals, HashCode, toString, and finally AllArgsConstructor. Of course, you can cover any of them if you wish.

People from outside the Java ecosystem often argue that “Lombok makes Java not Java”. I don’t agree with that. Lombok is Java. It is part of the modern Java ecosystem and uses legitimate Java mechanisms to augment its functionality to help you work with Java code, with few drawbacks, and is used and loved by many Java developers. How many people? According to one of the most popular Java ides, 11 million Lombok plug-ins have been downloaded.

It is a tool to make Java better, so in a practical sense it is Java for millions of people who use it. Still, there are sections of the Java community that oppose Lombok, and they have every right to do so — if you don’t like Lombok, no one is forcing you to do so.

Now imagine what these examples would look like in other languages. You may find that you can achieve the same goal with fewer characters. But will this code be as reliable, readable, maintainable, and fast as the Java language? I don’t think so.

Another important thing related to syntax is IDE support. This is not an abstract theoretical question, such as how powerful language structures are, or how much code developers have to write to do anything. Integrated Development environments add a utility layer that turns all the abstract questions into the question of how much developer time a particular task will take.

Using a well-designed language combined with a modern IDE, developers can achieve their goals faster than using more powerful or concise but ide-unfriendly languages. Java is one of the languages with the best IDE support because of its syntax. It’s not too complex and it’s not too optional, so the IDE can understand your current working environment and predict with great precision what you’re going to do next.

Finally, Java’s syntax allows for different styles of programming. Your code can be written in an object-oriented paradigm, where objects interact with each other; It can also be written in programmatic paradigms, changing global state through sequences of imperative program calls; You can also use functional paradigms. you can arrange and apply functions to achieve your goals. Sometimes people distinguish between more paradigms — For example, Java works well with section-oriented or actor-based paradigms. Java gives you a lot of flexibility in how you think about your tasks, so it’s well prepared for programming paradigm shifts.

In short, there is nothing wrong with Java syntax. It is relatively simple, flexible and expressive. Moreover, it allows the IDE to help developers effectively in many ways, greatly increasing their productivity. If you know Java well, write clear code, and use the right toolset for your task, your programs will be beautiful, maintainable, and concise. Don’t let people deceive you on this topic.

2.3 reliability

Unlike many other technologies, Java as a language and a platform gives you a level of reliability you can count on.

The Java language has the Java Language Specification, which is the primary basis for determining how the structure of Java code should work and how it should be used.

Why is it important? Because you can validate what you’re doing and resolve problems or disputes in a rigorous, predictable way. With languages without specifications, you can’t be completely sure what’s going on. You might find bits and pieces of information in manuals, blogs, or tweets from language creators, but until a language is regulated, none of these pieces of information have a strong basis to guarantee anything.

Of course, specifications vary in quality or level of detail, so something may be missing. But a regulated language gives you more confidence than a non-regulated language that you’re doing the right thing. The Java specification is so deep and detailed that there is almost no ambiguity in it.

The Java version is strongly backward compatible with things in the specification and public Java apis. This means that if you take code that uses version 1.3 of the public Java API that was written 20 years ago and run it on Java 15 today, it will work fine.

Also, if you use proprietary Java apis that include classes and methods/fields that should not be used directly by developers, you may get into trouble. I think it’s a pretty fair deal: if you’re using something with a backwards compatibility guarantee, you can rely on it, but if you’re using something you’re not going to use, don’t expect them to work forever.

Java is secure, not absolute, but realistic. Java code is safe because developers are less likely to make mistakes with it than in many other languages. It is safe because Java code does not have direct access to the operating system or hardware, so the Java runtime can restrict what Java programs can and cannot do.

Java code is portable. This means you can compile Java code on one platform and run it on any platform that implements the Java Virtual Machine without recompiling.” “Write once, run anywhere” — the old Java slogan — still works 25 years later.

Extensive portability with backward compatibility is a very powerful combination of assurance that developers will not quickly become obsolete with their efforts and knowledge. There are exceptions, of course, and some virtual machines allow only a subset of the Java language specification for different reasons, such as hardware limitations. For example, you can run Java code on a microcontroller with 8kB of RAM, but there are some limitations that you have to consider.

Java code is maintainable. Compared with C++ and other languages, Java syntax is a great simplification; It lacks many of the features, customization, and powerful structure of C++. At the same time, Compared to scripting languages, Java has many “rituals” that, at first glance, seem redundant. In this sense, Java tries to strike a balance between complexity, capability, and readability to maximize the long-term maintainability of code.

What is maintainability? I describe it as the time it takes an average skilled developer to apply a change to an existing code base (probably an old code base) that leads to the developer’s goals and doesn’t break anything else. The less time it takes, the more maintainable it is.

In that sense, Java is good. On the one hand, it is powerful enough to express many of the things a developer needs, but at the same time it is not as complex as some languages, where one can use extremely powerful language constructs to create beautiful, unsolvable mazes that only their creators can understand. Java, on the other hand, forces developers to write more verbose code with more explicit stuff than developers typically do in scripting languages, to increase readability and understandability.

Java is fast. If you try to research this topic, you’ll probably find dozens of articles like “Java is faster than X “and “X is faster than Java” with conflicting statements and conclusions. If you try to experiment on your own, you can easily build examples of Java being slow and Java being surprisingly fast — and you can do the same for other languages, by the way.

There is a good comment about why Java was considered slow in the past. It’s kind of out of date now. For example, the latest Java runtime handles strings much better than it did seven years ago, and I disagree with some other claims. But the general conclusion is that With each release, Java gets optimized to improve its performance, and that’s true. Remember the third example from the syntax section of this article?

On my laptop, it took an average of 10 seconds with Java 8 and 6 seconds with the same configuration with Java 15. This is one of the key assurances given to us by the language’s developers. Java is fast enough for many tasks today, and it will be faster in the future.

The last important thing about reliability is this. They have done so for more than 25 years, and there is no reason not to do so in the next few years.

2.4 Java has been slow to introduce modern language features

Yes. In general, is slow a bad thing? It isn’t. Ask yourself, the following is a question. If you were riding your bicycle and you saw a wall in front of you, what would you choose: speed up or slow down? I bet you did the same thing I did.

So why has Java been slower to adopt functionality than some other languages? Because of reliability, which we discussed in the last section. These reliabilities are walls that force features to be discussed, filtered, or translated in some way, where slow is a better friend than hurry.

There is a formal Process for how changes to the Java language are applied, called the Java Community Process. The main purpose of this process is to verify that the proposed functionality does not compromise Java reliability, which is obviously sometimes not a quick task.

Java language developers try to strike a balance between innovation and reliability, which is much harder than the “let’s add this cool feature to our language right now” strategy. But in the long run, it can do more good, because reliability means trust, which is more valuable for the future than cool features. Brian Goetz has a great talk on this strategy and the overall philosophy of Java, check it out.

Also worth mentioning is the current Java release schedule. Every six months in September and March, a new version of Java is released that is fully usable, and gradually updated over the next six months. Every three years, one such release becomes a long Term Support (LTS) release, gradually updated over the next three years.

Currently, Java 15 is the latest version, and Java 11 is the current LTS. The next LTS release will be Java 17, scheduled for September 2021. Each version may include some “preview functionality”. These features do not guarantee compatibility in future releases. Their goal is to get developers to try out controversial innovations and leave feedback about them. Such as

If a feature is not marked as a preview, it means it will be fully included in the platform and will have Java reliability.

2.5 Ecosystem

Some people take a narrow view of the language ecosystem, limiting its concept to a set of libraries available to programmers. I prefer to think of ecosystems more broadly as tools for dealing with problems. The more problems a developer can solve with language, the broader the ecosystem. It doesn’t matter which meaning you like. Java has a huge ecosystem.

Some of the problems listed below are personal problems I have had in the past:

  • Can I write web applications in pure Java without knowing anything about HTML, JS, or CSS? You can.
  • Can I stop the world with a terabyte heap in milliseconds? Yes, it’s very easy.
  • Can I process images and videos in pure Java for portability? You can.
  • Can I do deep learning in Java? Yes.
  • Can I program that robot I bought on Black Friday in Java? You can.
  • Can I find the answer to my stupid personal question about Java? Yes.

This list is definitely personal, but I’m pretty sure that in most cases, instances of “yes” will trump instances of “no” when the problem involves Java in a programming context.

With the help of the Java ecosystem, you can solve a lot of problems in a lot of areas, and you often have a lot of choices about how to do it. If you want to understand just how big the Java ecosystem is, take a look at this resource.

2.6 Startup Time and Memory Usage

Java Code is compiled into an intermediate form called Java Byte Code, which is then executed on a running platform called the JVM. In addition to complaining about Java’s syntax, critics often complain about JVM memory footprint and startup time. Let’s discuss it in more detail.

The JVM stands for Java Virtual Machine, which means your application runs inside a sandbox of a virtual computer. There are many benefits to this approach. Developers don’t have to worry about the nuances of the operating system and hardware, where the application runs. Virtual sandboxes provide greater security capabilities because they do not allow applications to interact directly with low-level things. The virtual environment stands outside of your application, can be dynamically optimized to improve performance in different situations, and so on.

The downside is that the JVM requires additional resources, including memory and processor time, to function, and it also has a boot and warm-up time.

In common usage, the standard Oracle HotSpot JVM introduces tens or hundreds of megabytes of additional footprint and requires an average startup time of a few seconds, depending on the application. (The JVM itself usually starts within a second, but some other libraries increase this time due to their internal routines). In addition, the JVM may consume more CPU than average in the first few seconds after startup because it recognizes and compiles the “hot” part of bytecode to optimize its future use.

In most cases, these shortcomings are justified for many types of applications. But, in some cases, they’re not, and you want to trade the pros and cons in some way. So, what should you do? Should you give up Java for something else? Usually not — just adopt another operating environment that suits your particular task.

Consider, for example, the world of microservices. Modern microservice applications typically require minimal memory footprint and startup time to efficiently populate container coordinators such as Kubernetes. To meet this need, Java developers created GraalVM. It allows developers to create local images from Java code that run in tens of milliseconds of startup time with only a few megabytes of additional memory footprint. Many Java networking frameworks use GraalVM for microservices. Quarkus, Micronaut, Spring, Helidon.

The downside of trading? You lose portability and build images that will only run on the platform where GraalVM is compiled. But for microservices, this doesn’t really matter, because your application will likely run in a container with a predefined environment. You may also face other limitations. In short, remember when you hear that Java is not suited to modern microservices requirements. This is wrong.

Java does not mean excessive memory usage and slow startup times, as many critics claim. The amount of memory used and startup time depends largely on how long it takes to finally run an application and the additional libraries it uses. In that sense, the choices the Java ecosystem gives you depend on your needs.

2.7 What exactly is Java for?

Java can be used for everything you can imagine: apis and web servers, gaming and multimedia software, UI and web applications, Internet of Things and robotics, AR and VR, machine learning and data streaming, databases and cloud native microservices, huge enterprise systems and small software projects.

Are there any exceptions? Not technically, but practically. Java is not intended to be a low-level system language, so creating the core or hardware drivers of an operating system in Java is not a good idea. Technically yes, but there are better tools than Java for these cases.

2.8 But we have to pay for Java, right?

No, if you use a free Java distribution, you don’t have to pay for Java.

Java is open source, so anyone can build ready-to-use Java distributions, and there are many free pre-built distributions such as OpenJDK, AdoptOpenJDK, AWS Coretto, Azul Zulu, and others. These distributions are completely free to use, and any one of them will most likely meet your requirements. If you want to learn more about this, please refer to this article.

2.9 The future of Java

To sum up, Java is still a monster.

Java’s role is to be the core technology in many areas, balancing innovation, capability, and maintainability to sustainably support the projects it applies to. If you like trying out cool new language ideas, please choose other technologies.

However, if you see a particular feature end up in the Java specification, you can be sure that it wasn’t added by chance or to catch up with a trend, but was the result of deep research and significant design efforts to achieve the same level of reliability as other Java features. In that sense, you can trust Java, unlike many other technologies on the market.

If you want to know which computer language you should learn as your first or next language, try Java. I believe Java will be with us for a long time.

I bet there are plenty of good arguments for Java’s longevity that are missing from this article, and feel free to share them in the comments.

Phase to select

  1. Java 8 Stream goes from beginner to advanced — playing with collections like SQL
  2. How many new Java8-15 features do you know?
  3. From the star of open source entrepreneurship to bomb building, finally delete library run away, what has he experienced?
  4. 11 Java Code Performance Optimization tips to Learn
  5. Alibaba’s Java development manual (Huangshan version) came

I’m Yi Jun, a semi-amateur coder who likes reading, photographing and writing, follow my public account “Savage Garden”, let’s have fun!