2Comment Your CodeWith small programs it may seem more trouble than it’s worth to add commentsHowever, developing the good habit of commenting your code will save you much grief in the future as your programs get more complex – I speak from experience!
3Here are a few suggestions as to why you should comment your code: Finding errors and the flow of your program is more efficient.Software is often developed as a team where people work on only parts of a large program. Other team members should be able to understand what your part does and how it does it without having to ask you. You would want the same.If you change jobs, you may be responsible for a piece of software you created for your previous job. You don’t want your past to haunt you because the “new guy” doesn’t know how your code worksIt makes marking your code easier!
4How to Comment in Java You can add comments in two ways: Using two forward slashes will comment everything after them on that line only:Example:This is not commented // This will be commentedThis is not commentedYou can create a block of comment starting with /* and ending with *//* This will be commentedThis is also commentedThis line is also commented */JCreator indicates a comment by turning it this green color
5What You Should Comment You should comment any part of your code that you feel may need some clarification onWhat I will be looking for in terms of commenting are:The Header Section: Should include - This class, Name, Block, Project NameMethods: What the method doesVariables and Constants: if name is not descriptive enoughClasses: What the class does (we’ll talk more about classes in the future)COMMENT YOUR CODE!
6Code Conventions Naming Conventions are part of Code conventions These are guidelines to follow when coding in Java
7Why Have Code Conventions Why Have Code Conventions? (From Code Conventions for the JavaTM Programming LanguageCode conventions are important to programmers for a number of reasons:80% of the lifetime cost of a piece of software goes to maintenance.Hardly any software is maintained for its whole life by the original author.Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly.If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create.
8Use these conventions for naming in your program from now on Naming ConventionsYou should be familiar with the conventions for the following Java elementsMethods, Classes, Variables and ConstantsThe information you need can be found at:Use these conventions for naming in your program from now on