2350 views
# **CS200 Java Stencil Setup Guide** This guide contains instructions for downloading and running Java stencil code into IntelliJ.  You can use this process to load example Java code posted for a lecture, or to get started with homeworks/projects/labs in Java.   # **Before you start** This guide assumes that you have set up IntelliJ and Git on your system, which was part of HW0.  Specifically, if you have not done so already, you should install and configure IntelliJ per the [**IntelliJ guide**](https://docs.cs200.io/s/intellij-guide).  If you encounter errors, remember to check the Troubleshooting section.   1. **Install and configure IntelliJ per the** [**IntelliJ guide**](https://docs.cs200.io/s/intellij-guide) up to the “Running assignments” section.  If you encounter IntelliJ errors, remember to check the [FAQ section](https://docs.cs200.io/intellij-guide?both#Common-BugsFAQ).   2. **Use the** [**Github guide**](https://docs.cs200.io/s/github-guide) **to create a Github account, install git on your system, and generate an Access Token** (not needed if you're in class right now and you just want to download lecture code) 3. **Create a CS200 folder on your computer** to hold all of your assignments and example code.  We recommend putting it on your Desktop (Mac) or or C: Drive (Windows) for ease of access, but you can use any path that you can find easily.  **If you already made a CS200 folder, take a moment to find it now.**   # **How we provide code** There are two ways we might give you code to run on your system: - For **Homework/Project/Lab stencils**, we will give you a **Github Classroom link** (eg. `https://classroom.github.com/<something>`).  To use these, see [**Accepting Github Classroom Assignments**](https://docs.cs200.io/s/github-guide#Accepting-an-Assignment-on-GitHub-Classroom) - For **HW0, lecture code, or other examples**, we will directly provide a direct **Github Repository URL** (`eg. https://github.com/<something>`).  To use these, see **[Cloning from a Repository URL](https://docs.cs200.io/s/github-guide#Cloning-a-repository-by-URL)**. ### **Accepting an Assignment on GitHub Classroom** <!-- DO NOT REMOVE THIS SECTION: yes, it's redundant, but other guides may link here --> See our Github Guide, [here](https://docs.cs200.io/s/github-guide#Accepting-an-Assignment-on-GitHub-Classroom). ### Cloning a repository by URL <!-- DO NOT REMOVE THIS SECTION: yes, it's redundant, but other guides may link here --> See our Github Guide, [here](https://docs.cs200.io/s/github-guide#Cloning-a-repository-by-URL). # **Opening a Stencil in IntelliJ** 4. To open your project, open IntelliJ and go to **File > Open** and browse to the folder you cloned in the previous step.   Select the folder and click **Open.** 5. If IntelliJ displays a warning about security settings, click **“Trust Project”** to allow IntelliJ to open the code.  From there, IntelliJ should open its main window, which looks like this: ![](https://lh4.googleusercontent.com/mgVi1t-yP_esAXet5iEQHl6dQXTTEdkkwore794Xhn0JYHQk-SUqtdKucxTn23SFlP29jo8ra4nv_jT932ZDotbE5ep0R1BsMJ-fyw7Xs78lHSsCTm28epL_eGCe-7CSTtVCkjXF1W1ExHwXoG54FdU) 6. If you’re new to IntelliJ, this might look like a lot.  That’s okay!  We’ll learn more about the different parts in the coming weeks.  For now, look at the sidebar on the left, which shows all the files in the project.  **Expand the** `src` **folder (and** `sol`**, if it’s there)**--here you will see the Java files you’ll be using.   7. When downloading any new project, the first step is to make sure the project is set up correctly.  To do this, open any file with `Test` in the name (eg. `AnimalsTest`, in the image above) , which contains code that’s easy to run–we’ll use this to test our IDE settings.   8. At the top of the file, you may see a yellow bar at the top saying “Project JDK not defined.”  If so, click **“Setup SDK”** and select the highest version of Java available on your system (17 or higher), like this: ![](https://lh3.googleusercontent.com/1lD0zuJ1cDjMKFpPAwgTS_fVFOqKQA553ouTJXqIBsOvzuoh-1xCFjcVLzlX_ESlNVsQUReS1aUPuG5vo-fiZH6vKlVK_2zB70H--X_euzd9F7gZIWqZdVoXwFFRWQUeQgAzojsfPIeqyCf9-MK8V5Y) 9. Once you’ve set your SDK, IntelliJ should start automatically building and checking the project–this may take a minute or two, depending on the size of the project–you should see a progress bar at the bottom-right  of the IntelliJ window that will tell if it’s still working.   10. Once IntelliJ is done setting up, you should see any red underlines in the code disappear.  This means the code is ready to test!  To run the tests, **look at the top of the test file for a green icon** (circle or arrow) next to a line labeled `public class SomeThingHereTest { `like this (we’ll talk about what it all means soon!): ![](https://lh3.googleusercontent.com/9yEGWn2sEceipBNcy51VjYcbxpE0vZ4H9583smKZ8Lj8Tq-yq_71uLlop-AjbLVjQmqmeqWe3fBLkIwCzdX0gg12kHdgbLGH4zAgLGA7Ojnc33951XzWjByulo-6rFOEsliPJejps_2owLxaYYBjvvM) :::info **_Note:_** **If you don’t have a green icon, or the code has lots of red underlines:**  make sure you have set your SDK (step 9).   **If you still have issues, this might be an issue with the stencil project**–check the [FAQ section of the IntelliJ guide](https://docs.cs200.io/intellij-guide?both#Common-BugsFAQ) or the IntelliJ setup megathread on Ed to see if any of the issues match your situation.  If you still have questions, feel free to post in this thread on Ed or ask us in hours!   ::: 11. Click the green icon and select **Run** `SomethingHereTest` (where `SomethingHereTest` is the name of the file) 12. If all goes well, IntelliJ will build the project code and run any tests–this may take a minute.  Once it’s done, a window should pop up showing the status of the tests.  **You don’t need to know what the output means yet–we’ll unpack it all over time in class.**  For now, just look for a window to pop up like one of these: **Example with passing tests** ![](https://lh3.googleusercontent.com/TWXq2eZ0L5_4b05Oyj4VfNVNK0PM0QM-waJx5iVEQGJiE-pe_CWxcxGonRsrBwz_CGyHGx7gfskc8t4MurksMcq14YAtUDY2TmcIQ-NiKhlUjIOcPax_yFH852v_8ufSV71PQPCKD85UucHiyBG_2Yk) **Example with failing tests (okay for now!)** ![](https://lh5.googleusercontent.com/5uuWIE48Ks8hcJxU61wUCticCGxia0R7Aj5sP9CDVK2Px0nrrQUSTIPIUeTfqVep--fZ_tJh2sWIqeS_q115vUQb-63ZVwGxHnysWBrvE4bChaFtRz05nnKuNaiPFmxbA2J5kUqmtdJGZtoO57L-kFQ) 13. **You may see some tests listed as failing–this is okay!**  This will occur in stencil code, usually because there are some components that haven’t been implemented yet!  For now, we just need to run the tests, which proves our IDE is working, yay!   14. If you were able to run the tests (whether they pass or fail), you’re done!  You have now successfully tested running code in your IDE! \ **If IntelliJ produced an error instead of running the tests, there may be an issue with your IDE, or the stencil project itself.**  Check the [FAQ section of the IntelliJ guide](https://docs.cs200.io/intellij-guide?both#Common-BugsFAQ) or the IntelliJ setup megathread on Ed to see if any of the issues match your situation.  If you still have questions, feel free to post in this thread on Ed or ask us in hours!  *** _Please let us know if you find any mistakes, inconsistencies, or confusing language in this or any other CSCI0200 document by filling out the_ [_anonymous feedback form_](https://forms.gle/8HY7tDdgM98fk2e19)_._