Skip to main content

Command Palette

Search for a command to run...

Java Boilerplate Code for VS Code | Make Java Coding Faster and Easier

Updated
2 min readView as Markdown
Java Boilerplate Code for VS Code | Make Java Coding Faster and Easier
o    Press Ctrl+Shift+P (or Cmd+Shift+P on macOS) to open the Command Palette.
o    Type Preferences: Configure User Snippets and select it.
o    You will see a list of languages and options.
o    Select java.json (you might need to type "Java" to filter the list).
o    In the java.json file, you can add your boilerplate code as a snippet.
o    Replace th ewhoel code below.
{
    // Place your snippets for java here. Each snippet is defined under a snippet name and has a prefix, body and  
    // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: 
    // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the  
    // same ids are connected. 
    // Example: 
    // "Print to console": { 
    //  "prefix": "log", 
    //  "body": [ 
    //   "console.log('$1');", 
    //   "$2" 
    //  ], 
    //  "description": "Log output to console" 
    // } 
    //---------------------------------------------------------------------------------------------------- 
    // Snippet for Java boilerplate code 
    "Java Class Boilerplate": {
        "prefix": "javaboiler",
        "body": [
            "import java.util.*;",
            "import java.util.Scanner;",
            "public class ${TM_FILENAME_BASE} {",
            "    public static void main(String args[]) {",
            "        // your code here",
            "        $0",
            "    }",
            "}"
        ],
        "description": "Creates a basic Java class with a main method"
    },
    //Snippet for Scanner Class 
    "Scanner Boilerplate": {
        "prefix": "sc",
        "body": [
            "Scanner sc = new Scanner(System.in);"
        ],
        "description": "Creates a Scanner object for user input"
    },
    //Snippet for For Loop 
    "For Loop": {
        "prefix": "forloop",
        "body": [
            "for (int ${1:i} = 0; ${1} < ${2:n}; ${1}++) {",
            "    ${3:// loop body}",
            "}"
        ],
        "description": "Creates a for loop"
    },
    //Snippet for Printing Line 
    "System.out.print": {
        "prefix": "sop",
        "body": [
            "System.out.print($0);"
        ],
        "description": "Prints text without a newline, with cursor inside parentheses"
    },
    //Snippet for Printing on New Line 
    "System.out.println": {
        "prefix": "sopln",
        "body": [
            "System.out.println($0);"
        ],
        "description": "Prints text with a newline, with cursor inside parentheses"
    },
    // Snippet for Java Public Static 
    "Java Static Boilerplate": {
        "prefix": "ps",
        "body": [
            "public static"
        ],
        "description": "Creates a basic Java class with a main method"
    },
    // Snippet for Array Creation 
    "Array Declaration": {
        "prefix": "arr",
        "body": [
            "int[] ${1:arr} = new int{${2:Input}};"
        ],
        "description": "Declares an integer array with specified name and size"
    }
}

That's it. Happy Coding :)

Written By: Rohan Satkar

Date: 06/02/2026

GitHub: https://github.com/Coderxrohan/

GitLab: https://gitlab.com/Coderxrohan

LinkedIn: https://www.linkedin.com/in/rohansatkar/

More from this blog

Coderxrohan

8 posts