April 15th

Useful links

HOMEWORK

Code Academy (Java Tutorial)

Installing Java and Eclipse

Project Euler

Java Basics

Loops

Methods

Objects/Classes

Lesson Plan

The Website & GitHub

The robotics website has a specific sub-site dedicated to programmers. This site includes information on our previous robots, references to APIs and other documentation, and notes and guides on various aspects of programming the robot. I highly suggest familiarizing yourself with the site as it will almost certainly come in handy.

In addition to this website, there is also another website called GitHub. GitHub is where we keep online copies of our code. GitHub works similarly to Google Docs, and allows multiple people to work on a programming project at the same time. After you make sure changes to a project, you can simply “commit” and “push” these changes to the online copy of the code. Once we start programming the actual robot, I will go into detail on how to use GitHub. For now, just know that it is where all of our code is stored. If you do not already have a GitHub account, please make one so that I can add you to our team.

Installing Java and Eclipse

Eclipse is what is known as an IDE (Integrated Development Environment). It works similarly to a word processor like Microsoft Word in that it is the place where you write your code. IDEs such as Eclipse also include features such as autocompletion and error checking which allows for a programmer to write code more quickly and be notified of mistakes before running the code.

The programming language that we will be coding in is called Java. By now, you should have already taken the Java programming course on Code Academy. To install Eclipse and Java, follow this tutorial here: Installing Java and Eclipse. I highly suggest installing this on your home computer so that you can program from home. Unlike building, programming requires a fair amount of out-of-club dedication. Part of being a programmer is writing code outside of robotics, especially during the last week of build season. Since you only get a limited amount of time with the robot, it is important to have everything ready to go and be prepared before you get your time with the robot. Because of this, you need to make sure you can program outside of robotics.

Using Eclipse

Unlike on Code Academy, writing projects in most IDEs is not quite so straight forward. A project is essentially an entire program in which you can have multiple files, classes, etc. with each file containing methods and code. In some of the later Code Academy tasks, there were two files involved which should give you at least a vague idea on how multiple files can work together in a project. For the most part, the files you create will be new classes as every program needs at least one class.

To create a new project, open Eclipse and go to File > New > Java Project. If Java Project is not an option, go to File > New > Other then open the Java folder and select Java Project.

On the next screen, type in a project name. Your project name should probably start with an uppercase letter. Leave everything else as it is, and click Finish.

Now on the left bar in Eclipse, you should see your project. Double click it to open it and then right click on src and select New > Class.

Class names always start with an uppercase letter, don’t have spaces, and use camel case. Typically, your first class will have the same name as your project.

Since this is your first class, once you type in the name, you also need to select public static void main(String[] args) as a method stub. This will create the “main method” in your new class file and should only exist in one class. All other classes should leave that option unchecked.

Once done, click finish and your new file should open and contain a single method titled main. Inside the method should be a comment that can be removed and replaced with your code.

After writing your code, you can click the green play button at the top of the window to run your code and see the output in a console at the bottom of the window.

Java Basics Review

Before moving on, we are going to review everything that you should have learned on Code Academy. I should note that only going through all this information is not enough and that you should consider practicing on your own by coming up with simple programs to make. There is an extensive list of simple programming challenges available online at Project Euler.

To finished up, go to this document here: Java Basics. It contains notes on all the basics of Java. Make sure you understand everything in the document and review by making programs using the information provided.

That document does not cover loops, methods (functions), or classes however, you should still be familiar all of these things. Look below for links that explain these things if you need to review. I also reposted the Java Basics guide I wrote below. (In case people don’t see it inside the wall of text above).

Covered this week:

Java Basics

Loops

For next week:

Methods

Objects/Classes

Homework

The homework due next Saturday is the 2nd project Euler challenge. Your job is to write a program that performs what the challenge asks. Feel free to use the resources above to help you or ask me (Kevin) for help by messaging me in Slack.

Challenge: projecteuler.net/problem=2

Challenge Answer: 4,613,732