How do you change a variable name in Java?

How to Rename Variables in Eclipse (Java)


wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 9 people, some anonymous, worked to edit and improve it over time. This article has been viewed 131,185 times.Learn more...

If you've ever tried to alter a variable's name manually, you'll know that it's a tedious process. In order for the program to compile, all occurrences of the variable must be found and changed to the new name. However, Eclipse makes this task extremely easy by providing a re-factoring tool that automatically finds and updates variable names. The build used here is Eclipse Ganymede 3.4.0.


  • 1Navigate toHighlight and right click on the variableyou want to rename.Refactorand selectRename....
  • 2Type in your new variable nameand pressEnter.Advertisement
  • 3Verify that occurrences of the variable are updating as you type.
  • 4Check through the source code to ensure that no errors have arisen.Advertisement

Community Q&A

Ask a Question

200 characters left

Include your email address to get a message when this question is answered.




  • The hotkey for Rename isAlt+⇧ Shift+Rand is much faster than navigating through the menu.
  • If you are on a mac, the hotkey isAlt+⌘ Cmd+R.

Submit a Tip

All tip submissions are carefully reviewed before being published

Thanks for submitting a tip for review!



  • If there are any syntax errors near occurrences of your variable, those occurrences may not re-factor correctly since Eclipse will not know how to handle the errors. Always check problematic areas after refactoring.


About This Article

In other languages

Thanks to all authors for creating a page that has been read 131,185 times.

Source: Wikihow

Related Articles