1. İki tür yorum

Yukarıda söylenenlere birkaç kelime eklememiz gerekiyor.

Java'da komutlar yazabilirsiniz, ancak doğrudan kodun içinden bu komutlara yorumlar da ekleyebilirsiniz. Derleyici yorumları tamamen yok sayar. Program çalıştırıldığında, tüm yorumlar atlanır.

İşte bir örnek:

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");
   }
}

'Şimdi ifadeyi göstereceğiz…' yorumunu ekledik. Yorumun başlangıcı bir çift sembolle ( /*) ve sonu - ( */) ile gösterilir. Program derlendiğinde, derleyici semboller arasındaki her şeyi atlar /*ve*/

Yoruma istediğinizi yazabilirsiniz.

Genellikle koddaki yorumlar, kodun anlaşılması zor olan bölümleriyle ilgilidir. Bazı yorumlar düzinelerce dizeden oluşur: bunlar genellikle nasıl çalıştıklarına ilişkin nüansları açıklamak için yöntemlerden önce yazılır.

Koda yorum eklemenin bir yolu daha var. İki eğik çizgi ( ) kullanabilirsiniz //.

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");
   }
}

//Burada, ile başlayan ve ile satırın sonuna kadar olan kod //yorum olarak kabul edilir. Başka bir deyişle, 'yorumu tamamlamak' için kullanılan ikinci bir sembol çifti yoktur.


2. Programcıların hayatından yorumlar

Bu arada, bazı yorumlar gerçekten ilginç.

// 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.

Evet bazı yorumlar çok komik.