1. ความคิดเห็นสองประเภท

เราควรเพิ่มคำสองสามคำให้กับสิ่งที่กล่าวไว้ข้างต้น

ใน Java คุณสามารถเขียนคำสั่งได้ แต่คุณยังสามารถเพิ่มความคิดเห็นในคำสั่งเหล่านั้นได้โดยตรงในโค้ด คอมไพเลอร์ไม่สนใจความคิดเห็นโดยสิ้นเชิง เมื่อโปรแกรมทำงาน ความคิดเห็นทั้งหมดจะถูกละไว้

นี่คือตัวอย่าง:

public class Home
{
   public static void main (String[] args)
   {
      /*
      Now we'll display the phrase 'Amigo is the Best'
      */
      System.out.print("Amigo ");
      System.out.print("is the ");
      System.out.print("Best");
   }
}

เราได้เพิ่มความคิดเห็น 'ตอนนี้เราจะแสดงวลี…' จุดเริ่มต้นของความคิดเห็นจะแสดงด้วยสัญลักษณ์คู่ ( /*) และจุดสิ้นสุด - โดย ( */) เมื่อโปรแกรมถูกคอมไพล์ คอมไพเลอร์จะละเว้นทุกอย่างระหว่างสัญลักษณ์/*และ*/

คุณสามารถเขียนสิ่งที่คุณต้องการในความคิดเห็น

โดยปกติแล้ว ความคิดเห็นในโค้ดจะเกี่ยวกับส่วนต่างๆ ของโค้ดที่เข้าใจยาก ความคิดเห็นบางอย่างประกอบด้วยสตริงมากมาย: เหล่านี้มักจะเขียนก่อนเมธอดเพื่ออธิบายความแตกต่างในการทำงาน

มีอีกหนึ่งวิธีในการเพิ่มความคิดเห็นในโค้ด คุณสามารถใช้เครื่องหมายทับสองตัว ( //)

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

ที่นี่ โค้ดที่ขึ้นต้นด้วย the //และจนถึงจุดสิ้นสุดของบรรทัดด้วย the //จะถือเป็นความคิดเห็น กล่าวอีกนัยหนึ่งคือไม่มีสัญลักษณ์คู่ที่สองที่ใช้ในการ 'เติมความคิดเห็น'


2. ความคิดเห็นจากชีวิตของโปรแกรมเมอร์

อย่างไรก็ตาม บางความคิดเห็นก็น่าสนใจจริงๆ

// I'm not responsible for this code. I was forced to write it against my will.
// Dear, future me. Please forgive me for this code.
// 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 programmer:
//
// When you finish 'optimizing' this subroutine
// and realize what a huge mistake it 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 only God knows.
// Sometimes it seems that the compiler is just ignoring all my comments
// I dedicate all my code and my work to my wife Darlene,
// who will have to provide for me, our three kids, and the dog when
// it gets released to the public.
// Magic. Don't touch.

ใช่ บางความเห็นตลกมาก