자바 프로그래밍 언어에서 클래스들이 구현해야 하는 동작을 지정하는데 사용되는 추상 자료형
//인터페이스 : 형식만 있고 내용이 없음
interface A2{
//인터페이스에는 일반메서드를 정의할 수 없음
/*
public void make() {
System.out.println("make메서드");
}
*/
//추상메서드
public abstract void play(); //원형
void fun();
}
class B2 implements A2{
//추상메서드 구현
@Override
public void play() {
System.out.println("play메서드");
}
@Override
public void fun() {
System.out.println("fun메서드");
}
}
public class InterMain02 {
public static void main(String[] args) {
B2 bp = new B2();
bp.play();
bp.fun();
}
}
play메서드
fun메서드
날짜 정보를 얻을 수 있는 클래스를 알아보자
import java.util.Date;
public class Main {
public static void main(String[] args) {
Date now = new Date();
System.out.println(now);
}
}
Sat Apr 30 16:07:50 KST 2022
결과가 표준시로 출력되는 것을 볼 수 있는데
이것을 다른 표기 방법으로 나타낼 수도 있다
import java.util.Date;
public class Main {
public static void main(String[] args) {
Date now = new Date();
System.out.println(now);
// deprecated 되어 사용하지 않음
System.out.println(now.toLocaleString());
}
}
Sat Apr 30 16:30:29 KST 2022
2022. 4. 30. 오후 4:30:29
YYYY-MM-DD, 와 문화권에 맞는 출력이 나왔다
하지만, 이 메서드 에는 문제가 있는데
이런 식으로 메서드에 취소선이 적용되는데, 이유는
다음과 같이 DateFomat 메서드로 대체 되었기 때문이다.
참고 : https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Date.html
import java.text.DateFormat;
import java.util.Date;
public class Main {
public static void main(String[] args) {
Date now = new Date();
DateFormat df = DateFormat.getInstance();
String today = df.format(now);
System.out.println(today);
System.out.println("--------------------------");
df = DateFormat.getDateTimeInstance();
today = df.format(now);
System.out.println(today);
System.out.println("--------------------------");
df = DateFormat.getDateInstance();
today = df.format(now);
System.out.println(today);
System.out.println("--------------------------");
df = DateFormat.getTimeInstance();
today = df.format(now);
System.out.println(today);
System.out.println("--------------------------");
}
}
22. 4. 30. 오후 4:49
--------------------------
2022. 4. 30. 오후 4:49:37
--------------------------
2022. 4. 30.
--------------------------
오후 4:49:37
--------------------------
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Main {
public static void main(String[] args) {
Date now = new Date();
DateFormat df = DateFormat.getInstance();
String today = df.format(now);
SimpleDateFormat sf = new SimpleDateFormat("yyyy년MM월dd일 (E) HH:mm:ss");
today = sf.format(now);
System.out.println(today);
}
}
2022년04월30일 (토) 16:58:44