What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
In Eclipse’s Java tools, select an eligible constant expression and choose Refactor > Extract Constant. Eclipse creates a static final field, replaces the selected expression with a reference to it, and lets you choose whether to replace other occurrences of the same expression.
What Extract Constant does
Eclipse JDT’s Refactor Actions guide describes Extract Constant as a way to turn a constant expression into a static final field. The selected expression is replaced with a reference to that field. You can also choose whether Eclipse rewrites other occurrences of the same expression.
| # | Preview | Product | Price | |
|---|---|---|---|---|
| 1 |
|
Eclipse IDE Pocket Guide: Using the Full-Featured IDE | $7.99 | Buy on Amazon |
| 2 |
|
Eclipse | $25.96 | Buy on Amazon |
| 3 |
|
Eclipse IDE - kurz & gut | $6.53 | Buy on Amazon |
| 4 |
|
Eclipse IDE - kurz & gut | $6.53 | Buy on Amazon |
| 5 |
|
Contributing to the Eclipse IDE Project: Principles, Plug-ins and Gerrit Code Review (vogella... | $24.99 | Buy on Amazon |
The command is for Java tooling in Eclipse. Its documented eligibility requirement is a constant expression, or a text selection that resolves to one. String and numeric literals are common examples when Eclipse recognizes the selected code as constant; not every expression involving a string or number qualifies.
Extract a constant in the Java editor
- Open the Java source file and select the eligible expression you want to name.
- Choose Refactor > Extract Constant. Eclipse also makes refactoring commands available through context menus in the Java editor and other views.
- Alternatively, invoke the available quick assist on the eligible expression and choose Extract Constant.
- Review the proposed field and replacement options in the refactoring controls. In particular, decide whether Eclipse should replace other occurrences of the same expression.
- Apply the refactoring, using the preview if you want to inspect the proposed changes first.
Eclipse determines the resulting field details from the selected code and the refactoring options. Check the proposed name, visibility, and destination rather than assuming a particular field name or location.
#1 Best Overall
Preview and review the proposed changes
Eclipse’s Refactoring Support documentation explains that you can preview proposed changes. The preview reports potential problems and lists the changes the refactoring will make. Use it to inspect the field creation and each replacement before applying the operation. A preview is a review aid, not a guarantee that every refactoring preserves behavior in every circumstance; check that the resulting code suits your intent.
When the command is unavailable
- The selection is not eligible: select a constant expression, or adjust the text selection so it resolves to one. A larger expression that depends on variables or other non-constant values may not qualify.
- You are not in Java tooling: Extract Constant is an Eclipse JDT Java refactoring, not a general-purpose extraction command for every language supported by Eclipse.
- You want to limit replacements: review the option for other occurrences before applying; rewriting them is optional.
For API and automation users
The JDT API identifies this refactoring as org.eclipse.jdt.ui.extract.constant. That identifier is mainly useful when working with Eclipse’s Java refactoring API or automation; IDE users can use the editor command or quick assist instead. Eclipse also documents workspace history and scripts that can replay recorded refactoring operations in its refactoring overview.
Quick Recap
Best Value
Rank #4
Rank #3
Rank #2
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

