Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Developer workflows using the VS Code for Java extension 1.0

October 20, 2021
Mohit Suman Roland Grunberg
Related topics:
Developer ToolsJava
Related products:
Red Hat OpenShift

Share:

    The 1.0 release of Language Support for Java by Red Hat on Visual Studio Code is now available on VS Code Marketplace. We'd like to take the opportunity to showcase a few workflows that really make it enjoyable to develop Java applications in Visual Studio Code (VS Code).

    vscode-java 1.0: The one with Java 17

    The extension's 1.0 release supports workflows with Java 17. Released a few weeks ago, Java 17 marks a major point of change in the Java community as many organizations migrate to the latest Java runtime. Here is a short demo around the workflow using the Java extension and Java 17 support:

    One of the advantages of the vscode-java extension is that all it takes to start coding is a simple Java source file. There's no need for fancy IDE-specific config files or even build files (such as pom.xml or build.gradle) to get a project started.

    Let's take an in-depth tour of the Java extension's new features.

    Configuring your Java project

    First, we'll begin by opening VS Code in a folder with just a few Java source files, as shown in Figure 1.

    A screenshot of the project loaded in VS Code.
    Figure 1. Loading the project in VS Code.

    Note: One point worth repeating is that we support pretty much any Java runtime for which we can detect a compatible JDK.

    As Figure 2 shows, we have configured Java 8, 11, and 17 environments by providing paths to a compatible JDK installation. Although in this example we have set Java 17 as the default for unmanaged projects, you can easily switch to Java 8 by setting it to default: true. Once saved, the configuration will take effect. Maven or Gradle projects will have this configured in their build files; vscode-java can detect and honor those settings.

    An animated graphic showing various Java configuration runtimes.
    Figure 2. Java configuration runtimes.

    With a variety of different code actions, it's very easy to quickly get some boilerplate code. You can generate source headers with java.templates.fileHeader (File → Preferences → Settings), and getters/setters can be auto-generated through code completion. They can also be auto-generated via code actions on the individual fields or class itself, as shown in Figure 3.

    create-class-generate-getset
    Figure 3. Creating the ​​class to auto-generate getters/setters.

    Access references for unnmanaged projects

    Having access to the sources of the libraries you're using is important. While we've always supported this for managed projects (e.g., Maven or Gradle), we now support it for unmanaged projects as well. Simply reference a library from Maven Central, and the sources will be available automatically when interacting with some reference from that library, as shown in Figure 4.

    If you want a little more control over your unmanaged project's dependencies, but don’t want to transition to using some build tool, you can use java.project.referencedLibraries (File → Preferences → Settings). To jump to a particular method definition, you can use the right-click context menu or configure a keyboard shortcut (e.g., the F12 key).

    source-lookup
    Figure 4. Source lookup.

    Search for methods

    It's handy to be able to search for your method declarations the same way you might search for a file, especially when you're dealing with a new project or file structure. Rather than searching for a file that has the method we're interested in, we can search for the method directly. Simply enable java.symbols.includeSourceMethodDeclarations (File → Preferences → Settings).

    Type hierarchy

    The Java extension also now supports type hierarchy. This feature is accessible from the right-click context menu, but you can also easily configure it as a keyboard shortcut, as shown as Figure 5.

    source-method-lookup-type-hierarchy.
    Figure 5. Source method lookup type hierarchy.

    Run and debug

    In order to take advantage of run and debug capabilities, you'll need to install the vscode-java-debug extension from the Visual Studio Code Marketplace.

    The Debugger for Java extension lets you run and debug the project in many different ways. For simple projects, you can enable java.debug.settings.enableRunDebugCodeLens (File → Preferences → Settings), and use CodeLens directly from the main method.

    You can set breakpoints, inspect and modify variable values, and even interact with the program from the Debug Console, as shown in Figure 6.

    run-debug
    Figure 6. Run and debug.

    Future roadmap

    There are many items planned for the Java language support in VS Code. Some of these include:

    • Making it easier to configure compiler error/warnings and code formatting options.
    • Adding useful auto-completion features (such as Postfix completion).
    • Continuing to adopt convenient code actions (new Java language features, for example) and eventually reach feature parity with those provided by the Eclipse Java IDE.
    • Improving the language server's initial startup time and overall performance.
    • Embedding a Java runtime to improve the "Getting Started" experience.

    Testimonials

    "For me, VS Code for Java is the easiest way to get started with a Java project. It doesn't matter if you're starting from scratch or you need to quickly open an existing project—VSCode for Java is blazingly fast and small. It will work fast even on older machines, and it has all the features you need to be productive when developing Java projects, from old versions of Java up to the latest version: 17!"

    —Edson Yanaga, Java Champion and Microsoft MVP, Director of Developer Experience, Red Hat

    "vscode-java makes Visual Studio code a fast and lean way to edit Java projects. I can start and stop the editor on any project, small or large, in no time. This makes it a great tool to use as both my primary and secondary IDE while working on JBang and Quarkus projects."

    —Max Rydahl Andersen, Distinguished Engineer, Red Hat

    "Visual Studio Code and its vscode-java extension have become my go-to solution for a quick and lightweight code exploration and editing experience. Whether it's for examining pull requests, diving into a new code base, or a live demo during a conference talk, vscode-java allows me to work with Java code intuitively and efficiently, providing all the goodies you'd expect from your coding workbench, like code navigation, refactoring support, instant feedback in case of failures, etc. Part of the VSCode extension pack for Java, vscode-java integrates seamlessly with other extensions like the Java debugger and test runner, as well as features like remote development via SSH, making it an invaluable part of my Java toolbox."

    —Gunnar Morling, Java Champion, Principal Software Engineer, Red Hat

    Conclusion

    Check out our Quick Start guide to get started building Java applications using Visual Studio Code. Obviously, 1.0.0 is not the endgame. Development continues, so you can look forward to more goodies—there's a big one coming in the near future.

    Give us your feedback

    We would love️ to hear what you think about the Java extension. As always, your feedback is critical to our product improvement.

    • Have a question? Start a discussion on GitHub Discussions.
    • File a bug in GitHub Issues.
    • Chat with us on Gitter.
    • Find us on Twitter at @VSCodeJava.

    Be more productive with the new VS Code Java 1.0

    Are you still stuck in Java 6, 7, or 8? Or up-to-date with Java 17?

    It doesn't matter which version; you can be more productive with the shiny and new VS Code Java 1.0 Extension! Join us as we review some of the noteworthy features of the past few releases, and talk about Java 17 support, type hierarchy, source lookup improvements, and plenty of valuable tips in between!

    Browse all DevNation Tech Talks

    Last updated: October 6, 2022

    Related Posts

    • Devfiles and Kubernetes cluster support in OpenShift Connector 0.2.0 extension for VS Code

    • vscode-xml 0.14.0: A more customizable XML extension for VS Code

    • How to use the VS Code Tekton Pipelines extension

    • Introducing 10 new features in Quarkus Tools for Visual Studio Code

    Recent Posts

    • GuideLLM: Evaluate LLM deployments for real-world inference

    • Unleashing multimodal magic with RamaLama

    • Integrate Red Hat AI Inference Server & LangChain in agentic workflows

    • Streamline multi-cloud operations with Ansible and ServiceNow

    • Automate dynamic application security testing with RapiDAST

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue