Tut00 - james-bern/CS136 GitHub Wiki


image 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 โŒ˜ + 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

๐Ÿ 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, typing terminal, and pressing ENTER.
  • A Terminal should pop up in the home directory (denoted by a ~).
    • If not in the home directory, in the Terminal, type cd ~ and press ENTER to change directory to the home directory.
  • In the Terminal, type cd Desktop and press ENTER.

๐Ÿคทโ€โ™‚๏ธ Windows

  • Open a Command Prompt by pressing โŠž Win, typing cmd, and pressing ENTER.
  • A Command Prompt should pop up in the home directory (mine is C:\Users\jbern).
  • In the Command Prompt, type cd Desktop and press ENTER.
    • NOTE: You may need to use cd OneDrive\Desktop instead; please ask Jim about this if applicable.

How to open a File Explorer / Finder from a Terminal

๐Ÿ Mac

  • In the folder of your dreams, type open . and press ENTER.

๐Ÿคทโ€โ™‚๏ธ Windows

  • In the folder of your dreams, type start . and press ENTER.

๐Ÿฉบ DrJava Setup

Install Java Development Kit (JDK)

  1. 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
          
      • ๐Ÿคทโ€โ™‚๏ธ Windows: Press โŠž Win, type add or remove programs, and press Enter; Uninstall Java.
  2. Download and Install the Amazon Corretto 8 JDK.

  3. (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.

Install DrJava

  1. 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 File on this website: https://drjava.sourceforge.net
  2. 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 (or Settings) -> Profiles -> Shell -> When the shell exits; Select Close 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
          
      • Double-click the runDrJava script on your Desktop.
    • ๐Ÿคทโ€โ™‚๏ธ Windows: Double-click drjava.jar
  3. (If you get an annoying pop-up) In Check for New Versions of DrJava, select Check for: -> none (disabled); press Close.
  4. Help DrJava find the JDK we downloaded.
    • Please click Compiler Output at the bottom of the screen.
    • If Compiler is NOT JDK 8.0_222 (could be JDK 8.0_382, JDK 8.0_492, etc.): The JDK was likely found automatically. Please continue to the next step.
    • If Compiler is JDK 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
      • Close DrJava.
      • Open DrJava.
      • If Compiler is now NOT JDK 8.0_222, please continue to the next step. Otherwise, please ask for help.

Write Your First Java Program

  1. Open DrJava.
  2. 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: type Tut00.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
      • Press Tab
  3. 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 World in Interactions: You did it! ๐Ÿ˜ƒ
      • You get an error: Please ask for help. Don't give up we can do this. ๐Ÿ™‚๐Ÿ’ช
  4. You can go ahead and delete Tut00.java from your Desktop (we won't need it again)

Experiment in the โœจInteractions Paneโœจ

  • Click on Interactions
  • Type 2 + 2 and press ENTER
  • Type "Foo" + "Bar" and press ENTER
  • Type 1 + "Foo" and press ENTER
  • Type 2 / 3 and press ENTER
  • Type 42 / 0 and press ENTER
  • Type -(-1) and press ENTER

๐Ÿฎ 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 press ENTER
    • Read the bottom of the message that brew prints to your Terminal.
      • If there are additional instructions there, follow them as well. ๐Ÿ™‚๐Ÿ‘
  • Install Git
    • In the Terminal, type brew install git and press ENTER

๐Ÿคทโ€โ™‚๏ธ 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
  • Mash Next/Install until 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 CS136 folder (the one you just cloned, which should be on your Desktop)
  • Click HelloCow.java and press Open to open HelloCow.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 -> Preferences
    • Miscellaneous
      • ๐Ÿšจ Indent Level -> Make sure is 4
      • Keep Emacs-style Backup Files -> Uncheck box.
    • Display Options
      • ๐Ÿšจ Show All Line Numbers -> Make sure box is checked.
      • ๐Ÿ Mac: (Optional) Look and Feel -> Select Nimbus.
    • Fonts
      • Set all font sizes to 14 (or a bigger number if 14 is 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.

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 โŒ˜ + Space type Appearance and press ENTER; select a light theme.
    • ๐Ÿคทโ€โ™‚๏ธ Windows: Press โŠž Win, type Turn on light mode systemwide, and press ENTER; select Light
  • 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; set Theme mode to Single theme and select Light default.