Use the Code Formatting Preferences page (Window > Preferences > Java > Code Formatter) to specify your preferences for code formatting.
Open a Java file and select the code you want to format. If nothing is selected, then all of the editor content is formatted.
Format the code by either
Java development tools (JDT)
Java editor
Using the Java editor
Formatting Java code
Setting code formatting preferences