Java: Comments and Delimiters



Comment your code, let it well explained and clear to other developers when they will read.

In a few months you will notice that those "others" include you, when you do not remember anymore why you implemented the method like that.

  A comment is always good to explain what a passage means in your code, so you or someone else does not waste time trying to decipher. Just read the comment that explains its operation.

- Commenting

Well, at this late date you may have created several projects and outputs. Create a project called 'Test'. Let's try something, let's put this line here under the 'main' and see what happens: / / Hello, what happens if I write that? Test:

public class Test {

    //What will happen if I write this here?
    public static void main(String[] args) {
        System.out.println("I don't know, what will happen?");
    }
}

What we did was a comment.
Everything we put on the same line and after the two bars, '//', has no effect on the compilation/execution. You can even scolding Java it will run anyway.

So, for what I will use this if it will not influence in any way?
Well, in large projects, mainly academics and involving complex logic, it is difficult to understand what another programmer programmed.
The times seem hieroglyphics. Sometimes the subject is a magic math and you can not understand what someone did. Sometimes you create a complex algorithm and long, spends months without see it, then you will look back to your code, and you will not remember how you created it.
The comments are for this, write something like this before:
// the following method does this, this and that
// this class is used for those
// this algorithm takes these numbers, do these calculations and returns this operation

However, avoid comment on everything.

Do not discuss the obvious:
// I sat
// I pause to read the new
// function displays 'Hello' on the screen

Use comments for things that do not understand, like bizarre things, for example:
// A simple output following is a famous Brazilian in 2012
System.out.println ("Delicia, delicia...assim voce me mata. Ai, se eu te pego...Ai, ai , se eu te pego");

- Delimiters

Let's assume that you will create a complex algorithm, or copied an issue even in the IDE (not to have to keep looking at the book, the blog Programming Progressive or pdf).
Assuming that this comment has various lines, dozens. What's up?
Will create dozens of '//'?
// Question 08
// blog: Programming Progressive
// Outputs & prints
// of course Java
/  draw the letter P in a giant with the characters P

Of course not, it is very tiring. For that, there are the delimiters '/ *' and '* /' Anything you write in it will be disregarded. See:

/* Muppet Babies, 
we make our dreams come true 
Muppet Babies, we'll do the same for you 

Kermit: When your world looks kinda weird and you wish that you weren't there 
Piggy: Just close your eyes and make believe and you can be anywhere 

Kermit: I like adventure 
Piggy: I like romance 
Fozzie: I love great jokes 
Animal: Animal dance!! 
Scooter: I've got my computer 
Skeeter: I swing through the air 
Rowlf: I play the piano 
Gonzo: And I have blue hair 
Bunsen: Me, I invent things 
Beaker: Mee mee mee meee! 

Nanny: Is everything all right in here? 
All: Yes, Nanny. 

Muppet Babies, we make our dreams come true 
Muppet Babies, we'll do the same for you 

Muppet Muppet Muppet Muppet 
Babies Babies Babies Babies 
Make dreams come true.*/


public class Test {

    public static void main(String[] args) {
        System.out.println("I wanna back to my childhood");
    }
}

Note that NetBeans has a color different stresses in the part that is delimited, which is a comment, in fact.

Learn how to comment ('//') and use delimiters ('/*' and '*/')

No comments: