- 1). Load the NetBeans IDE by clicking on its program icon. When the program loads, navigate to "New/New Project" and select "Java Application" from the list on the right-hand side of the screen. A new source code file appears in the NetBeans text editor. The source code file contains an empty main method, which is where all the source code will go.
- 2). Declare a byte variable that stores the size of the byte array. Write the following between the curly brackets of the main method:
byte arraySize = 100; - 3). Create a byte array using the "arraySize" variable to set the array size. Write the following right below the statement written in Step 2:
byte[] byteArray = new byte[arraySize]; - 4). Loop through the byte array using a "for" loop. A "for" loop iterates through each item in an array, and allows you to perform an operation on each item in turn. You can use a "for" loop to add values to the byte array and print out the values contained in the array. Write the following "for" loop to do so:
for(byte i = 0; i < arraySize; i++)
{ byteArray[i] = i; System.out.println(byteArray[i]); } - 5). Execute the program by pressing the "F6" key. The program creates a byte array and assigns it the values 0 through 99. The values are printed out in decimal format to the output window.