DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Trending

  • After 9 Years, Microsoft Fulfills This Windows Feature Request
  • From Hype to Harm: Why AI Governance Needs More Than Good Intentions
  • Domain-Centric Agile Modeling for Legacy Insurance Systems
  • Yet Another GenAI Nightmare: Seven Shadow AI Pitfalls to Avoid

How to Configure VS Code for Java

Take a step-by-step look at the extensions and configurations that I use with my new favorite highly customizable and fast IDE, Visual Studio Code (VS Code).

By 
Alejandro Duarte user avatar
Alejandro Duarte
DZone Core CORE ·
Apr. 19, 22 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
36.0K Views

Join the DZone community and get the full member experience.

Join For Free

I recently shifted from IntelliJ IDEA Ultimate to Visual Studio Code (VS Code) and I have no regrets! VS Code is highly customizable and fast. It stores your settings in the cloud so you don’t have to worry about configurations when you move to a different machine.

As expected, it has support for Java, Git, SQL, Spring Boot, and many other languages, frameworks, and tools.

In this article, I’ll show you the extensions and configurations that I use with my new favorite IDE.

Java Extension Pack

VS Code has tons of extensions that add support for programming languages, frameworks, and tools. An extension pack groups related extensions that work well together. The first thing to do is install the Java Extension Pack:

Spring Boot, Microprofile, and Quarkus Extensions

There are extensions for Spring Boot, Microprofile, and Quarkus if you are using any of these frameworks. These extensions make it easy to create new projects, deploy and run applications, as well as configure them.

Creating a New Java Project

To create a new Java project, in the Explorer tab on the sidebar, click Create Java Project:

You can select from a variety of frameworks depending on the extensions you installed. Here are some of the ones that I see in my IDE:

Each option will prompt further information to generate the new project.

Importing a Project

The Java Extension Pack includes the Maven for Java extension (there’s a Gradle extension as well). VS Code recognizes Maven projects when you open a directory with a pom.xml file in it. Simply go to File | Open… in the menu and select the directory that contains the pom.xml file.

Code Command

Although you don’t have to, you can also use the command line to open projects. VS Code makes it extremely easy to enable this. Press F1 and type shell to include the code command in your PATH environment variable:

After this, make sure to restart the terminal (if you have any opened), and type code to launch VS Code. You can specify a directory to open.

To open the current directory, specify a dot:

code .

Running an Application

Once you have a new or an existing project opened in VS Code, you can run it by pressing F5. Select Java and the class that contains the standard Java entry point main method that you want to run:

Select environment

Database Client

Most applications connect to databases like MariaDB, MySQL, PostgreSQL, MongoDB, etc. The best extension for this is Database Client. You can try it out with SkySQL for example. Make sure to enable the Use SSL option, download the CA file from SkySQL, and specify the path to the file in the Client Cert field in VS Code. After that, you can run SQL queries without having to leave your IDE. Check this video:

Git

VS Code includes Git support out-of-the-box. However, I suggest installing the GitLens extension to add useful views to the Source Control sidebar panel:

Install GitLens extension

In my case, I disabled the current line blame annotations since I find it a bit intrusive, but try it out and decide for yourself.

Keyboard Shortcuts

If there’s one shortcut you should learn, that is the sequence Ctrl K, Ctrl S (or Cmd K, Cmd S). It shows all the keyboard shortcuts with the option to search and edit the key combinations as you wish.

Here are a few keyboard shortcuts that I use frequently:

  • Ctrl B/Cmd B: Toggle sidebar
  • Ctrl Shift E/Cmd Shift E: Show/focus explorer
  • Ctrl J/Cmd J: Toggle panel (terminal, output, debug console, etc.)
  • Ctrl `/Ctrl Shift `: Toggle terminal
  • F5: Run the application
  • Ctrl ;/Cmd ; : Settings
  • Ctrl Shift P/Cmd Shift P/F1: Show all available commands
  • Ctrl P/Cmd P: Open a project file
  • Ctrl Shift O/Cmd Shift O: Outline (to show for example class members)

I recommend going through the Get Started guide inside VS Code (available in the Help menu) especially the Learn the Fundamentals walkthrough which teaches you how to edit code with a bunch of shortcuts that will improve your productivity.

Presentation Mode

If you are presenting your code to an audience, it’s always useful to increase the font size of the code. Most IDEs allow you to do this, but the size of all other things in the UI remains the same, which is not ideal in my opinion. VS Code is the best at this since you can simply hit Ctrl + (or Cmd + on macOS) and the whole UI is zoomed in, just like in a web browser. Use Ctrl - (or Cmd - on macOS) to zoom out.

You might want to go full screen (F1 and search for Toggle Full Screen) or even better activate the Zen mode (F1 and Toggle Zen Mode). I do this in presentations and videos like this:

Other Resources

Like almost always, the official documentation is the best source of knowledge. It includes resources for multiple programming languages like JavaScript, TypeScript, Java, Python, and C++. Check the official YouTube channel as well and visit the GitHub repository. VS is open source!

Published at DZone with permission of Alejandro Duarte. See the original article here.

Opinions expressed by DZone contributors are their own.

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!