Tut00 - james-bern/CS136 GitHub Wiki
README
- This tutorial will get you ready to code Java in the Eclipse IDE!
- 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
⌘ + C
to copy - Press
⌘ + V
to paste - NOTE: There is also
⌘ + X
to "cut," which copies the text and deletes it
🤷♂️ Windows
- Highlight text by clicking and dragging the mouse
- Press
CONTROL + C
to copy - Press
CONTROL + V
to paste - NOTE: There is also
CONTROL + X
to "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 pressENTER
to change directory to the home directory
- If not in the home directory, in the Terminal, type
- In the Terminal, type
cd Desktop
and 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 Desktop
and 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
⌘ + SPACE
typeAppearance
and 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 mode
toSingle theme
and 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
- In the Terminal, type
- Install Git
- In the Terminal, type
brew install git
and 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 Control
popup- Press 'Yes'
- Click
Next
- Click
Next
Select Components
window- Uncheck all boxes
- Click
Next
- Click
Next
Choosing the default editor used by Git
window- Choose
Use Notepad as Git's default editor
- Choose
- Mash
Next
/Install
until 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 by c
- 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 complete
box is checked - Click
Extract
- The unzipped folder should pop up
- Click and drag the inner
eclipse
folder to yourDesktop
- Close the
File Explorer
window - Double-click the
eclipse
folder to open it - Hold the
ALT
key and drageclipse.exe
onto yourDesktop
to make a desktop shortcut - Close the
File Explorer
window
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 pressENTER
to open Eclipse - 🤷♂️ Double-click
eclipse.exe - Shortcut
to open Eclipse
- 🍏 Press
- A window titled
Eclipse IDE Launcher
should 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
Welcome
pane
Open Project
- In Eclipse,
File
->Open Projects from File System...
Directory...
Desktop
->CS136
- Press
Open
- Press
Finish
- In
Package Explorer
on 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 decision
and 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 decision
and say YES 🙆 - ⚠️ IMPORTANT: If Eclipse wants say it needs to go around your firewall, ALLOW 🙆
- Option A: Press the
Debug
button (🪲) - 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
F11
may 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 folding
is 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
Variables
andDebug
panes, 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
Console
pane, tryWindow
->Show View
->Console
- 🍏 NOTE: You may need to drag the
Problem
pane'sDescription
column separator over to the right to see anything. - NOTE: There is a
Maximize
button 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 clickCS136
and 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 + A
thenCONTROL + I
Run the Starter Code
- Run HW00 by pressing the bug (🪲) or your computer's
F11
hotkey combination that you looked up earlier
Compile Error
- You should get an
Errors in Workspace
popup - Press
Cancel
- Verify that you can read the compile error (missing semicolon) in the
Problems
pane like this:
- Add the missing semicolon
- Run again
Runtime Error
- Read the runtime error (divide by zero) in the
Variables
pane like this:- NOTE: You will need to click on
main() is throwing
- NOTE: You will need to click on
- Press the
Resume
button (yellow and green icon kinda like ⏯️) to crash the program (and terminate the debugging session) - Replace
0
with6
- Run again
Assert Error
- Read the assert error (
2 + 2 == 5
) in theDebug
pane 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
Resume
button (yellow and green icon kinda like ⏯️) to crash the program (and terminate the debugging session) - Replace
5
with4
- Run again
Console Message
- Read the console message (
7
) in theConsole
pane like this:
Warning
- Read the warning (
Comparing identical expressions
) in theProblems
pane like this:
- Delete the very silly
ASSERT(2 + 2 == 4);
- Run again
- 🙂👍