Tut00 - james-bern/CS136 GitHub Wiki
README
- This somewhat terrifying tutorial will get you ready to code Java in the (relatively) simple Eclipse IDE!
- Learning how to use your IDE is a really good time investment 🙂👍
 
- We will also fill in some gaps in your knowledge of computer basics
- NOTE: If you have any problems feel free to email Jim or we can fix them together on the first day of class 🙂👍
Definitions
- A window is made up of panes
- A GUI (pronounced "gooey") lets you interact with a computer program using the mouse (includes checkboxes, buttons, icons, etc.)
- Most programs you use have a GUI, but some, like the Terminal/Command Prompt, do not
 
- A text editor lets you edit text
- A debugger helps you find bugs in your code
- A "graphical debugger" has a GUI, and is usually a lot easier to use than a pure "command-line debugger"
 
- An IDE is a text editor plus other stuff (debugger, etc.)
How to copy and paste
🍏 Mac
- Highlight text by clicking and dragging the mouse
- Press ⌘ + Cto copy
- Press ⌘ + Vto paste
- NOTE: There is also ⌘ + Xto "cut," which copies the text and deletes it
🤷♂️ Windows
- Highlight text by clicking and dragging the mouse
- Press CONTROL + Cto copy
- Press CONTROL + Vto paste
- NOTE: There is also CONTROL + Xto "cut," which copies the text and deletes it
How to right click on a Macbook
- Click the trackpad with two fingers
How to open a Terminal/Command Prompt and Navigate to the Desktop
🍏 Mac
- Open a Terminal by pressing ⌘ + SPACE, typingterminal, and pressingENTER
- A Terminal should pop up in the home directory (denoted by a ~)- If not in the home directory, in the Terminal, type cd ~and pressENTERto change directory to the home directory
 
- If not in the home directory, in the Terminal, type 
- In the Terminal, type cd Desktopand pressENTER
🤷♂️ Windows
- Open a Command Prompt by pressing ⊞ Win, typecmd, and pressingEnter
- A Command Prompt should pop up in the home directory (mine is C:\Users\jbern)
- In the Command Prompt, type cd Desktopand pressENTER
How to Put GitHub into Light Mode
It will be easier to read the course webpage in "light mode" (black text on white background).
- Option A (easier): Set you system theme to a light mode
- 🍏 Mac: Press ⌘ + SPACEtypeAppearanceand pressEnter; select a light theme.
- 🤷♂️ Windows: Press ⊞ Win, typeTurn on light mode systemwide, and pressEnter; selectLight
 
