커뮤니티

고용노동부, 산업인력공단과 함께하는 강원도 유일한 기업중심 IT전문교육기관 ICT융합캠퍼스만의 특별한교육입니다.
공인 IT숙련기술인의 다양한 접근방법으로 전문가다운 실무교육을 받을 수 있습니다.

Category

교육강좌

언어 Java - 주석과 세미콜론

페이지 정보

작성자 관리자 댓글 0건 조회 2,358회 작성일 20-06-10 11:01

본문

주석과 세미콜론

주석

주석(comment)은 로직에 대한 설명이나 코드를 비활성화 할 때 사용한다. 주석은 프로그래밍적으로 해석되지 않는다.

한줄 주석

1
2
3
4
public static void main(String[] args) {
// 두개의 변수가 같은 데이터 타입 일 때 아래와 같이 코드를 작성한다.
String a, b;
}

여러줄 주석

1
2
3
4
5
6
7
8
public static void main(String[] args) {
String a, b;
/*
a = "coding";
b = "everybody";
System.out.println(a+b);
*/
}

JavaDoc 주석

/**로 시작하는 주석은 JavaDoc 주석이라고 해서 자바의 문서를 만들 때 사용한다. 아래 예제는 다음 URL의 문서를 생성한다.

http://docs.oracle.com/javase/7/docs/api/java/io/PrintStream.html#println(long)

1
2
3
4
5
6
7
8
9
10
11
12
13
/**
* Prints an integer and then terminate the line. This method behaves as
* though it invokes <code>{@link #print(int)}</code> and then
* <code>{@link #println()}</code>.
*
* @param x The <code>int</code> to be printed.
*/
public void println(int x) {
synchronized (this) {
print(x);
newLine();
}
}

세미콜론

세미콜론은 문장(statement)의 끝을 의미한다. 자바에서는 문장의 끝에 세미콜론을 사용하지 않으면 컴파일 에러가 발생한다. 

1
2
3
4
5
6
7
8
// assignment statement
aValue = 8933.234;
// increment statement
aValue++;
// method invocation statement
System.out.println("Hello World!");
// object creation statement
Bicycle myBike = new Bicycle();

세미콜론을 이용하면 여러개의 문장을 한줄에 표현할 수 있다.

1
int a = 100; double b = 10.1;
  • 트위터로 보내기
  • 페이스북으로 보내기
  • 구글플러스로 보내기

답변목록

등록된 답변이 없습니다.