How to Code a Basic Program in Netbeans

Introduction: How to Code a Basic Program in Netbeans

In this instructable I will explain how to write a basic code in Java environment Netbeans. Whether you are learning for a course or just for fun, coding is something anyone can learn!


  • Computer
  • Netbeans IDE 8.0.2

Step 1: Create a New Project

After downloading, the first thing you need to do is create a new project.

  • Click on the orange file with the green plus sign at the top left corner.
  • A new box will pop up and type in the name of your project, I have named mine "Example."
  • Make sure the box that says "Create Main Class" is not checked.

Step 2: Create a File

After creating a new project you need a file to go in your project.

  • Click on the white paper with the green plus sign at the top left corner.
  • A box will pop up, choose new Java Class and type in the name of your file, I named mine "Hello World."
  • Make sure your Project box is the name of the project you created.

Step 3: Class Is Properly Defined

After you have created your file make sure your class is properly defined.

  • The class should be the same name as the .java file on the tab in the top left corner.
  • Make sure curly brackets placed after the class name, everything written within is what will be implemented.

Step 4: Create Main Method

After your class is created and properly defined create your main method.

  • Under your class name, create a main method. This method is where you will write your code to display to the user.
  • Make sure you place brackets around each method {}

Step 5: Add Import

Don't forget to add your import, this import will allow the user to put their input into the code.

  • Add;
  • Also add Scanner console = new Scanner(;

Step 6: Declare Variables

Declare your variables, these are what will be initialized to output what you want to the user. This code will output "Hello (your name)!"

  • I declared them as strings, string type variables are usually words. You can name them whatever you would like.
  • I have already initialized n1 to "Hello" since I already know that is what I want it to output.
  • The user will input what the variable name will be.

Step 7: Initialize Variable

Next you need to put an output statement that will display to the user. Also put a statement that will allow the user to initialize the variable "name".

  • Put the System.out.println statement, whatever is in-between the parenthesis and quotation marks is what will be outputted.
  • Whatever the user types in next will be initialized into variable "name."

Step 8: Output Full Statement

After you initialize all of your variables you will need to combine them to make one full statement.

  • In order to combine the statements you will need to put another output statement and combine the variables into one sentence by adding them with a plus sign in-between.

Step 9: Run Program

After you have all of your code you will need to run your program.

  • You run the program by clicking on the green triangle at the top.
  • It will them output the statement asking you for your name and you then type it in.

Step 10: Statement Outputted

After you ran the program you will now see that it says "Hello (your name)!"

Or "Hello Rachelle!" in my case.

You have now coded your own simple Java Program!

Be the First to Share


    • Pocket-Sized Speed Challenge

      Pocket-Sized Speed Challenge
    • Super-Size Speed Challenge

      Super-Size Speed Challenge
    • Audio Challenge 2020

      Audio Challenge 2020

    3 Discussions


    4 years ago

    Great info! Thanks for sharing!


    Reply 11 months ago

    in netbeans ide i entered the code but its showing errors


    4 years ago

    Great info! Thanks for sharing!