Visual Studio Code setup for Java and Spring with GitHub Copilot

Introduction-

In this tutorial blog, we will explore the process of setting up and utilising Visual Studio Code for Java programming, as well as incorporating GitHub Copilot as a valuable coding tool. Visual Studio Code is a powerful and versatile code editor that offers a wide range of features and extensions for Java developers. By using Visual Studio Code for Java programming, developers can benefit from features such as code completion, debugging, and live coding.
Additionally, with the integration of GitHub Copilot, developers can streamline their coding process with AI-assisted suggestions for code snippets and functions. This blog will provide a comprehensive guide for setting up and using these tools for Java development.

Setup Visual Studio Code for Java and Spring

Visual Studio Code (VS Code) is an open-source code editor that supports a wide range of programming languages, including Java. It is a powerful tool for developing Java applications, offering an intuitive interface, customisable features, and an extensive library of extensions. In the below steps, we will guide you through the process of downloading and setting up VS Code for Java and SpringBoot development.

Step 1: Download and Install Visual Studio Code

The first step is to download and install VS Code on your computer. To do so, follow these steps:

1. Go to the official VS Code website (Link to website) and click the Download button.

2. Choose the version of VS Code that is compatible with your operating system and download the installer.

3. Once the download is complete, run the installer and follow the instructions to complete the installation process.

Step 2: Install Java Extension Pack

After installing VS Code, you need to install the Java Extension Pack to enable Java development features. To do so, follow these steps:

1. Open VS Code and click on the Extensions icon in the left-hand menu bar.

2. In the search bar, type "Java Extension Pack" and press Enter.

3. Click on the "Install" button next to the Java Extension Pack option.

You can see after installation is done, it can view in the INSTALLED section. Once the installation is complete, you will need to reload VS Code to activate the extension.

Step 3: Install Spring Boot Extension Pack

The Java Extension Pack provides a broad range of tools and features for Java development, while the Spring Boot Extension Pack provides a more focused set of tools and features for Spring Boot development. Developers who work with Spring Boot may find the Spring Boot Extension Pack to be more useful, while developers who work with Java more generally may find the Java Extension Pack to be more useful.

In addition to the Java Extension Pack, you can install the Spring Boot Extension Pack to enable Spring Boot development features. You can enable and disable any extension as per your requirements.

To Spring Boot Extension Pack, follow these steps:

1. Open VS Code and click on the Extensions icon in the left-hand menu bar.

2. In the search bar, type "Spring Boot Extension Pack" and press Enter.


3. Click on the "Install" button next to the Spring Boot Extension Pack option.

4. Once the installation is complete, you will need to reload VS Code to activate the extension.

Step 4: Create a Java Project in VS Code

Now that you have installed the necessary extensions, you can create a Java project in VS Code. To do so, follow these steps:

1. Click on the "Explorer" icon in the left-hand menu bar.

2. You can open a Java project or create a new one by clicking on the button "Create Java Project".


3. You can select a project type or search for your project type. For example, if you want to create a Spring Boot project, then search spring boot and select it from the options.

4. You can choose or, type according to the options it gives like Maven or Gradle,  Group Id, Artifact Id, , packaging (Jar/War), dependencies and other pieces of stuff one by one and press enter for the next options.

You can now start coding and use the features provided by the Java Extension Pack and Spring Boot Extension Pack.

Step 5: Configure the Java Environment

To be able to run and debug your Java code in VS Code, you need to configure the Java environment. To do so, follow these steps:

1. Open the "Command Palette" by pressing "Ctrl+Shift+P" (Windows) or "Cmd+Shift+P" (Mac).

2. Type "Java: Configure Java Runtime" and press Enter.

3. Select the Java runtime that you want to use and click "OK".

4. Restart VS Code for the changes to take effect.

Step 6: Run and Debug the Application

To run and debug your Java and Spring Boot applications in VS Code, follow these steps:

1. Open the "Command Palette" by pressing "Ctrl+Shift+P" (Windows) or "Cmd+Shift+P" (Mac).

2. Type "Run Java" and select the option to run the application.

3. You can also use the "Debug" button in the left-hand menu bar to debug your application.

Setup GitHub Copilot

About GitHub Copilot

GitHub Copilot is an AI-powered coding assistant that streamlines the coding process by providing quick and relevant suggestions for individual code lines or entire functions. By analyzing both code and comments, Copilot utilizes the OpenAI Codex generative language model to offer intelligent programming suggestions. This extension is compatible with various integrated development environments (IDEs), such as Visual Studio Code, Visual Studio, Neovim, and the JetBrains suite. With GitHub Copilot, coding becomes faster and more efficient.

