Z OLD Tutorial 00 - 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...Dark Mode and the ability to read your mind? Pffff... πŸ™„ Don't believe the hype. DrJava is where it's at. πŸ©Ίβ˜•πŸ”₯

Install Software on Your Laptop

Let's get you set up to work from the comfort of you laptop!

(The lab Mac's are already set up if you ever want to use 'em instead.)

Notes:

  • 🚨 Please follow the instructions exactly. Otherwise it's not gon' work. 😬
  • Take your time! Ask for help! Everything is going to be okay! πŸ™‚πŸ‘

Practice Opening Terminals and File Explorers / Finders

Open a Terminal from the Desktop

  • Windows: press ⊞ Win; type cmd; press Enter
  • Mac: type ⌘ + Space; type terminal; press Enter

Navigate using the terminal

  • TODO

Open a File Explorer / Finder from a Terminal

  • Windows: start .
  • Mac: open .

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!
      • Windows: Press ⊞ Win, type add or remove programs, and press Enter; Uninstall Java.
      • Mac:
        • Open a Terminal and run the following commands (you can copy and paste them all in at once.)
          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
          
  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 raise your hand.
    • If you get an error...
      • ...and you're on Windows: We may need to add Java to your path? Please raise your hand.
      • ...and you're on Mac: Perhaps you didn't actually run the installer? Please raise your hand.

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 raise your hand.
    • 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.
    • Windows: Double-click drjava.jar
    • 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.
  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 JDK 8.0_372 or JDK 8.0_382 (usually the case on Windows): The JDK was 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 -> ...
        • Windows: Copy and paste this in -> C:\Program Files\Amazon Corretto\jdk1.8.0_372\lib\tools.jar
        • Mac: Copy and paste this in -> /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/lib/tools.jar
      • Close DrJava.
      • Open DrJava.
      • If Compiler is now JDK 8.0_372 or JDK 8.0_382, please continue to the next step. Otherwise, please raise your hand.

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 raise your hand)
    • In the box next to File Name: type Tut00.java
    • Press Save.
    • Highlight the following code by clicking and dragging.
       class Main {
                    public static void main(String[] arguments) {
          System.out.println("Hello World");
            }
                           }
      
    • Copy the code.
      • Windows: Ctrl + C
      • Mac: ⌘ + C
    • Click into DrJava's document (click on the giant white box on the right hand side).
    • Paste the code.
      • Windows: Ctrl + V
      • Mac: ⌘ + V
    • Automatically indent the code.
      • Highlight all your code.
        • Windows: Ctrl + A
        • Mac: ⌘ + 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 raise your hand. Don't give up we can do this. πŸ™‚πŸ‘

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

Do the Practice Exam questions for Week 00

  • And check your work by running code!

Configure Your Settings

DrJava

  • Click and drag the bottom pane up a bit so you can see more lines inside Interactions, etc.
  • Edit -> Preferences
    • Miscellaneous
      • 🚨 Indent Level -> 4
      • Keep Emacs-style Backup Files -> Uncheck box.
    • Display Options
      • 🚨 Show All Line Numbers -> Check box.
      • 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: Set bottom three fonts to Helvetica.

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 you system theme to a light mode
    • Windows: Press ⊞ Win, type Turn on light mode systemwide, and press Enter; select Light
    • Mac: Press ⌘ + Space type Appearance and press Enter; select a light theme.
  • 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.