Installing Java, Eclipse, and Git

You will need to install the following:



If you already have Git installed, you do not need to install the latest version. Windows users should look for the Git shell. OS X & Linux users should try running git in a terminal.


The Git site should prompt you to download the appropriate version. Follow the instructions of the executable.


Windows:

On the Select Components page, choose all the selected components plus at least one of the Additional icons (this creates a Git Bash shortcut which you will use for all Git commands).


Choose Use Git from the Windows Command Prompt and Checkout Windows-style, commit Unix-style line endings (and defaults for the rest).


Configuring Eclipse


The Eclipse integrated development environment (IDE) is a powerful, flexible, complicated, and occasionally frustrating set of tools for writing, modifying, and debugging programs. It is especially useful for working in Java.


When you run Eclipse, you will be prompted for a “workspace” directory, which is where Eclipse will store its configuration and metadata. The default location is a directory called workspace in your home directory. You should not run more than one copy of Eclipse at the same time with the same workspace, or the metadata will become corrupted. Choose a place to put your workspace and continue.


The first time you run Eclipse, it will show you a welcome screen. Click the “Workbench” button and you’re ready to begin.


You may store your code in the workspace directory, but this is not recommended. On the left side of your Eclipse window is the Package Explorer, which shows you all the projects in your workspace. The Package Explorer looks like a file browser, but it is not. Don’t be fooled — it rearranges files and folders, includes things that are not files or folders, and can include projects stored anywhere on disk that have been added (but not copied into) to the workspace.

  1. Open Eclipse preferences.

    Windows & Linux: got to Window → Preferences.


    OS X:
    go to Eclipse → Preferences.

  2. Make sure Eclipse is configured to use Java 8.

    1. In preferences, go to Java → Installed JREsEnsure that "Java SE 8" is the only one checked. If it's not listed, click Search.

    2. Go to Java → Compiler and set "Compiler compliance level" to 1.8.

  1. Make sure assertions are always on. Assertions are a great tool for keeping your code safe from bugs, but Java has them off by default.

    In preferences, go to Java → Installed JREsClick Java SE 8 and then the Edit... button. In the "Default VM arguments" box enter: -ea (which stands for enable assertions). And click Finish.

  2. Tab policy. Configure your editor to use spaces instead of tabs, so your code looks the same in all editors regardless of how that editor displays tab characters.

    In preferences, go to Java → Code Style → Formatter. Click the Edit... button next to the active profile. In the new window, change the Tab policy to "Spaces only." Keep the Indentation size and Tab size at 4. Enter a new name for the profile and click OK.

  3. Save all preferences by pressing OK at the bottom to close the menu.


Creating Your MIT Github Account


For this class, we are using Git for you to turn in all your problem sets and coding exercises. We need you to set up your MIT Github account for this. However, we still want you to use the commandline for all other needs to better prepare you for future classes.

  1. Go to https://github.mit.edu and log in with your credentials. (This will automatically create an account for you.)

  2. At the top right hand corner, click the Settings wheel, and go to Profile. You can add an email to receive notifications.

  3. Within Settings, go to Applications, and click Generate new token. The default checked scopes are fine. Give it any description you want. You will need this token when cloning your repo because the system does not know (or use) your MIT kerberos password.

  4. Once we've added you to the 6.178 organization you should receive an email if you asked to be notified in Step 2. If not, go to https://github.mit.edu/6178-iap16 to accept the invitation. If you did not receive an invitation by the start of class, please email the staff.


Configuring Git


Before using Git, let's do some required setup, and make it behave a little nicer.

  1. Who are you?


    Every Git commit includes the author's name and email. Make sure Git knows your name and email by going to the terminal (Git Bash on Windows) and running:


    git config --global user.name "Your Name" git config --global user.email username@mit.edu

  2. Editing commit messages.


    Every Git commit has a descriptive message, called the commit message. Configure the default text editor you will use to write them.


    Option 1(a): use nano on OS X and Linux


    nano
    is a simple text editor. It does not come with the Windows version of Git, so Windows users should choose a different option.


    To see if you have nano, try running:


    nano


    in the terminal. The result should be a simple editor with instructions at the bottom of the screen; quit with ctrl-X. If that worked:


    git config --global core.editor nano


    will configure Git to use the nano editor. The commands to use the text editor (like copy, paste, quit, etc) will be shown on the bottom on the screen. The ^ symbol represents the ctrl key. For example, you can press ctrl-0 to save (name calls it "write out") and then ctrl-X to quit.


    Option 1(b): use Notepad on Windows


    You can change the default editor to Notepad with:


    git config --global core.editor notepad


    If you prefer to edit your commit messages in the terminal, choose the next option instead.


    Option 2: use Vim on Linux, OS X, and Windows


    On OS X and Windows, your default editor will be Vim. On Linux, the default editor depends on your distribution.


    Vim is a popular text editor, but it’s tricky to use.


    Before making your first commit, try running:


    vim


    in the terminal.


    You start in a mode called “normal mode”. You can’t immediately type anything into the file!


    In order to start typing, press i (stands for “insert”). This will bring you to “insert mode”, so named because in this mode you can type text into the file.


    When you are done typing, press esc. This will bring you back to “normal mode”.


    Once you’re back in normal mode, you can type commands that start with :.


    To save your work, type :w (stands for “write”) and press return.


    To exit (quit) Vim, type :q and press return.


    To save and quit in one command, combine them: type :wq and press return.

  3. Add some color.


    Out of the box, it can be hard to see and understand all the output that git prints out at you. One way to make it a little easier is to add some color. Run the following commands to make your git output colorful:


    git config --global color.branch auto git config --global color.diff auto git config --global color.interactive auto git config --global color.status auto git config --global color.grep auto

  4. LOL.


    As we’ll see later on in the course, git log is a command for looking at the history of your repository.


    To create a special version of git log that summarizes the history of your repo, let’s create a git lolalias using the command (all on one line):


    git config --global alias.lol "log --graph --oneline --decorate --color --all"


    Now, in any repository you can use:


    git lol


    to see an ASCII-art graph of the commit history.


This document is based on the 6.005 Getting Started Notes.