Z OLD Tutorial 00 - 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...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
; typecmd
; pressEnter
- Mac: type
β + Space
; typeterminal
; pressEnter
Navigate using the terminal
- TODO
Open a File Explorer / Finder from a Terminal
- Windows:
start .
- Mac:
open .
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!
- Windows: Press
β Win
, typeadd or remove programs
, and pressEnter
; 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
- Open a Terminal and run the following commands (you can copy and paste them all in at once.)
- Windows: Press
- Open a Terminal and run
-
Download and Install the Amazon Corretto 8 JDK.
- Download the Installer.
- 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 ->
About This Mac
- 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 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.
- If Java prints out its version...
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 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
- 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
(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
runDrJava
script on your Desktop.
- Do the following setup (you only have to do it the first time).
- Windows: Double-click
- (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 Output
at the bottom of the screen. - If
Compiler
isJDK 8.0_372
orJDK 8.0_382
(usually the case on Windows): The JDK was found automatically. Please continue to the next step. - If
Compiler
isJDK 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
- Windows: Copy and paste this in ->
- Close DrJava.
- Open DrJava.
- If
Compiler
is nowJDK 8.0_372
orJDK 8.0_382
, please continue to the next step. Otherwise, please raise your hand.
- 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 raise your hand)
- In the box next to
File Name:
typeTut00.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
- Windows:
- Click into DrJava's document (click on the giant white box on the right hand side).
- Paste the code.
- Windows:
Ctrl + V
- Mac:
β + V
- Windows:
- Automatically indent the code.
- Highlight all your code.
- Windows:
Ctrl + A
- Mac:
β + A
- Windows:
- 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 World
inInteractions
: You did it! π - You get an error: Please raise your hand. Don't give up we can do this. ππ
- If you see a green
- Press
Experiment in the β¨Interactions Paneβ¨
- Click on
Interactions
- Type
2 + 2
and pressEnter
- Type
"Foo" + "Bar"
and pressEnter
- Type
1 + "Foo"
and pressEnter
- Type
2 / 3
and pressEnter
- Type
42 / 0
and pressEnter
- Type
-(-1)
and pressEnter
Practice Exam questions for Week 00
Do the- 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
-> SelectNimbus
.
- π¨
Fonts
- Set all font sizes to
14
(or a bigger number if14
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
.
- Set all font sizes to
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
, typeTurn on light mode systemwide
, and pressEnter
; selectLight
- Mac: Press
β + Space
typeAppearance
and pressEnter
; select a light theme.
- Windows: 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 ->