Code Comments in Java

I would hope by this point in the course that you worked out how to add code comments in Java… I’m sure you have. For those that haven’t, it’s simply //.

//This is a code comment

That is the very basic, we also have a few more options available to us

/**
* This is a class to explain code comments
*/publicclassN_CodeComments{//So in IntelliJ if you type /** and press <enter> you'll get this/**
* This is a method to explain code comments
* @param a this is the person's Name
* @param b this is the person's Age
*///IntelliJ will automatically create you some comments to fill in.//It knows your method has some parameters, so it includes them so you can add some contextpublicvoidCodeCommentMethod(Stringa,intb){// int c = 1; //If you press Ctrl+/ it will comment the line out/in}}

Using code comments is something that most developers frown upon. Their argument is that the code should be self-explanatory. Class, Methods and Variables should all be well named, so that’s immediately clear what they are for, or what they do. I can understand that stance. But you are new to Java, so add as many comments and you need, and keep adding them until you are comfortable enough not to.