Formatting a JAVA Document in VSCode requires one to follow the below steps:

  1. Install the plugin: Language Support for Java(TM) by Red Hat from the Extensions window in VSCode.

    • You can open the Extensions window from the left aligned sidebar or simply by pressing Ctrl + Shift + X
  2. Post Installation, from the required page with JAVA code

    • Right Click and choose Format Document With..
    • In the command pallette that opens up on top, select Language Support for Java(TM) by Red Hat option

The Java Document should be now properly formatted.

PS: Trying Alt+Shift+F may not work for users who have set their default formatter as Prettier - Code formatter or alike. By default, java formatting is not supported by it.
If Language Support for Java(TM) by Red Hat is the only formatter plugin installed, then Alt+Shift+F might work for you.

If you wish to bind Alt+Shift+F to format your JAVA Document,
then you can add the below configuration to your settings.json by:

  1. Pressing Ctrl+, to open your Settings
  2. From Top Right Corner, select Open Settings(JSON) either for User or Workspace settings.
  3. Append the below JSON property to it and save:
    "[java]": {
        "editor.defaultFormatter": "redhat.java",
      },
Answer from RICHARD ABRAHAM on Stack Overflow
🌐
Visual Studio Code
code.visualstudio.com › docs › java › java-linting
Java formatting and linting
November 3, 2021 - You can export an Eclipse formatter file and then use it for your project in VS Code. In addition, there are also the Checkstyle for Java and SonarLint extensions, which provide features for live linting and code analysis.
Top answer
1 of 3
40

Formatting a JAVA Document in VSCode requires one to follow the below steps:

  1. Install the plugin: Language Support for Java(TM) by Red Hat from the Extensions window in VSCode.

    • You can open the Extensions window from the left aligned sidebar or simply by pressing Ctrl + Shift + X
  2. Post Installation, from the required page with JAVA code

    • Right Click and choose Format Document With..
    • In the command pallette that opens up on top, select Language Support for Java(TM) by Red Hat option

The Java Document should be now properly formatted.

PS: Trying Alt+Shift+F may not work for users who have set their default formatter as Prettier - Code formatter or alike. By default, java formatting is not supported by it.
If Language Support for Java(TM) by Red Hat is the only formatter plugin installed, then Alt+Shift+F might work for you.

If you wish to bind Alt+Shift+F to format your JAVA Document,
then you can add the below configuration to your settings.json by:

  1. Pressing Ctrl+, to open your Settings
  2. From Top Right Corner, select Open Settings(JSON) either for User or Workspace settings.
  3. Append the below JSON property to it and save:
    "[java]": {
        "editor.defaultFormatter": "redhat.java",
      },
2 of 3
8

For proper formatting, you need to install a VSCode extension that provides Java formatting. Try this one from Redhat: https://marketplace.visualstudio.com/items?itemName=redhat.java

After the extension is installed, that standard code format commands / shotcuts should work for Java code.

Discussions

IntelliJ vs VSCode Java formatter differences are driving me nuts
You all should use the same cli formatter that can be triggered from the IDE, an example would be Prettier with Java plugin. More on reddit.com
🌐 r/vscode
6
16
September 24, 2025
Java Formatter not working properly
Check your settings.json for some formatted settings. You can try to clean the Java language server workspace settings or reinstall vscode. More on reddit.com
🌐 r/vscode
2
2
January 15, 2023
There is no formatter for 'java' files installed
Hi, I have imported an Eclipse format XML file to vscode follow your instruction in here https://github.com/redhat-developer/vscode-java/wiki/Formatter-settings But it didn't work. Before that, it ... More on github.com
🌐 github.com
4
June 19, 2020
visual studio code - Preserving line breaks in VSCode Java formatter - Stack Overflow
I am currently using Java in Visual Studio Code, and I am having a problem with formatting. I want to preserve the line breaks I made on purpose even after formatting. BUT VSCode doesn't allows me ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
DEV Community
dev.to › marcushellberg › how-to-configure-vs-code-java-formatting-1p10
How to configure VS Code Java formatting - DEV Community
June 30, 2021 - You can either use a formatter like the Google Java Style Guide (which I did) or export your Eclipse profile through Preferences > Java > Code Style > Formatter. Save the file somewhere convenient where it won't get deleted.
🌐
GitHub
github.com › redhat-developer › vscode-java › wiki › Formatter-settings
Formatter settings · redhat-developer/vscode-java Wiki · GitHub
redhat-developer / vscode-java Public · Notifications · You must be signed in to change notification settings · Fork 542 · Star 2.3k · Jump to bottom · Fred Bricon edited this page · May 1, 2018 · 3 revisions · In order to use the formatter, you need an Eclipse formatter file like https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml.
Author: redhat-developer
🌐
Seth Vargo
sethvargo.com › using-google-java-format-with-vs-code
Using google-java-format with VS Code | Seth Vargo
January 12, 2020 - This post explores how to format Java source files using google-java-format in Visual Studio Code.
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Google Java Format for VS Code - Visual Studio Marketplace
Extension for Visual Studio Code - Visual Studio Code extension to format Java files using google-java-format program to comply with Google Java Style.
🌐
ryo8000
ryo8000.com › set-up-a-java-formatter-in-visual-studio-code
Set Up a Java Formatter in Visual Studio Code | ryo8000
January 7, 2025 - You can obtain the Google Java Style formatter from https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml. You will configure this formatter in the following steps, so there is no need to download the file now. Open the VSCode settings either through the GUI or by editing the settings.json file.
Find elsewhere
🌐
Reddit
reddit.com › r/vscode › intellij vs vscode java formatter differences are driving me nuts
r/vscode on Reddit: IntelliJ vs VSCode Java formatter differences are driving me nuts
September 24, 2025 -

