In 2020, Java marked its 25th anniversary and, despite its age, remains strong and active. Its seven to 10 million developers make it one of the top three languages in use today, according to the TIOBE Index.
To help celebrate Java reaching a quarter-century, Daniel Oh recounted Java's history before he explained How to install Java on a Mac (because its future depends on more people using it). To continue the party, we've compiled the top five things we learned about Java in 2020. Whether you're just starting with the language or experienced and trying to improve your Java development skills, these are things you should know.
Choose the right IDE
If you are new to Java and curious to know more about its possibilities and ecosystem, BlueJ is a good place to begin. Seth Kenlon's Painless Java with BlueJ explores this open source integrated development environment (IDE) for people learning Java (or programming in general). As Seth writes, "BlueJ aims to make Java easy to learn, regardless of whether you're an experienced programmer or still struggling with your first 'hello world.'"
BlueJ has a visual and intuitive environment to help new developers understand advanced concepts like variable scoping, loops, and conditionals. Its purpose is not to be a full IDE like Eclipse and NetBeans but to be a learning tool to speed knowledge of the programming language and its concepts.
If you want to go to the next level with a great open source IDE to write your Java code, I strongly recommend reading Daniel Oh's 5 open source IDE tools for Java to help you decide which IDE is the best for you.
Use external libraries
One of Java's biggest advantages is its extensibility, which enables the Java community to reuse code to create many components and plugins represented in libraries. In Using external libraries in Java, Chris Hermansen explains what an external library is and how to use it in a real-life application.
Chris shares the major benefits of using external libraries and provides full sample code for connecting to a PostgreSQL database. He says:
"… there are a lot of interesting Java libraries created by people who find gaps in the core libraries. For example, Apache Commons 'is an Apache project focused on all aspects of reusable Java components' and provides a collection of some 43 open source libraries (as of this writing) covering a range of capabilities either outside the Java core (such as geometry or statistics) or that enhance or replace capabilities in the Java core (such as math or numbers)."
Creating and using different external libraries is useful in open source projects because it enables you to share the same solution and codebase across multiple applications. Also, using its design patterns can help you create extensible and modular libraries for your applications.
Explore JDK alternatives
In What makes Java open source? Daniel Oh talks about open source alternatives to Oracle's Java Development Kit (JDK). The most popular is OpenJDK for desktop and server-side purposes.
Different runtimes for Java applications are also emerging that aim to increase Java code compatibility with more devices, including mobile and low-end embedded devices (e.g., Raspberry Pi, Beagle Board, etc.). In Open source cross-platform development with TotalCross, I explore TotalCross, one of the open source options to guarantee low footprint and high performance in any device.
TotalCross VM differs from a regular Java Virtual Machine (JVM) implementation because it uses a register-based architecture, which resembles the architecture used by most hardware, where the operands are stored in a structure based on the CPU's registers. This architecture is more complex to code than a stack-based architecture, as the instructions must address the operands directly instead of just popping the last operand from the stack, but it can guarantee more performance to execute operations.
Which should you use? I write:
"TotalCross VM and Java VMs have different approaches. Not only their bytecodes and architecture differ; they also have different uses. While TotalCross is geared toward applications on the edge, Java's best uses are in things like web applications, server-side applications, and middleware. To decide whether to use a 'pure' Java application or a TotalCross application, look at the requirements of your application and target devices."
Stop with loops; try Java Streams
If you want to level up your programming skills and reduce code and complexity in your applications, take a look at these two Java APIs: Streams API and functional programming constructs.
As Marty Kalin writes in Data streaming and functional programming in Java, "The stream API is a concise and high-level way to iterate over the elements in a data sequence. The packages java.util.stream and java.util.function house the new libraries for the stream API and related functional programming constructs." This is a detailed article about code simplification using these two APIs.
Chris Hermansen wrote two articles about using the Streams API to leverage Streams and Collectors to reduce loops in your code. In Don't like loops? Try Java Streams and Why use Java Streams instead of loops, he applies these APIs to complex problems to clarify the approach's application and benefits.
Using the Streams API and functional programming constructs can improve your source code's maintainability and increase your algorithm's overall performance with features like automatic multithreading and others provided by JDK.
Consider Kotlin instead of Java
It's well-known that you can run different programming languages, including Groovy, Scala, and Kotlin, on top of the JVM—but what is the real benefit of choosing one of them instead of Java?
Stephon Brown provides a great overview of the Kotlin language in Why I switched from Java to Kotlin. He goes through Kotlin basics, like variables and arrays, and offers a clear path about deciding which one to use for your applications.
He says, "Kotlin is an advanced—but intuitive—[object-oriented programming] language that simplifies and streamlines Java development for mobile devices, server-side, web, and data science applications. I find its syntax and configuration much simpler than Java's."
Also, learning to code with a new programming language adds a lot of value to your development skills because it helps you solve problems using the best aspects of each technology. As Stephon writes, "Kotlin's simplicity and Java interoperability equate to little risk that you will spend time learning something that isn't useful. After taking your first steps into Kotlin, you may never look at your Java code or the JVM the same way again."
Other Java news
2020 provided a lot of new updates, features, and possibilities for the Java community. These five topics don't convey all the great things that happened, such as the release of JDK 14 and 15. We shouldn't expect any less in 2021, with the announcement of JDK 16.
For newcomers, this means Java is still one of the best programming languages to learn. It's fully updated with the most modern paradigms and features available for software development. For Java experts, these advances mean there are now more possibilities to leverage their skills in open source projects.
Now it's your turn: What was the best thing you learn about Java in 2020?