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.

예, 일부 댓글은 매우 재미 있습니다.