Hey folks,
some of my teammates are using IntelliJ and I really want to stick with VSCode. It’s lighter, I’ve got a nice Vim setup there, it works for pretty much everything, and most importantly it’s smooth with WSL (unlike IntelliJ, which is a dealbreaker for me).

The problem is Java code formatting. Ideally, we’d all use the same formatter so we don’t end up with messy diffs. I’m using the Red Hat Language Support for Java extension in VSCode. I tried exporting the IntelliJ formatting settings (Eclipse XML) and importing them into VSCode, but there are still differences. For example, how annotations in record parameter wrapping get formatted, and a few other spots.

Has anyone dealt with this before? Is there a reliable way to get IntelliJ and VSCode (with Red Hat Java support) to format identically, or am I chasing something impossible? Any advice would be appreciated.

🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Google Java Formatter - Visual Studio Marketplace
Extension for Visual Studio Code - Reformats Java source code to comply with Google Java Style for VS Code
🌐
Baeldung
baeldung.com › home › ide › how to auto-format code in vs code
How To Auto-Format Code in VS Code | Baeldung
December 30, 2025 - VS Code also lets us format code using the right-click context menu. We simply right-click anywhere inside the editor and select Format Document. VS Code immediately formats the entire file based on the active formatting rules:
🌐
Microsoft
devblogs.microsoft.com › dev blogs › microsoft for java developers › java on visual studio code update – may 2021
Java on Visual Studio Code Update – May 2021 - Microsoft for Java Developers
June 16, 2021 - To launch the editor, click Ctrl+Shift+P to open command palette, and then type “java: open java formatter settings with preview” on the palette and run the command.
🌐
Reddit
reddit.com › r/vscode › java formatter not working properly
r/vscode on Reddit: Java Formatter not working properly
January 15, 2023 -

how can i reset my java formatter? I tried uninstalling the prettier extension and reinstalling it. but nothing seems to work. Every time I use the formatter it messes up my code and makes it very hard to read. It wasn't like this before and actually worked. I would appreciate any help. ty!

🌐
Heatware
heatware.net › java › format-code-in-vs-code
Format Java in Visual Studio Code: Step-by-Step Guide
February 11, 2025 - Install formatters like autopep8 or Black from the Extensions Marketplace.
Author: redhat-developer
🌐
Medium
medium.com › @nithinpm09 › how-to-use-intellij-formatter-in-vscode-82d6ff4b0161
How to use IntelliJ formatter in Vscode | by Nithin P M | Medium
May 24, 2023 - From IntelliJ, export the eclipse formatter file (XML) from settings > editor > Code Style > Java. ... In Vscode you can download the extension — Language Support for Java™ by Red Hat which can import settings from XML files.
🌐
openHAB Community
community.openhab.org › development
VSCode java formatter for addons development - Development - openHAB Community
December 2, 2020 - I’m using vscode on osx to edit some addons code. I’ve been trying to get the java formatter to work but I’m having problems. I’ve installed the Java Extension Pack from Microsoft. I downloaded / cloned GitHub - openhab/openhab-addons: Add-ons for openHAB and opened the local directory on my computer with vscode.
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Prettier Java formatter - Visual Studio Marketplace
Extension for Visual Studio Code - Integration of Prettier Java into Visual Studio Code
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
google-java-format - Visual Studio Marketplace
Extension for Visual Studio Code - Yet another simple google-java-format runner
🌐
GitHub
github.com › redhat-developer › vscode-java › issues › 220
Format on save · Issue #220 · redhat-developer/vscode-java
May 22, 2017 - I've been playing around with the "Format Document" command and I was wondering if it would be possible to configure it to format the document whenever I save.
Author: redhat-developer