Skip to content

Java formatting preferences

Shivam Madan edited this page Mar 16, 2026 · 5 revisions

Using jdk.format.options

The following formatting options can be specified as key-value pairs in the jdk.format.options settings object.

Tabs and Idents

Key Description Type
tab-size Number of spaces to draw when the '\t' character is found in the text; the drawing-engine computes the next multiple of tab-size and continues drawing from that position. integer
expand-tabs Whether to expand typed tabs to spaces; number of spaces substituted per typed tab is determined by spaces-per-tab. boolean
spaces-per-tab How many spaces to substitute per one typed tab; effective only when expand-tabs is true; does not influence how existing tabs are displayed. integer
indent-shift-width How many spaces the formatter should use to indent the inner level of code; independent of tab-size and spaces-per-tab. integer
absoluteLabelIndent Absolute Label Indentation integer
indentCasesFromSwitch Indent Case Statements In Switch boolean
indentCasesFromSwitch Tabs and Indents boolean
indentTopLevelClassMembers Indent Top Level Class Members boolean

Alignment

Key Description Type
alignMultilineAnnotationArgs Annotation Arguments boolean
alignMultilineArrayInit Array Initializer boolean
alignMultilineAssignment Assignment boolean
alignMultilineBinaryOp Binary Operators boolean
alignMultilineCallArgs Method Call Arguments boolean
alignMultilineDisjunctiveCatchTypes Disjunctive Catch Types boolean
alignMultilineExports Exports boolean
alignMultilineFor For boolean
alignMultilineImplements Implements List boolean
alignMultilineLambdaParams Lambda Parameters boolean
alignMultilineMethodParams Method Parameters boolean
alignMultilineOpens Opens boolean
alignMultilineOpens Alignment boolean
alignMultilineParenthesized Parenthesized boolean
alignMultilineProvides Provides boolean
alignMultilineTernaryOp Ternary Operators boolean
alignMultilineThrows Throws List boolean
alignMultilineTryResources Try Resources boolean

Inserting New Lines

Key Description Type
placeCatchOnNewLine "catch" boolean
placeElseOnNewLine "else" boolean
placeFinallyOnNewLine "finally" boolean
placeNewLineAfterModifiers After modifiers boolean
placeWhileOnNewLine "while" boolean

Java Language Specific

Key Description Type
blankLinesBeforeEnumClosingBrace Blank Lines integer
parensAroundSingularLambdaParam Braces boolean
specialElseIf Special "else if" Treatment boolean
addOverrideAnnotation Add Override Annotation boolean
keepGettersAndSettersTogether Keep Getters And Setters Together boolean
makeLocalVarsFinal Make Generated Local variables Final boolean
makeParametersFinal Make Generated Parameters Final boolean
qualifyFieldAccess Qualify Field Access boolean
sortMembersByVisibility Sort Members By Visibility boolean
sortMembersInGroups Sort Members in Groups Alphabetically boolean
sortUsesDependencies Ordering boolean
localVarNamePrefix Naming string

Java Doc

Key Description Type
addLeadingStarInComment Add Leading Star boolean
alignJavadocExceptionDescriptions Align Exception Descriptions boolean
alignJavadocExceptionDescriptions Comments boolean
alignJavadocParameterDescriptions Align Parameter Descriptions boolean
alignJavadocReturnDescription Align Return Value Descriptions boolean
blankLineAfterJavadocDescription Add Blank Line After Description boolean
blankLineAfterJavadocParameterDescriptions Add Blank Line After Parameter Descriptions boolean
blankLineAfterJavadocReturnTag Add Blank Line After Return Tag boolean
enableBlockCommentFormatting Format Block Comments boolean
enableCommentFormatting Enable Comments Formatting boolean
generateParagraphTagOnBlankLines Generate "

" On Blank Lines

boolean
preserveNewLinesInComments Preserve New Lines boolean
wrapCommentText Wrap Text At Right Margin boolean
wrapOneLineComment Wrap One Line Comments boolean

Imports

Key Description Type
allowConvertToStarImport Allow Conversion To Star Import boolean
allowConvertToStaticStarImport Allow Conversion To Static Star Import boolean
importInnerClasses Import Inner Classes boolean
preferStaticImports Prefer Static Imports boolean
separateImportGroups Imports boolean
separateImportGroups Separate Groups boolean
separateStaticImports Separate Static Imports boolean
useFQNs Use Fully Qualified Names boolean
usePackageImport Use Package Imports boolean
useSingleClassImport Use Single Class Imports boolean

Line Wrapping

Key Description Type
wrapAfterAssignOps Wrap After Assignment Operators boolean
wrapAfterBinaryOps Wrap After Binary Operators boolean
wrapAfterDisjunctiveCatchBar Wrap After Bar in Disjunctive Catches boolean
wrapAfterDotInChainedMethodCalls Wrap After Dot In Chained Method Call boolean
wrapAfterLambdaArrow Wrap After Lambda Arrow boolean
wrapAfterTernaryOps Wrap After Ternary Operators boolean
wrapProvidesWithList Wrapping boolean

Examples

In settings.json add the following setting to specify:

"jdk.format.options": {
    "indent-shift-width": 2,            // set indent-shift-width to 2
     "allowConvertToStarImport": true,  // enable converting to `*` imports
     "enableCommentFormatting": true    // enable formatting in comments
}

Using jdk.format.settingsPath (Deprecated)

Note: The steps below are associated with using the jdk.format.settingsPath setting. This is deprecated now, in favour of using the jdk.format.options setting described above.

Follow the steps given below to setup the custom formatter preferences:

  1. Install NetBeans.
  2. Configure your Java formatting preferences in NetBeans:
    Menu: Apache Netbeans | Settings... | Editor | Formatting
    In the "Language" drop-down: Choose "Java"
  3. Press "Export" button (lower left corner)
  4. Check the "Editor" and "Formatting" checkboxes.
image
  1. Export the options as a .zip file, e.g. "MyNetBeansJavaFormatting.zip"
  2. Set the jdk.format.settingsPath setting in VS Code:
    In VS Code, open the "Command Palette" (Ctrl+Shift+P)
    Type "Preferences: Open User Settings (JSON)"
    Set the following property:
    "jdk.format.settingsPath": "PATH_TO_EXPORTED_NETBEANS_FORMAT_PREFERENCES_ZIP"
  3. You might also need to make sure that "Editor: Default Formatter" is set to "null" in your VS Code Settings (Ctrl+,).

Your custom Java formatting preferences should now be honoured by the "Oracle Java" extension in VS Code.

While it may not be the perfect solution, performing this task should be a one-time requirement, unless you find yourself regularly adjusting your formatter settings.

Clone this wiki locally