Tut00 - james-bern/CS136 GitHub Wiki
is the best IDE ever. It comes with a working
Debug Mode, easy to click Compile and Run buttons, an Interactions pane for easy experimentation, and the simplest automatic indentation in the business (just highlight your code and press Tab). Meanwhile, VS Code is clocking in with...what? Agentic Dark Mode and Psychic Tab Complete? Pffff... ๐ Don't believe the hype. DrJava is where it's at. ๐ฉบโ๐ฅ
Alright, let's get you set up to work from the comfort of your laptop!
(The lab Mac's are already set up if you ever want to use 'em instead.)
NOTE:
- ๐จ Please follow the instructions exactly. Otherwise it's not gon' work. ๐ฌ
- Take your time! Ask for help! Everything is going to be oooookay! ๐๐
๐ค Computer Basics
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
๐ Mac
- 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, typingcmd, 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.- NOTE: You may need to use
cd OneDrive\Desktopinstead; please ask Jim about this if applicable.
- NOTE: You may need to use
How to open a File Explorer / Finder from a Terminal
๐ Mac
- In the folder of your dreams, type
open .and pressENTER.
๐คทโโ๏ธ Windows
- In the folder of your dreams, type
start .and pressENTER.
๐ฉบ DrJava Setup
Install Java Development Kit (JDK)
-
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): You have no Java! Please continue to the next step. ๐๐
- If an ancient Java version (e.g., 1.8) is installed: This is actually probably fine, especially if you're on a Windows laptop. Continue to the next step for now. ๐๐
- If a more recent Java version (e.g., Java 19) is installed: We need to uninstall Java!
- ๐ Mac:
- Open a Terminal and run the following commands (you can copy and paste them all in at once.) To copy a code block on GitHub, press the little icon with the two overlapping squares.
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
- Open a Terminal and run the following commands (you can copy and paste them all in at once.) To copy a code block on GitHub, press the little icon with the two overlapping squares.
- ๐คทโโ๏ธ Windows: Press
โ Win, typeadd or remove programs, and pressEnter; Uninstall Java.
- ๐ Mac:
- Open a Terminal and run
-
Download and Install the Amazon Corretto 8 JDK.
- Download the Installer.
- ๐ Mac: click the Apple icon at the top left of your screen ->
About This Mac - ๐คทโโ๏ธ Windows: https://corretto.aws/downloads/latest/amazon-corretto-8-x64-windows-jdk.msi
- ๐ Mac: click the Apple icon at the top left of your screen ->
- Run the Installer.
- Click the file that you just downloaded (on Mac, it will be in your Downloads) and then click all the way through the Installer.
- Download the Installer.
-
(Optional) Check whether we were successful by opening a Terminal and running
java -version(On Windows, you will need to open a brand new Terminal.)- If Java prints out its version...
- ...and it includes the word "Corretto": Continue onto next step.
- ...and it does NOT include the word "Corretto": You may have failed to uninstall existing versions of Java? Please ask for help.
- If you get an error...
- ๐ ...and you're on Mac: Perhaps you didn't actually run the installer? Please ask for help.
- ๐คทโโ๏ธ ...and you're on Windows: We may need to add Java to your path? Please ask for help.
- If Java prints out its version...
Install DrJava
- Download drjava.jar to your Desktop.
- โจ The rest of this tutorial assumes you have put drjava.jar on your Desktop -- If you need help getting drjava.jar moved onto your Desktop, please ask for help.
- If that link doesn't work (give it a couple minutes before giving up): Click
Download Jar Fileon this website: https://drjava.sourceforge.net
- Run DrJava.
- ๐ Mac:
- Do the following setup (you only have to do it the first time).
- Configure your Terminal to not pop up weird windows.
- Open a Terminal.
Terminal->Preferences(orSettings) ->Profiles->Shell->When the shell exits; SelectClose if the shell exited cleanly- Close the Terminal.
- Make a "Desktop shortcut": Open a Terminal and run the following commands (you can copy and paste them all in at once.)
cd ~/Desktop echo 'cd "`dirname "$0"`" && java -jar drjava*.jar &' > runDrJava chmod +x runDrJava
- Configure your Terminal to not pop up weird windows.
- Double-click the
runDrJavascript on your Desktop.
- Do the following setup (you only have to do it the first time).
- ๐คทโโ๏ธ Windows: Double-click
drjava.jar
- ๐ Mac:
- (If you get an annoying pop-up) In
Check for New Versions of DrJava, selectCheck for:->none (disabled); pressClose. - Help DrJava find the JDK we downloaded.
- Please click
Compiler Outputat the bottom of the screen. - If
Compileris NOTJDK 8.0_222(could beJDK 8.0_382,JDK 8.0_492, etc.): The JDK was likely found automatically. Please continue to the next step. - If
CompilerisJDK 8.0_222(usually the case on Mac): We're going to need to tell DrJava where to look.Edit->Preferences...Resource Locations->Tools.jar Location->...- ๐ Mac: Copy and paste this in ->
/Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/lib/tools.jar - ๐คทโโ๏ธ Windows: Copy and paste this in ->
C:\Program Files\Amazon Corretto\jdk1.8.0_504\lib\tools.jar
- ๐ Mac: Copy and paste this in ->
- Close DrJava.
- Open DrJava.
- If
Compileris now NOTJDK 8.0_222, please continue to the next step. Otherwise, please ask for help.
- Please click
Write Your First Java Program
- Open DrJava.
- Create a file and paste code into it.
File->Save As...- Navigate to the Desktop (on Windows, pressing the ๐ button should work; if you have trouble on Mac, please ask for help)
- In the box next to
File Name:typeTut00.java - Press
Save. - Highlight the following code by clicking and dragging.
class Tut00 { public static void main(String[] arguments) { System.out.println("Hello World"); } } - Copy the code.
- Click into DrJava's document (click on the giant white box on the right hand side).
- Paste the code.
- Automatically indent the code.
- Highlight all your code.
- ๐ Mac:
โ + A - ๐คทโโ๏ธ Windows:
Ctrl + A
- ๐ Mac:
- Press
Tab
- Highlight all your code.
- Compile and Run
- Press
Compile(you may have to make the DrJava window wider in order for this button to appear) - Press
Run- If you see a green
Hello WorldinInteractions: You did it! ๐ - You get an error: Please ask for help. Don't give up we can do this. ๐๐ช
- If you see a green
- Press
- You can go ahead and delete
Tut00.javafrom your Desktop (we won't need it again)
Experiment in the โจInteractions Paneโจ
- Click on
Interactions - Type
2 + 2and pressENTER - Type
"Foo" + "Bar"and pressENTER - Type
1 + "Foo"and pressENTER - Type
2 / 3and pressENTER - Type
42 / 0and pressENTER - Type
-(-1)and pressENTER
๐ฎ Cow.Java Setup
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.
Clone our Codebase
- Open a new Terminal
- Navigate to the Desktop
- Type
git clone https://github.com/james-bern/CS136.git - Press
ENTER
Compile and Run HelloCow
- Open DrJava.
- Press
Open - Navigate to
CS136folder (the one you just cloned, which should be on your Desktop) - Click
HelloCow.javaand pressOpento openHelloCow.java - Press
Compile - Press
Run - Enjoy an invigorating game of tic-tac-toe
โจ Final Touches
Configure DrJava
- Click and drag the bottom pane up a bit so you can see more lines inside
Interactions, etc. Edit->PreferencesMiscellaneous- ๐จ
Indent Level-> Make sure is4 Keep Emacs-style Backup Files-> Uncheck box.
- ๐จ
Display Options- ๐จ
Show All Line Numbers-> Make sure box is checked. - ๐ Mac: (Optional)
Look and Feel-> SelectNimbus.
- ๐จ
Fonts- Set all font sizes to
14(or a bigger number if14is too small for you to read comfortably) - ๐คทโโ๏ธ Windows: Set top two fonts to
Consolas. - ๐คทโโ๏ธ Windows: Set bottom three fonts to
Arial. - ๐ Mac: Make sure bottom three fonts are set to
Helvetica.
- Set all font sizes to
Configure GitHub
It will probably be easier for you to read the webpages for this course in "light mode" (black text on white background).
- Option A (easier): Set your 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 ->