Once you click post assignment, learners in the selected class will immediately be able to see and complete this assignment
Back to Classroom
Comments
AP® Computer Science A (Java) Course
Engineers From These Top Companies and Universities Trust EXLskills
1M+ Professionals | 100+ Institutions
This is the EXLskills free and open-source AP® (Advanced Placement®) Java Course. It guides learners via explanation, demonstration, and thorough practice, from no more than a basic understanding of Java, to a moderate level of essential coding proficiency. It is a substantial amount of coursework that represents a typical year of high school-level study or a semester of a University computer science course. This course may also be used to prepare for the AP® Computer Science A exam.
-->
Is this course FREE?
Yes, this a 100% free course that you can contribute to on GitHub here!
A "comment" is a message written to a human reader of the program. A comment is denoted by // at the beginning of the line. Those two characters (//) and everything that follows on the one line are disregarded by the Java compiler. Please take a look at the example below showing the use of comments.
CommentsExample.java
package exlcode;
public class CommentsExample {
/* Comment Block
You can write as much as you want inside the comment block
*/
// this is another example of a comment
public static void main (String[] args){
// this will not print because it is a comment
// System.out.println("Hello!");
System.out.println("Hello World!");
}
}
In the example above, some comments span for more than one line. To get the Java compiler to ignore multiple lines, we use /* at the beginning of the comment and */ at the end of the numerous lines of comments. When using this method to add a lengthy comment, make sure there are no characters between '/' and '*'. The /* and */ can start and stop anywhere on a line. Everything between the pair is a comment ignored by the compiler.
In addition to marking an actual comment in this way, we can also use the comment functionality for debugging. If we run into a situation where the program has a syntax error, one way to search for the root of the error is to remove some of the code from being compiled by turning it into a comment. If the modified program works as expected, the error must be in the section of code that was made into a comment. From there, we can decrease the amount of code in the comments until we pinpoint the error. Please remember this useful and important method for debugging long lines of code.