Trybotics Logo

How to Code a Basic Program in Netbeans

DESCRIPTION

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!

Materials:

  • Computer
  • Netbeans IDE 8.0.2


Description:

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.

Description:

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.

Description:

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.

Description:

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 {}

Description:

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

  • Add import.java.util.Scanner;
  • Also add Scanner console = new Scanner(System.in);

Description:

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.

Description:

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."

Description:

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.

Description:

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.

Description:

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!


YOU MIGHT ALSO LIKE