Expand All Collapse All


Java
Which version of Java must I use?
Any version of Java 8 to Java 11 should be fine, provided you don’t use any exotic features. Our autograder uses OpenJDK 11.
Which Java programming environment should I use?
We recommend our customized IntelliJ programming environment for Mac OS X, Windows, and Linux. If you followed our step-by-step instructions, then everything should be configured and ready to go.

If you prefer to use another environment (such as Eclipse or Sublime), that’s perfectly fine—just be sure that you know how to do the following:

How do I configure IntelliJ to access the libraries in algs4.jar?
If you use the provided IntelliJ project, you should be ready to go. Note that the provided IntelliJ project is configured to automatically add (and remove) import statements as needed, so you won’t type import statements explicitly.
What’s the Project link?
Each assignment has its own Project link, located in the menu at top. It contains an IntelliJ project that you can use to develop your program. It may also contain supplemental test clients and data files (that you can use even if you do not use IntelliJ).
I haven’t programmed in Java in a while. Which material do I need to remember?
For a review of our Java programming model (including our input and output libraries), read Sections 1.1 and 1.2 of Algorithms, 4th Edition.
I’ve never programmed in Java before. Should I continue with the course?
That depends. You will need to write your programs in Java to receive feedback from the autograder. Perhaps you can use this course as an opportunity to learn Java.
Where can I find the Java source code and documentation for the algorithms, data structures, and I/O libraries from lecture and the textbook?
They are in algs4.jar. Here are links to the source code and Javadoc.
Submission and Feedback
How do I create a ZIP file for submission to Coursera?
Here are three approaches:

  • Mac OS X.
    • Select the required files in the Finder.
    • Right-click and select Compress 3 Items.
    • Rename the resulting file to hello.zip.

  • Windows.
    • Select the required files in Windows Explorer.
    • Right-click and select Send to -> Compressed (zipped) folder.
    • Rename the resulting file to percolation (the .zip extension is automatic).

  • Command line (Linux or Mac OS X or Windows Git Bash).
    • Change to the directory containing the required .java files.
    • Execute the command: zip hello.zip *.java.
Which style and bug checkers does the autograder use? How can I configure my system to use them?
The autograder uses the following tools:

Here is some guidance for installing on your system.

Note that Checkstyle inspects the source code; SpotBugs inspects the compiled code.
Will I receive a deduction if I don’t adhere to the course rules for formatting and commenting my code?
The autograder (and IntelliJ) provide style feedback to help you become a better programmer. The autograder, however, does not typically deduct for stylistic flaws.
HelloWorld
Can I print text other than "Hello, World"?
No.
HelloGoodbye
I get the error Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0. What does this mean?
Did you forget to type a command-line argument when you executed the program?
RandomWord
Is there an idiomatic way to read all strings from standard input?
while (!StdIn.isEmpty()) {
    String s = StdIn.readString();
    ...
}
What is standard input and standard output?
Standard input and utput are mechanisms that your system uses to communicate between a program and its environment. The library calls System.out.println() and StdOut.println() print text to standard output; the library call StdIn.readString() reads text from standard input.
while (!StdIn.isEmpty()) {
    String s = StdIn.readString();
    ...
}
What is redirection?
By default, standard input comes from the keyboard and standard output is sent to the screen. You can change this behavior by using redirection.