나를 기록하다
article thumbnail
Published 2022. 11. 6. 16:27
[JAVA] 주석과 세미콜론 Java
반응형

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

한줄 주석 // 사용

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;

 

반응형

'Java' 카테고리의 다른 글

[JAVA] 상수의 데이터 타입  (1) 2022.11.06
[JAVA] 데이터 타입  (0) 2022.11.06
[JAVA]변수  (0) 2022.11.06
[JAVA]숫자, 문자와 문자열, 이스케이프  (0) 2022.11.06
[JAVA] 첫 언어로 선택한 자바 - 생활코딩  (0) 2022.11.06
profile

나를 기록하다

@prao

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!

profile on loading

Loading...