Java/📃 자바 입문

주석문

가지코딩 2025. 4. 30. 13:32

주석이란?

프로그램의 코드와 실행에는 영향을 주지 않는 문장

 

주석의 종류

  • 구현 주석
    • 행단위 주석 (// 를 해주면, 해당 행이 주석 처리됨 )
    • 블럭단위 주석 (/* 주석으로 사용할 내용 */ )
public class HeloWorld{
    public static void main(String[] args){
        System.out.println("HelloWorld");
        // 한 줄만 주석 처리합니다.
        // System.out.println("test");

        /* 여러 줄을 주석 처리합니다.*/
        /* System.out.println("1");       
        System.out.println("2");         
        System.out.println("3"); */
    }
}

 

 

  • 문서화 주석
    • /** 문서에 포함할 내용을 작성함 */
    • 문서화 주석은 클래스, 인터페이스 그리고 멤버 당 하나씩 가질 수 있고, 선언 바로 전에 작성
    • 문서화 주석 예
import java.io.*;

/**
* <h1>Add Two Numbers!</h1>
* The AddNum program implements an application that
* simply adds two given integer numbers and Prints
* the output on the screen.
* <p>
* <b>Note:</b> Giving proper comments in your program makes it more
* user friendly and it is assumed as a high quality code.
*
* @author  Zara Ali
* @version 1.0
* @since   2014-03-31
*/
public class AddNum {
   /**
   * This method is used to add two integers. This is
   * a the simplest form of a class method, just to
   * show the usage of various javadoc Tags.
   * @param numA This is the first paramter to addNum method
   * @param numB  This is the second parameter to addNum method
   * @return int This returns sum of numA and numB.
   */
   public int addNum(int numA, int numB) {
      return numA + numB;
   }

   /**
   * This is the main method which makes use of addNum method.
   * @param args Unused.
   * @return Nothing.
   * @exception IOException On input error.
   * @see IOException
   */
   public static void main(String args[]) throws IOException
   {

      AddNum obj = new AddNum();
      int sum = obj.addNum(10, 20);

      System.out.println("Sum of 10 and 20 is :" + sum);
   }
}

'Java > 📃 자바 입문' 카테고리의 다른 글

기본형 타입과 타입(형)변환  (0) 2025.04.30
상수  (0) 2025.04.30
변수  (0) 2025.04.30
자바란?  (0) 2025.04.30
프로그래머스 - 무료 | 자바 입문  (0) 2025.04.30