Site icon TestingDocs.com

How to rename a class in Eclipse IDE?

Introduction

In this post, we will learn how to rename a class in Eclipse IDE. This is useful when we want to refactor a class name in a Java Project. 

Environment:

Steps to Rename a Class

Launch Eclipse IDE. There are multiple ways to launch the Eclipse IDE.

Select the Java project and the class to be renamed in the Project Explorer.

Right-click the mouse on the class name and choose the following option from the context menu option:

Refactor >> Rename…

This will open a new window called  Rename Compilation Unit.

Alternatively, we can press the keyboard shortcut Alt + Shift + R.

 

Keep the option checked in the checkbox Update references. This option will automatically rename any references of the class in other class files. 

Choose the new name for the Java class. Click on the Next > button.

 

 

Eclipse would show a preview the changes. The original source on the left tab, the refactored source on the right tab. For example, HelloWorld class name was renamed to new HelloWorldDemo

 

 

Click on the Finish button on the Rename Compilation Unit screen.

Eclipse would rename the class name with the updated new name. That’s it. We have successfully renamed a java class in Eclipse IDE.

Java Tutorials

Java Tutorial on this website:

https://www.testingdocs.com/java-tutorial/

More information on Java can be found on the official website:

https://www.oracle.com/in/java/

Exit mobile version