Java Updates Q&A (Need to know about Java Q&A Article Series 8)

Hi Java people.

I am Huseyin. Have been a .Net developer for years and Java backend and Android developer for 6 years as well as a QA Automation Engineer team member for several projects for 3 years.

Have been getting a reasonable amount of questions from any level of Java developers for years. In the end, decided to write my own answers instead of spending my time over the same thing again and again. As a developer, by experiencing the reusability, abstraction and the maintainability issues for years, I decided to implement the same structure in my life and abstract myself from answering similar questions 🙂. Thus, put my effort into creating this “Need to know about Java Q&A Article Series”. By doing so, I am comfortable about answering similar questions by just sending a link to these articles 🙂. It helped me to understand many very important concepts of Java as well.

The target audience of “Need to know about Java Q&A Article Series” is the ones who already know coding with Java, but also want to improve his/her knowledge or to prepare for Java Interviews. If you are a new bee, I believe these articles may be a couple of levels higher for you.

Main purpose of these articles is not to explain topics in detail. Of course there are a lot of sources about Java on the internet. What I experienced is that some different approaches while explaining the same thing helps people to understand the topics. What I am trying to do is actually that. A different kind of explanation.

Articles are prepared by Question & Answer structure which I do believe is an efficient way of learning.

If these articles help you to understand a concept, I definitely feel very happy. Feel free to share and comment.

Sharing is learning at the same time! Enjoy.

Explain the release cycle of Java versions

First of all, there are a couple of implementations of the same Java specification. Most popular ones are; OpenJDK and Oracle JDK. Both OpenJDK and Oracle JDK are created and maintained by Oracle. OpenJDK is a free and open-source implementation of the Java SE Platform Edition, while Oracle JDK was licensed under the Oracle Binary Code License Agreement.

Oracle JDK delivers releases every three years, while OpenJDK releases every six months.

Oracle JDK provides long term support for its releases. On the other hand, OpenJDK only supports the changes to a release until the next version is released.

So OpenJDK, compared to Oracle JDK, delivers releases more often.

In the past, Java release cycles were much longer, up to 3–5 years.

As of September 2022, Java 19 is the latest released Java version. In March 2023, Java 20 will follow. The last long-term support version (LTS) of Java is Java 17, released in September 2021. Open JDK 8, 11 and 17 are the last three LTS versions of Java.

AdoptOpenJDK, Amazon Corretto and Azul Zulu are other open-source popular JDK implementations.

What is Modularity in Java?

Modularity is a general concept which applies to the development of software in a fashion which allows individual modules to be developed. This technique focuses on separating the program functionality into independent, interchangeable modules.

A module is more like an independent partition of software that is communicated through an interface. Modularity explores the creation of a program by using different modules than a single legacy architecture.

Java 9 introduces a new level of abstraction above packages; Modules.

Advantages of Modularity in Java;

  • More readable and independently testable code,
  • Enhanced reusability,
  • Development time reduction,
  • Provides parallel development,
  • Update risks lowered,
  • Code-fix enhanced.

Modularity is useful as a general concept to break down an application into different parts, which can then be tested (and evolved) separately.

How can we create a module in Java?

A module descriptor is the compiled version of a module declaration that’s defined in a file named module-info.java which is added to the module’s root folder. Each module declaration begins with the keyword module, followed by a unique module name and a module body enclosed in braces:

Here’s how to set up the project structure dialog from within IntelliJ:

Right click on the project root and select New>Modules, then specify the SDK, and name the module (general naming convention is reverse-domain-name like net.kicchi.core).

Each module has it’s own main and test folder as well as it’s own pom.xml file (if it is a maven project). Recall that modularity simplifies testing by segregation.

What features can interfaces have In Java 9 and later versions?

Interfaces in Java 1.0 include only two types of items — constants and public abstract methods.

Java 1.1 introduced the concept that Interfaces can contain other interfaces and classes.

With Java 5 Enum and Annotation declarations allowed in interfaces, and generic interface declarations introduced.

Java 8 introduced default and static methods in interfaces.

Java 9 introduced private static/non-static method declarations in interfaces.

With Java 15, the sealed keyword becomes available for interfaces as well as classes (The sealed keyword is used in conjunction with the “permits” keyword to determine exactly which classes are allowed to implement this interface).

What is the structure of the Switch-Case Expression that came with Java 14?

Regular switch-case usage;

For this usage, you should end your cases with a break statement, otherwise all cases will run, finally the default part will always run.

New switch-case usage;

Notice that the new syntax uses the -> operator instead of the colon we’re used to with switch statements. Multiple cases are merged with commas. Also, there’s no break keyword: The switch expression doesn’t fall through cases. Moreover, we are able to assign the returning value to a variable.

What is “Records”?

Record is introduced in Java 14 to reduce boilerplate code and improve the reliability of immutable classes. Immutable classes means that the classes whose main purpose is to hold data such as database results, query results, or information from a service that will not be changed in the program flow.

For such immutable classes, instead of writing getters, toString method, equals method, constructors again and again records can be used. Records automatically generates getters, toString method, equals method, hashCode method and all-args constructor. So you do not have to write all of them for immutable classes and you will gain time.

Record declaration is done like that;

Can be used like that;

Pay attention that there are no compiler-generated setter methods.

Record’s power is more understandable when you add a new field. If you have a class instead of a record, you have to update your toString, equals and hashCode implementations when you add a new field. That is something that you can forget. But for records, after adding a new field, all these methods are updated by the compiler.

Thanks for reading. Hope this helps! See you in the next articles.

PS: Really benefited from especially Baeldung and other Java Tutorial Websites, as well as Official Java Documentation.

Dedicated to Dirty Java Rangers

--

--

Software Developer & SDET/QA

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store