Home Java Tutorial First Java Program

First Java Program

by Anup Maurya
8 minutes read

Visual Studio Code (VS Code) is a lightweight and versatile code editor that is popular among developers. It is also a great choice for writing and running Java programs. In this tutorial, we will write our First Java Program and run it using VScode.

To write your first Java program in VS Code, you need to follow these steps

  1. Install Java Development Kit (JDK) on your computer

To write and run Java programs, you need to install JDK on your computer. You can download the latest version of JDK from the Oracle website: https://www.oracle.com/java/technologies/javase-downloads.html.

  1. Install the Java Extension Pack in VS Code

The Java Extension Pack provides essential tools for Java development in VS Code, such as language support, debugging, and code completion. You can install it from the VS Code Marketplace: https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack.

  1. Create a new Java project in VS Code

To create a new Java project in VS Code, follow these steps

  • Open VS Code and click on File > Open Folder.
  • Create a new folder for your project and select it.
  • Click on the New File button in the Explorer pane and create a new file with the .java extension (e.g., HelloWorld.java).
  1. Write your first Java program

To write your first Java program in VS Code, follow these steps

  • Open the HelloWorld.java file in the VS Code editor.
  • Type the following code
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

This program will print “Hello, World!” to the console.

  1. Compile and run your Java program

To compile and run your Java program in VS Code, follow these steps

  • Open the Terminal in VS Code (View > Terminal).
  • Compile your Java program by typing the following command: javac HelloWorld.java.
  • Run your Java program by typing the following command: java HelloWorld.

You should see “Hello, World!” printed to the console.

Congratulations! You have written and run your first Java program in VS Code. From here, you can continue learning Java by exploring its syntax, data types, control structures, and object-oriented programming concepts. Happy coding!

related posts

Leave a Comment

Enable Notifications OK No thanks