Beginning Java 9 migration

You probably have some Java 8 (or earlier) code on your hands. And you are probably wondering what you'll need to do to get this to work with Java 9. When the Java 9 specification was going through the Java Community Process (JCP), there was some concerns in the developer community about just this. Will the legacy Java code work as-is in Java 9? If there are changes to be made, how much time and effort would they consume? Fortunately, Java has a great track record of maintaining backward compatibility, and that continues even with such major changes that have been brought into the language with the new modularity features. However, since Java 9 is one of the biggest overhauls to the Java internals, there might be some work that needs to be done. The amount of work depends primarily on two factors--the nature of migration you are trying to perform and the way the code itself is written.

Now what do I mean by nature of migration? When tackling Java 9 migration, it's useful to think about the effort in stages. At a high level, you could move your existing pre-Java 9 code through the following two stages:

  1. Getting your code to compile and execute in Java 9 as-is.
  2. Refactoring the structure of your code to use the modularity features.

Step 1 involves using the javac and the java commands on your existing code base just like you have done all along, but with the new Java 9 version of the compiler and runtime. In this phase you'd like to make as little changes to the code as possible! Step 2 involves refactoring or rewriting your code to use modularity features, including the things we've learned so far in this book--breaking down the code base into modular units, creating module-info.java for each of those modules and then establishing relationships between the modules.

Are both these steps necessary for migrating to Java 9? Well, Step 1 is. For any application that you plan to run and use in the foreseeable future, it's worth getting it to at least work with the new Java 9 runtime. That way, you are ready for whenever Java 8 becomes end-of-lifed in the future. This type of migration should be relatively easy, except for a few things to look out for that we'll cover in this chapter.

After you've done that, and your applications now work with Java 9 compiler and runtime, you do have an option of refactoring your code to use all the cool new modular features you've learned. But that may not always be valuable. If you have code that you don't plan to modify or enhance over time, and you just need to maintain it to run the business, you aren't going to get a lot of value by refactoring it to use Java 9 modules.

However, if you anticipate making changes and actively working on the code base, there is benefit to refactoring the code to use modules. The next chapter deals with migrating code that involves using the rich JPMS features we now get with Java 9.

We'll be covering Step 1 in this chapter. Step 2 is covered in Chapter 11, Migrating Your Code to Java 9.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.182.159