Search code examples
javanetbeansjava-8java-5

How to migrate Java code to a more recent jdk (e.g. 1.8)


What is the best way to migrate Java code of an older jdk (1.5) to a more recent Java version (1.8) to provide from its new features and improvements. We have a large Java jdk 5 code base and want to migrate to jdk 8.

There are a lot of compiler warnings and hints (e.g. diamond operator, multicatch, unnecessary (un)boxing, etc) which will improve the performance, code readability, etc.

We are using Netbeans IDE. Are there any plugins which we can use or are there migration scripts?


Solution

  • Found what I was looking for: Netbeans offers Inspect and Transform.

    This can be used to transform your complete code base (or parts of it) with a configuration of changes.

    This is how it works:

    1. select your project
    2. click Refactor menu
    3. click Inspect and Transform menu item
    4. select configuration and configure it using the Manage button
    5. choose your desired transformations (e.g. Can Use Diamond, Join catch sections using multicatch, unnecessary boxing, etc.)
    6. click Inspect
    7. Review proposed refactoring suggestions and click Do Refactoring

    Your complete code base is refactored and uses your selected new features and new idioms.

    IntelliJ IDEA has a similar feature. See Analyze > Inspect Code ...

    In Eclipse this is called clean up in code style (configuration) or source (menu).