Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I am trying to format my code properly. I have already read the programming standards document and I believe that my code follows these rules. I have also used the Ctrl + Shift + F keys in Eclipse which should format the code automatically.

Could someone tell me if this looks ok? It would be nice to get some feedback back and to see if it is being created automatically. I already know that the program does work. Any help would be great. If someone knows a better way to format the code, it would be great to hear it as well.

public class UniString {
    public static void main(String[] args) {
        char[] det = { '\u20ac', '1', '1', '8' };
        // char[]det is an array of characters.

        for (char a : det) {
            /*
            * the for loop takes in the char values and prints them off in
            * order the "det" array enters into the for loop  through "det" ,
            * goes into char a and can be written to the console through
            * System.out.println(a).
            */
            System.out.print(a);
        }
        System.out.println();

        char[] name = { 'j', 'o', 'e' };
        // This is another char array.

        String nameString = new String(name);
        /*
        * The char array is made into a String by loading "name" into a String
        * class
        */

        String changeCase = nameString.toUpperCase();
        /*
        * The String "nameString" is changed to Upper case letters. The string
        * is then stored as "caseChange".
        */

        System.out.println(changeCase);
        // "caseChange" is printed out.
    }
}
share|improve this question
    
cheers for the edit. –  Rob Carrigan Oct 22 '13 at 17:56
add comment

3 Answers

up vote 1 down vote accepted

Comments rarely go under a piece of code. Move it above it.

Other than that I'd personally also put the opening parenthesis of the "for" loop right next to the "for:

for(char a : det) { }
share|improve this answer
add comment

I disagree with @user1021726: Keeping a space after the for keyword is good — it's a keyword, not a function. It should be kept more like return something than return(something).

Comments should go above the code that they refer to. Also, in multi-line comments, the asterisks should line up, like in the JavaDoc guide:

    /**
     * The for loop takes in the char elements of the "det"
     * array and prints them to the console using
     * System.out.print(a).  Afterwards, System.out.println()
     * adds a newline.  The code below should be equivalent
     * to System.out.println(new String(det)); — though
     * probably slower.
     */
    for (char a : det) {
        System.out.print(a);
    }
    System.out.println();
share|improve this answer
    
I absolutely agree. However, I noticed that you changed the multiline comments /* ... */ to JavaDoc comments /** ... */ although the comment refers to code, not a method, field or class. Does this have any special significance? –  amon Oct 22 '13 at 20:18
    
No, comments inside a method have absolutely no semantic significance, and are certainly not interpreted as JavaDoc. I just expect them to follow the same formatting conventions. I would be just as happy with multi-line // comments. –  200_success Oct 22 '13 at 22:34
    
I always use // comments within a method body to allow temporarily commenting out different sections in the method. –  Dave Jarvis Oct 28 '13 at 22:15
add comment
// char[]det is an array of characters.
// This is another char array.
...

These are so obvious things. In my opinion, code should have comments to justify "why's" of the code and not "what's" of it.

I feel none of the comments in the code are required. Those just make your code look verbose and do not have any meaning what so ever.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.