「在 Java 裡,你可以寫命令,你也可以直接在代碼裡那些命令旁邊加上註解 (comment)。編譯器會完全忽略那些註解。程式運行的時候,所有的註解都會被忽略。



public class Home
    public static void main(String[] args)
        Now we'll display the phrase 'Amigo Is The Best' on the screen
        System.out.print("Amigo ");
        System.out.print("Is ");
        System.out.print("The ");

「我們加了『現在我們要把…』這個註解。註解的開頭用一個符號對 (/*) 標示,結尾則是用 (*/) 標示。程式被編譯時,編譯器會忽略在符號 /**/ 中間的所有東西。



「要在代碼裡加上註解還有一種方法。你可以使用兩個前斜線 (//)。」

public class Home
    public static void main(String[] args)
        System.out.print("Amigo ");
        System.out.print("Is The "); // This is also a comment

「在這裡,// 開始一直到有 // 符號的同一行結束前的代碼,都被視為註解。也就是說,沒有第二個符號對來『完成註解』。」


// I'm not responsible of this code. They made me write it, against my will.
// Dear future me. Please forgive me.
// I can't even begin to express how sorry I am.
// If I see something like this once more, I'll have a complete mental breakdown at work.
// If this condition is ever satisfied,
// please inform me for a reward. Phone: xxx-xxx-xxx.
// Dear maintainer:
// Once you are done trying to 'optimize' this routine,
// and have realized what a terrible mistake that was,
// please increment the following counter as a warning
// to the next guy:
// total_hours_wasted_here = 42
// When I wrote this, only God and I understood what I was doing
// Now, God only knows
// Sometimes I believe compiler ignores all my comments.
// I dedicate all this code, all my work, to my wife, Darlene, who will 
// have to support me and our three children and the dog once it gets 
// released into the public.
// Drunk, fix later
// Magic. Do not touch