- 🍏 Mac: Press 
- Option B: Change theme of Github only.
- Log in to Github (make an account if you don't already have one) and click the circular icon in the top right -> Settings->Appearance; setTheme modetoSingle themeand selectLight default.
 
- Log in to Github (make an account if you don't already have one) and click the circular icon in the top right -> 
Misc Setup
🧑🔬 NOTE: If you are working on a Lab Machine, please skip to Clone the Codebase.
Install Git
🍏 Mac
- Install Homebrew
- In the Terminal, type /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"and pressENTER
- Read the bottom of the message that brew prints to your Terminal.
- If there are additional instructions there, follow them as well. 🙂👍
 
 
- In the Terminal, type 
- Install Git
- In the Terminal, type brew install gitand pressENTER
 
- In the Terminal, type 
🤷♂️ Windows
- Download Installer
- Open the downloaded file (it can be found by clicking the ⬇️ button at the right-top corner of Edge)
- You may get a User Account Controlpopup- Press 'Yes'
 
- Click Next
- Click Next
- Select Componentswindow- Uncheck all boxes
 
- Click Next
- Click Next
- Choosing the default editor used by Gitwindow- Choose Use Notepad as Git's default editor
 
- Choose 
- Mash Next/Installuntil it starts actually installing
- Congratulations, you have installed Git
Uninstall Java
Uninstall any versions of Java already on your computer.
- Open a Terminal and run java -version
- If you get an error (command java not found or similar): You have no Java! Please continue to the next step 🙂👍
- If a recent-ish Java version (e.g., Java 17) is installed: This is actually probably fine. Continue to the next step 🙂👍
- If an ancient Java version (e.g., 1.8) is installed: We need to uninstall Java!
- Windows: Press ⊞ Win, typeadd or remove programs, and pressEnter; Uninstall Java
- Mac: Open a Terminal and run the following commands (you can copy them all at once by clicking the icon in the top right (⧉))
sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane sudo rm -rf /Library/Application\ Support/Oracle/Java/ sudo rm -rf /Library/Java/JavaVirtualMachines
 
- Windows: Press 
Install Eclipse
🍏 Mac
- Download the right Eclipse 2021-12-R installer for your Mac
- Click the Apple icon at the top left of your screen -> About This Mac
 
- Click the Apple icon at the top left of your screen -> 
- Double-click the downloaded file (it can be found by clicking the ⬇️ button at the right-top corner of Safari)
- A Finder window should pop up
- Click and drag Eclipse (🔮) into the Applications shortcut (📁) to install Eclipse
- Click the red x (❌) to close the Finder window
- There Eclipse installer (⬜️) is still on your Desktop; eject it by right clicking its icon and pressing Eject "Eclipse"
🤷♂️ Windows
- Download Zip Folder
- Open the downloaded file (it can be found by clicking the ⬇️ button at the right-top corner of Edge)
- Click Extract all
- Make sure Show extracted files when completebox is checked
- Click Extract
- The unzipped folder should pop up
- Click and drag the inner eclipsefolder to yourDesktop
- Close the File Explorerwindow
- Double-click the eclipsefolder to open it
- Hold the ALTkey and drageclipse.exeonto yourDesktopto make a desktop shortcut
- Close the File Explorerwindow
Clone The Codebase
- Open a new Terminal
- Navigate to the Desktop
- Type git clone https://github.com/james-bern/CS136.git
- Press ENTER
Launch Eclipse
- ⚠️ IMPORTANT: Never update Eclipse
- Open Eclipse
- 🍏 Press ⌘ + SPACE, typeeclipse, and pressENTERto open Eclipse
- 🤷♂️ Double-click eclipse.exe - Shortcutto open Eclipse
 
- 🍏 Press 
- A window titled Eclipse IDE Launchershould pop up
- Check the box for Use this as default and do not ask again
- Press Launch
- A webpage may open (for...some reason)
- Close it
 
- Close the Welcomepane
Open Project
- In Eclipse, File->Open Projects from File System...
- Directory...
- Desktop->- CS136
- Press Open
- Press Finish
- In Package Exploreron the left...- Click the >next toCS136
- Click the >next to(default package)
- Double-click HelloCow.java
 
- Click the 
Run HelloCow (in the Debugger)
- ⚠️ IMPORTANT: If Eclipse ever offers to switch its Perspective automatically, check Remember my decisionand say NO 🙅- If you mess this (or any other stuff) up, just lemme know 🙂👍
 
- ⚠️ IMPORTANT: If Eclipse ever offers to save your file before running, check Remember my decisionand say YES 🙆
- ⚠️ IMPORTANT: If Eclipse wants say it needs to go around your firewall, ALLOW 🙆
- Option A: Press the Debugbutton (🪲)
- Option B: Press the keyboard shortcut for Debug- NOTE: You can find it in the top menu under Run->Debug
- NOTE: On a laptop, you may F11may actually beFn + F11
 
- NOTE: You can find it in the top menu under 
- Press the keyboard shortcut (something involving F11)
- 🥳 Amuse yourself with a rousing game of Tic Tac Toe
Configure Eclipse Prefences
- Open the Preferences
- 🍏 Eclipse->Settings...
- 🤷♂️ Window->Preferences
 
- 🍏 
- Disable Content Assist Auto Activation
- Java->- Editor->- Content Assist- NOTE: You will need to click the >'s to drop down the menus
 
- NOTE: You will need to click the 
- Uncheck the box for Enable auto activation
 
- Disable Initial Folding
- Java->- Editor->- Folding
- Make sure Enable foldingis checked (leave it alone)
- Make sure all other boxes are unchecked (you should have to uncheck two boxes)
 
- Press Apply and Close
Configure Eclipse Panes
- Make your Eclipse looks like this (you will need to spend ~5-10 minutes with dragging the panes around):
- NOTE: If you don't already have the VariablesandDebugpanes, you can add them with something like...- 🍏 Window->Show View->Variables
- 🤷♂️ Window->Show View-> click>byDebug->Variables->Open
 
- 🍏 
- NOTE: If you don't already have the Consolepane, tryWindow->Show View->Console
- 🍏 NOTE: You may need to drag the Problempane'sDescriptioncolumn separator over to the right to see anything.
- NOTE: There is a Maximizebutton on the right-top (looks kinda like 💾) that will make the text editor bigger. UseRestore(⧉) to go back.
 
- NOTE: If you don't already have the 
How to use Eclipse
Create HW00.java
- In the Project Explorer, right clickCS136and pressNew->File
- Type HW00.java
- Press Finish
- Open HW00 in a new window or tab (right-click on the link for options)
- Scroll down to the Starter Code
- Copy the Starter Code by pressing the button in its right-top corner (⧉)
- Paste the Starter Code into HW00.java by clicking inside of HW00.java and pressing...
- 🍏 ⌘ + V
- 🤷♂️ CONTROL + V
 
- 🍏 
Auto-Indent the Starter Code (you want usually have to do this), by clicking inside of HW00.java and pressing
- 🍏 ⌘ + A(select all) then⌘ + I(auto indent)
- 🤷♂️ CONTROL + AthenCONTROL + I
Run the Starter Code
- Run HW00 by pressing the bug (🪲) or your computer's F11hotkey combination that you looked up earlier
Compile Error
- You should get an Errors in Workspacepopup
- Press Cancel
- Verify that you can read the compile error (missing semicolon) in the Problemspane like this:
- Add the missing semicolon
- Run again
Runtime Error
- Read the runtime error (divide by zero) in the Variablespane like this:- NOTE: You will need to click on main() is throwing
 
- NOTE: You will need to click on 
- Press the Resumebutton (yellow and green icon kinda like ⏯️) to crash the program (and terminate the debugging session)
- Replace 0with6
- Run again
Assert Error
- Read the assert error (2 + 2 == 5) in theDebugpane like this:- NOTE: You will need to click one call below the ASSERT(...)call in the stack trace
- NOTE: A message will also be printed to the Console.
 
- NOTE: You will need to click one call below the 
- Press the Resumebutton (yellow and green icon kinda like ⏯️) to crash the program (and terminate the debugging session)
- Replace 5with4
- Run again
Console Message
- Read the console message (7) in theConsolepane like this:
Warning
- Read the warning (Comparing identical expressions) in theProblemspane like this:
- Delete the very silly ASSERT(2 + 2 == 4);
- Run again
- 🙂👍