For optimal performance, GitHub Copilot functions best when you break down your code into concise functions, utilise descriptive names for your function parameters, and provide detailed documentation and comments as you code. Additionally, Copilot excels when assisting with unfamiliar libraries or frameworks.

GitHub Copilot is a revolutionary tool that uses machine learning models to provide suggestions for code as you type in your favourite code editor. By integrating Copilot into your Visual Studio Code (VS Code) environment, you can enjoy a more efficient coding experience, as Copilot will offer code snippets, function declarations, and even entire classes that match your needs.

Here’s a step-by-step guide on how to set up GitHub Copilot in Visual Studio Code:

Step 1: Install Visual Studio Code

As explained above first need to download VS Code.  It's available for Windows, macOS, and Linux on their official website (https://code.visualstudio.com/).

Step 2: Install the GitHub Copilot extension

Once you have installed Visual Studio Code, you need to install the GitHub Copilot extension. To do this, open VS Code and click on the "Extensions" icon in the sidebar.

In the search bar, type "GitHub Copilot" and select the extension from the search results. Click on the "Install" button to install the extension.

Step 3: Sign up or Sign in for the GitHub Copilot

Once GitHub Copilot is installed in the VS Code. You need to sign in to your Git Lab account.
(If you have no Git Lab account, it will be good if you first create a git hub account before coming to this step).
To access GitHub Copilot, follow these steps:
1.Go to any page and locate your profile photo in the upper-right corner. Click on it, and select 'Settings' from the menu.
2.Look for the 'Code, planning, and automation' section in the sidebar and click on 'GitHubCopilot'.
3.Once you're on the GitHub Copilot settings page, select 'Enable GitHub Copilot'.
4.Decide whether you want to pay monthly or yearly, then click 'Continue' to gain access to Copilot.If your personal account qualifies for a free GitHub Copilot subscription, you will be directed to step 6 automatically instead of a trial or paid subscription.
5.Confirm your payment details by following the instructions provided and then click 'Submit'.
6.Select your preferences and click "Save and get started" to begin using Copilot.

You can read Official Documentation Guide to know more about above steps.

Step 4: Authorize GitHub for VS Code

Step 5: Start using GitHub Copilot in Visual Studio Code

Now that you have set up GitHub Copilot in Visual Studio Code, you can start using it to improve your coding experience.

To use GitHub Copilot, simply start typing code as you normally would. As you type, GitHub Copilot will offer suggestions for code snippets, function declarations, and even entire classes that match your needs.

How to Cancel Your GitHub Copilot Subscription or Trial

1. Go to your account settings by clicking your profile photo in the upper-right corner of any page and selecting "Settings".
2. In the "Access" section of the sidebar, click "Billing and plans", then click "Plans and usage".
3. Under the "GitHub Copilot" section, select the "Edit" dropdown on the right.
4. If you have a paid subscription, click "Cancel GitHub Copilot". If you are within your 30-day trial period, click "Cancel trial".
5. In the "Cancel GitHub Copilot" modal, click "I understand, cancel GitHub Copilot" if you have a paid subscription. If you are within your 30-day trial period, click "I understand, cancel GitHub Copilot trial".
Please note that if you cancel during your 30-day trial, you won't be charged. However, if you do not cancel your Copilot for Individuals subscription before the end of the trial, you will be charged according to the billing cycle you selected when setting up the trial.
You can read Official Documentation Guide to know more about managing subscriptions for GitHub Copilot.

You can accept the suggestions by pressing the "Tab" key or clicking on the suggestion. Alternatively, you can ignore the suggestion by continuing to type your code.

Hope this blog tutorial has been helpful to you. If you have any remaining doubts or suggestions, please feel free to share them in the comments below. We would be glad to receive your feedback.

💛 You can Click Here to connect with us. We will give our best for you.

Comments

Popular Posts on Code Katha

Java Interview Questions for 10 Years Experience

Sql Interview Questions for 10 Years Experience

Spring Boot Interview Questions for 10 Years Experience

Java interview questions - Must to know concepts

Spring Data JPA

Data Structures & Algorithms Tutorial with Coding Interview Questions

Java interview questions for 5 years experience

Spring AI with Ollama

Elasticsearch Java Spring Boot