We are going to be using Eclipse for our exercises since this is the tool we will be using to program our robots including the FRC robots. We are going to assume that Eclipse is already installed on your computer. If not, follow the instructions in the section which describes how to install the tools you will need for programming the robots.
Start up Eclipse and choose the workspaceJava folder as your workspace. If this is the first time you have run Eclipse, you should see something like:
Now click on the File menu, and choose New / Java Project as shown below:
Then in the New Java Project dialog box, enter HelloWorld for the Project name:
Make sure that the Use an execution environment JRE dropdown is set to JavaSE-1.7, and then click Finish. You should then see the following:
There are a lot of open windows here and we want to clean it up a bit so it is not quite so confusing. Close the Start Page and the Welcome page by clicking on the little close icons circled in red. Then minimize the two windows with the minimize buttons circled in red. Your project should then look like:
Now create your first class by right clicking on the src folder in the Package Explorer on the left and choosing New / Class as shown below:
Then enter the name HelloWorld in the Name field, and check the ‘public static void …’ option as shown:
Click Finish and you should see your class created:
Now all we are going to do is have this program print out ‘Hello World’ when it is executed. The function that prints to the console is System.out.println() which we add to the main function of our HelloWorld class as follows:
public class HelloWorld
public static void main(String args)
We can now run our program by right clicking on the HelloWorld project in the Package Explorer and choosing the Run As / Java Application option:
After our program runs, the output will be displayed in the Console window at the bottom:
Let’s take a look at this program. In Java all of your code needs to reside inside an object called a class and here we have created the main class for our program. All Java programs need an entry point, and that entry point will be a function called main. Remember when we created our HelloWorld class, we specified that Eclipse should automatically create our main() entry point function. This saves us some typing.
We then learned how to write a string to the console. In general, when we are writing our robot programs we will not be outputting text to the console, although doing so may be useful for debugging purposes.
The next time you want to run this program, you will be able to use the dropdown menu as shown below: