Junior — Middle
Which version of Java do you prefer to use when developing a new microservice?
sobes.tech AI
Answer from AI
When developing a new microservice, it is preferable to use the current stable version of Java that is supported by your stack and infrastructure. As of 2024, this is usually Java 17 or Java 20, as they offer performance improvements, new language features, and long-term support (LTS for Java 17). For example, Java 17 is an LTS version, which is important for stability and support in production.
Using an LTS version is preferred for microservices to minimize risks associated with updates and compatibility. If the project requires the latest language features, newer versions can be considered with caution.
An example of using new features in Java 17:
// Using pattern matching for instanceof
Object obj = "Hello";
if (obj instanceof String s) {
System.out.println(s.toUpperCase());
}