COS 126 Coding Guidelines
-
To create a new Java class in IntelliJ, select LIFT → New Java Class from the menu.
-
Do not use any Java features, constructs, or coding patterns that have not yet been introduced or permitted in COS 126. Only the material covered in lectures, labs, and assigned readings is considered in scope.
-
Each line in
.java
and.txt
files must be no longer than 87 characters. Lines exceeding this limit may not be viewable on our online grading platform (codePost). -
Pay close attention to all warning and error messages - they can help you identify bugs and style issues. Your final submission should be free of any warnings or errors.
-
Be careful about output format (e.g., spelling, spacing, punctuation, new lines, etc.). Please follow assignment instructions precisely.
-
Submitting to TigerFile:
- Login into TigerFile using your OIT NetID and upload the specified files. To run the autograder, click the Check Submitted Files button:
-
The autograder compiles your code and checks that it conforms to the assignment specifications by running a battery of correctness tests. On some assignments, it also performs memory and timing tests. It also runs three static code analysis tools - Spotbugs, PMD, and Checkstyle - that automatically identify common bug patterns and style issues.
-
You should address all reported issues (including those reported for your
readme.txt
andacknowledgments.txt
files) and resubmit.- You may submit one file at a time or several files at a time.
- However, you may only click the Check Submitted Files button a total of twenty (20) times.
FAQ
Click the Question below to expand. Click the Question again to collapse.
Style
How should I format my code?
Answer:
- Indent your code consistently. Use four (4) spaces for each indentation level. IntelliJ does this automatically. Under the
Code
menu, selectReformat Code
- Do not exceed 87 characters per line. Long lines are hard to read and will annoy your grader. Use line breaks as needed. This rule also applies to the
readme.txt
file andacknowledgments.txt
file. - Use whitespace for readability. Insert blank lines to separate logical sections of your code. Insert a space between arithmetic operators. Until you get a feel for what is expected, use the output of Checkstyle as a guide.
How should I compose a program?
Answer:
- Use meaningful variable names. Each variable’s purpose should be obvious from its name, if possible. For example, name a variable
isOrdered
instead ofo
orordered
. One common exception to this rule is with loop-index variables: they often have short names, such asi
orj
. - Use straightforward logic and flow-of-control. For example, you should simplify the conditional statement:
if (isBlue == true) {...}
toif (isBlue) {...}
. - Follow directions. For example, if a command-line argument is specified as an integer, then assign it to a variable of type
int
; if the assignment says to use awhile
loop, use awhile
loop. - Follow output formats exactly. If the assignments specifies to print
Hello, World
, don’t printHello, World.
(i.e., prints a period.) You should also have the specified number of lines of output. This means that you should remove,or comment out, extraneous debugging print statements before submitting.) - Avoid magic numbers. A magic number is an unnamed numeric constant (other than
-1
,0
,1
, or2
, used in an obvious manner). Magic numbers make programs hard to debug and maintain. - Declare variables to minimize scope. For example, variables that are only used within a loop should be declared within the loop itself. In object-oriented programs (starting with the Classifier assignment), don’t declare a variable to be an instance variable if it is used only as a local variable in one method. All instance variables must be private.
How should I comment my code?
Answer:
- Include a brief comment above each code paragraph.
- Many experienced programmers write the comments before they write the code. Outlining or mapping out your program before you code is the best way to make sure you fully understand what the program needs to do and to avoid bugs.
- You should certainly comment as you code! This will help you better understand your approach, as well as help staff your approach when you attend instructors office hours or Lab TAs.
- Include a comment describing every method (whether public or private).
- Include a comment describing every static and instance variable (including those for nested classes).
Submission and Check All Submitted Files
What’s TigerFile?
Answer: A web-based system that you will use to submit assignments. Every assignment has its own submission link.Can I submit assignments via Canvas, email, or hard copy?
Answer No, all assignments submissions must be done via TigerFile.How do I successfully submit an assignment?
Answer: Remember to:
- Remove any extraneous debugging statements from your code.
- Upload all of the required files. The filenames are case-sensitive. Be sure to submit the most up-to-date version of your code.
- After testing on your computer, click the
Check Submitted Files
button to receive feedback from the autograder. Fix any errors. (Note - the autograder does NOT actually produce a grade, but does perform various tests in your code.) - Complete, sign and upload the
acknowledgments.txt
file to indicate that your solutions are ready to be graded. This is the only file that will contain any identifying information and only instructors can view this file.
What is a readme.txt
file?
Answer: It is a plain text file that contains a narrative description of your work. This is the first thing the grader will read. Each week, we’ll provide a template readme.txt
file. Be sure to answer any questions that it contains. Do not place any identifying information in the readme.txt
file - e.g., name, netid or email.
What is an acknowledgments.txt
file?
Answer: It is a plain text file that contains your acknowledgment of original work (as specified in Rights, Rules, Responsibilities, any citations, names and dates of those who provided help, a digital signature, etc. Submitting the acknowledgments.txt
indicates that you have stopped working on your assignment and your submitted work is ready to be graded. Your assignment will only be graded if the acknowledgments.txt
is submitted.
Which program should I use to edit the readme.txt
and acknowledgments.txt
files?
Answer: Use IntelliJ. Be careful to save the file as readme.txt
or acknowledgments.txt
and not as a .java
file. The .txt
file must be a plain text file. Note, Microsoft Word .doc
or .docx
formats and Mac TextEdit .rtf
formats will not be accepted. Please do not rename your .doc
, .docx
, or .rtf
file to .txt
as this will cause your file not to be readable by our system.
How do I submit an assignment after the deadline?
Answer: There is no need to contact the staff. Just submit theacknowledgments.txt
file when you have completed your assignment.
On assignments that allow partnering, how do I submit?
Answer: First, you must form a group by clicking the green Create Group button in TigerFile. You must do this even if you are working alone (a group of one). If you are working with a partner, add your partner as a group member. Your partner will receive an email with a link to confirm the partnership. Once you have created a group, any group member may submit.Can I correct my program and resubmit?
Answer: Absolutely. That’s the point of this system. There is no penalty for resubmitting files prior to the deadline.When I submit a file, TigerFile reports Filename is not in list. Why is it rejecting my submission?
Answer: Be sure the file has the correct name. Both the capitalization and .java extension are important. We recommend configuring your system to show the file extensions. Here are instructions for Mac and Windows).What exactly does the Check Submitted Files button in TigerFile do?
Answer: It compiles your code and checks that it conforms to the assignment specifications by running a battery of correctness tests. On some assignments, it also performs memory and timing tests. It also runs three static code analysis tools - Spotbugs, PMD, and Checkstyle that automatically identify common bug patterns and style issues. You may only click the Check Submitted Files button a total of twenty (20) times.Must I submit all of the required files to receive feedback?
Answer: No. The autograder will give feedback on whichever files you submit, provided that they compile.I receive various compiler errors and warnings. What does this mean?
Answer: Your programs should compile cleanly, with no errors or warnings. Consult an instructor or Lab TA if you are unsure how to fix them.I receive various FAILED messages in the correctness, timing, or memory tests. What does this mean?
Your program does not meet the assignment specifications on the tested inputs. Failing any of these tests will likely lead to a deduction. (Passing all of these tests is a good sign, but does not guarantee that your program is 100% correct; we run additional tests when grading.) Consult instructor or Lab TA if you do not understand the error message.I receive various SpotBugs, PMD, or Checkstyle warnings. What does this mean?
- Spotbugs is a program that looks for common bug patterns in your code. You should treat anything it reports as an error (though, occasionally there are false positives).
- PMD is a program that looks for common programming flaws in your code.
- Checkstyle is a program that looks for common style issues in your program. The appearance of a warning message does not necessarily lead to a deduction (and, in some cases, it does not even indicate an error). You should pay particular attention to the custom checks, which are specialized to each program. As you gain programming experience, you’ll get used to the myriad (and sometimes seemingly arbitrary) conventions that good programmers employ, and you will learn to like Checkstyle.
- Consult an instructor or Lab TA if you are unsure what an error/warning message means or how to fix it.
I receive the error Process took too long and was killed (output may be truncated). What could cause this?
Answer: This usually means that the autograder could not complete in the allocated amount of time. One common cause is an infinite loop. Another possibility is that your program produces an enormous amount of output, perhaps because you left in a debugging statement.When I click the Check Submitted Files button, I receive a failed to fetch NetworkError when attempting to fetch resources message. How can I fix that?
Answer: This is your browser’s way of telling you that you are not connected to the Internet.Testing
Do my programs need to handle every conceivable input?
Answer: No. Your program must handle all meaningful inputs, but you need not worry about meaningless ones. For example, when testingRGBtoCMYK.java
, we will always supply three command-line arguments that are integers between 0 and 255.
Do I have to test my code?
Answer: Yes. For some assignments, you will be given very clear instructions on how to implement the test client. In others, you will be asked to implement your own test client that tests the methods you have implemented. Although the autograder tests your code, you are expected to test your code before you use the autograder. For grading purposes, your test client will satisfy the requirements if it calls every public method in your code at least once in a meaningful way (by printing the return value, for example). For genuinely testing your code, you will often need to do more than that.Java Programming
Answer: No, your code should use only the Java language features previously introduced in the course. Answer: You must use the project folder with IntelliJ. This is provided as a .zip file. Often associated data files that are useful for testing are included. They are bundled together in a .zip file, which you will need to extract:Which Java programming environment should I use?
Answer: We strongly recommend using IntelliJ for this course. We can only provide support for IntelliJ.
How can I download a program from the textbook?
Answer: The booksite contains links to all of the Java programs in the textbook. Each link goes to an HTML file (such as UseArgument.java.html
) that is suitable for display in a browser. You can copy-and-paste the code into IntelliJ as needed, with appropriate attribution. The HTML file contains a link to the Java source file (such as UseArgument.java
); you can right click this link and save the file to your computer.
How should I read in user input?
Answer: It depends on the assignment. If the assignment specifies command-line arguments, your program should accept command-line arguments; if the assignment specifies standard input, your program should accept input from standard input. You will receive a significant deduction for not following these directions.
May I use (advanced) Java features that have not yet been covered in the course?
Project Files
How can I extract the
.zip
file associated with an assignment?
.zip
file listed on the assignment page. In Finder, view the directory containing the downloaded .zip
file. Some browsers will automatically unzip the .zip
file and create a project folder – which will have the same name without the .zip
extension – containing the individual files. (Some browsers may also delete the original .zip
file.) Otherwise, if you see the .zip
file but no project folder, double-click the .zip
file to create the project folder. You will want to create the .java files in this project folder..zip
file listed on the assignment page. In Explorer, view the directory containing the downloaded .zip
file. Right-click on the .zip
file and select Extract All…, which will ask you to choose the extraction location. This creates a new project folder – which will have the same name without the .zip
extension – containing the individual files.. (Do not double click the .zip
file—that browses the contents instead of extracting them.) You will want to create the .java
files in this project folder.