Skip to content

VS Code Tips

Siddharth Srinivasan edited this page Dec 4, 2025 · 1 revision

Guide: Using VS Code with the Oracle Java Extension

Run Commands in VS Code

Install the Oracle Java Extension

  • Open Extensions: Ctrl+Shift+X (Cmd+Shift+X on macOS) or View > Extensions.
  • Search for "Java" and install the extension published by Oracle.
  • Or, via Command Palette: "Extensions: Install Extensions" then search "Java".
  • Or, via CLI: code --install-extension oracle.oracle-java.
  • Reload VS Code if prompted.
  • See also: VS Code - Get Started > Extensions

Open VS Code Settings

There are multiple ways to open VS Code Settings.

  • Gear icon (bottom-left) > Settings
  • Command Palette: "Preferences: Open Settings"
  • Menu:
    • Windows/Linux: File > Preferences > Settings
    • macOS: Code > Settings > Settings (Cmd+,)
  • Open settings JSON:
    • Command Palette: "Preferences: Open Settings (JSON)"
    • Click "Open Settings (JSON)" in the Settings UI
  • See also: VS Code - Configure > Settings

Kinds of Settings and Order of Application

  • Scopes (from lowest to highest precedence):
    1. Default settings i.e. Application settings.
    2. User settings i.e. VS Code user profile settings.
    3. Workspace settings
    4. Folder settings (in multi-root workspaces)
  • Language-specific settings (e.g., [java]) override non-language settings at the same scope.
  • Effective value = highest-precedence matching scope, with language override applied last.

CodeLens, Suggestions, Hints, and Completions

  • CodeLens: Inline, clickable annotations above code (e.g., "Run | Debug", references count). Click to run code, debug, test or navigate.
  • Suggestions/Completions (IntelliSense): Symbols, methods, imports, etc.; auto or via Ctrl+Space.
  • Hints (Inlay/Parameter hints): Small annotations showing parameter names/inferred types.
  • Configuration is possible for various features, including:
    • Editor: CodeLens, Inlay Hints
    • Java completion/suggestions/import settings

Format Code

  • Format Document:
    • Windows/Linux: Shift+Alt+F
    • macOS: Shift+Option+F
    • Or right-click editor > Format Document
  • Enable "Editor: Format On Save" for automatic formatting.
  • See Configure Java formatter for defining your code style.

Refactor Code

  • Quick Fix / Code Action: Lightbulb or Ctrl+. (Cmd+. on macOS)
  • Rename symbol: F2 (updates all references)
  • Extract method/variable/constant, inline, implement/override methods, organize imports:
    • Right-click > Refactor…
    • Command Palette: "Refactor…" or "Source Action…"
    • Many refactors appear when you select code
  • Organize Imports: Command Palette "Organize Imports" or enable via Settings | Jdk › Java › On Save: Organize Imports.

View Output Logs from the Oracle Java Extension

  • View > Output (Ctrl/Cmd+Shift+U).
  • In the Output panel dropdown, select the Oracle Java channel (e.g., "Oracle Java SE Language Server"). If not visible, also check the "Extension Host" channel.
  • For issues, also check View > Problems.

Access the Integrated Terminal

  • Toggle terminal: Ctrl+` (backtick) or View > Terminal.
  • Create/select terminals (Command Prompt, PowerShell, Bash, zsh).
  • Run Maven/Gradle or java/javac commands directly.

Launch or Run Your Code

  • Use CodeLens "Run"/"Debug" above main methods or tests.
  • Run menu:
    • Run > Start Debugging (F5)
    • Run > Run Without Debugging (Ctrl+F5 / Cmd+F5)
  • Run and Debug view (Ctrl+Shift+D / Cmd+Shift+D):
    • Click "Run and Debug" to auto-detect Java configs, or create a launch.json for custom configs.
  • Optional: Use tasks.json for custom build/run tasks.

View Run/Debug Output and Enter Input

  • Program output and input, as well as, debug logs and expression results are shown in the DEBUG CONSOLE tab (Ctrl/Cmd+Shift+Y).

View Variables and Evaluate Expressions During Debugging

  • Start a debug session (F5 or via CodeLens).
  • Use:
    • Variables view for locals/globals
    • Watch to track expressions
    • Hover to see variable values inline
    • Debug Console to evaluate expressions
    • Call Stack and Breakpoints to navigate and manage conditions/logpoints