Skip to content
Jinho D. Choi edited this page Aug 28, 2017 · 27 revisions

Java Development Kit (JDK)

  • Download JDK 8 and install.

IntelliJ

  • Download the latest version of IntelliJ, install, and launch the program.
  • Create a new project called CS323:
    • Choose "Java" on the left pane.
    • Make sure the project SDK indicates a java version "1.8.x".
  • Right click on the src directory and create a package called utils.
  • Right click on the utils package and create a class called Utils.
  • Add the following methods to the Utils class:
    static public int getMiddleIndex(int beginIndex, int endIndex)
    {
        return beginIndex + (endIndex - beginIndex) / 2;
    }
    	
    static public void main(String[] args)
    {
        System.out.println(getMiddleIndex(0, 10));
    }
    
  • Run the program by choosing [Run -> Run].
  • If you see 5 on the console, your program is successfully run.

JUnit Test

  • Right click on the utils package and create a class called UtilsTest.
  • Add the following method to the UtilsTest class:
    @Test
    void getMiddleIndexTest()
    {
        assertEquals(Utils.getMiddleIndex(0, 10), 5);
    }
    
    • Make sure to include the @Test annotation. You must see @Test in red. Hover over and add JUnit 5.
    • Import the followings:
      import static org.junit.jupiter.api.Assertions.assertEquals;
      import org.junit.jupiter.api.Test;
      
  • Run the test by choosing [Run -> Run].
  • If you see a green bar with the message "1 test passed", your program passed the unit test.

How to change the JDK version in IntelliJ

  • Choose [File -> Project Structure].
  • Choose the java version you want for the project SDK. If the java version is not shown, click the New button and add.
  • Choose the project language level to the same java version.

Quiz

CS323: Data Structures and Algorithms

Instructor


Emory University

Clone this wiki locally