#15 Java in Containers
The role of preview features. Reading, Writing, and Creating Files. Authoring Gradle plugins. The S.O.L.I.D Principles in Pictures.
Welcome to the fifteenth Dukesletter edition!
Java in Containers
Containers have become a standard, and we must deploy our applications as Docker containers.
If we want to do real DevOps, developers must take ownership of how our applications are deployed. Now our deliverable is not the FatJAR or WAR, it is the docker image.
In the following video, David Delabassee explains different points related to deploying JVM applications in Containers: which type of base image to use, which type of JRE use, security, available resource, etc.
You can also read the transcript in InfoQ.
The role of preview features
The best decision that Oracle/OpenJDK Team has taken in recent years has been to change to a 6-monthly release cadence.
Instead of release a new version once every 3 years, release a new stable version every 6 months, and create a Long Term Support version once every 3 years.
If your business allows it, you can enjoy the latest stable features and try preview features without waiting for 3 years. Some people get stressed, but everyone gets happy.
To explain how the JDK Team manages different feature status David Delabassee has written a very interesting article: The role of preview features in Java 14, Java 15, Java 16, and beyond. How Oracle gathers feedback on new JDK functionality with preview, experimental, and incubating features.
Using the correct communication channels you can give feedback about new features, and as any Open Source project, contribute with bug reporting or even code.
Sometimes new developments are too experimental and are implemented in isolated branches, but are available in the early access sites.
This mail from the OpenJDK mailing list gives us more information about how Preview APIs are developed. The whole thread is very interesting.
Reading, Writing, and Creating Files
Every time I must write code that read a binary or text file I must google which are the needed classes: FileInputStream, InputStream, Reader, BufferedReader, etc..
But probably all you need to work with files and I/O is in this guide from Java SE documentation: “Basic I/O”. Specifically for files in the chapter “Reading, Writing, and Creating Files”.
Even though Java NIO 2 was introduced in JDK 7, 99% of times I use File class instead of Path. But I think most of our problems would be solved just by using the method Files.readString(Path path)
introduced in JDK 11 😅.
Authoring Gradle plugins
Sometimes our projects become complex, and their build infrastructure with Gradle becomes a collection of copy & pasted snippets of code, replicated throughout different modules.
In the following video, Cédric Champeau explains how to author Gradle plugins for readability, maintainability, and user experience.
Just like you DRY when you write your code, there are good engineering practices that you MUST follow with Gradle. This leads to faster, more maintainable builds.
The S.O.L.I.D Principles in Pictures
Everyone knows SOLID, and has read Clean Code by Robert C. Martin. Everyone understands when to apply each concept, but we don't.
There are so many great articles online about SOLID but I rarely see any examples with pictures. This makes it a bit difficult for visual learners like me to learn while staying engaged.
To solve this Ugonna Thelma has created in ”The S.O.L.I.D Principles in Pictures” some illustrations emphasizing the goal for each principle.
Next time you have a conversation with a co-worker you can use these illustrations to understand and discuss these concepts.