Overriding Class Class Static class Parents instance method

  • Slides: 48
Download presentation

 • 오버라이딩(Overriding) • "부모(Class)에서 정의한 메서드를 자식 Class에서 변경하는 것 • Static 메서드는

• 오버라이딩(Overriding) • "부모(Class)에서 정의한 메서드를 자식 Class에서 변경하는 것 • Static 메서드는 오버라이딩을 허용하지 않는다. class Parents { // instance method void func() { System. out. println("hello world"); } } class Child extends Parents { @Override void func() { System. out. println("Kim. Jun. Hyeon"); } }

 • to. String class Car { // instance variable String color; int price;

• to. String class Car { // instance variable String color; int price; Car(String c, int p) { this. color = c; this. price = p; } // 조상 클래스 (Object)에 정의된 접근성보다 같거나 넓어야 하므로, public @ Override public String to. String() { return "color: " + this. color + " price: " + this. price; } }

class Person implements Cloneable { // instance variable String name; int age; public Object

class Person implements Cloneable { // instance variable String name; int age; public Object clone() { Person a = new Person(); a. name = new String(this. name); a. age = this. age; return a; } }

 • 얕은 복사 예) public static void main(String[] args) { // TODO Auto-generated

• 얕은 복사 예) public static void main(String[] args) { // TODO Auto-generated method stub Array. List<String> test 1 = new Array. List<String>(); Array. List<String> test 2 = new Array. List<String>(); test 1. add("Kim"); test 1. add("Jun"); test 1. add("Hyeon"); test 2 = test 1; // 얕은 복사 - 둘 중에 한개만 수정해도 양쪽 다 적용 System. out. println(test 1); test 2. add("Lee"); System. out. println(test 1); }

 • 깊은 복사가 이루어져서 한쪽의 수정이 다른 한쪽에 영향을 주지 않는다. public static

• 깊은 복사가 이루어져서 한쪽의 수정이 다른 한쪽에 영향을 주지 않는다. public static void main(String[] args) { // TODO Auto-generated method stub Array. List<String> test 1 = new Array. List<String>(); Array. List<String> test 2 = new Array. List<String>(); Array. List<String> test 3 = new Array. List<String>(); test 1. add("Kim"); test 1. add("Jun"); test 1. add("Hyeon"); test 2 = test 1; test 3 = (Array. List<String>)test 1. clone(); System. out. println(test 1); test 2. add("Lee"); System. out. println(test 1); System. out. println(test 3); }

 • 깊은 복사의 또다른 예 // TODO Auto-generated method Array. List<String> test 1

• 깊은 복사의 또다른 예 // TODO Auto-generated method Array. List<String> test 1 = new Array. List<String> test 2 = new Array. List<String> test 3 = new test 1. add("Kim"); test 1. add("Jun"); test 1. add("Hyeon"); test 2. add. All(test 1); test 1. add("Lee"); System. out. println(test 1); System. out. println(test 2); stub Array. List<String>();

Math 클래스 Math. abs(double x) Math. ceil(double x) 값 올림 Math. floor 값 내림

Math 클래스 Math. abs(double x) Math. ceil(double x) 값 올림 Math. floor 값 내림 Math. round(double x) 반 올림 Math. max(double x, double y) 큰 쪽 반환 Math. min(double x, double y) 작은 값 반환 Math. pow(double x, double y) 제곱

 • Math. pow public class stu 02 { public static void main(String[] args)

• Math. pow public class stu 02 { public static void main(String[] args) { int x = 10; System. out. printf("10^2 => %. 2 fn", Math. pow(x, 2. )); } } • 반환 타입도 : double • %. 2 f : 소수점 2번째 자리까지만 출력

 • Math. ceil public class stu 03 { public static void main(String[] args)

• Math. ceil public class stu 03 { public static void main(String[] args) { double d. Data = 12. 123; System. out. printf("%fn", Math. ceil(d. Data)); // 13. 000000 } }

래퍼 클래스 (wrapper class) • 변수 • 기본형 (primitive) : 비객체 • 참조형 (reference

래퍼 클래스 (wrapper class) • 변수 • 기본형 (primitive) : 비객체 • 참조형 (reference type) Java Data Type ㄴ Primitive Type ㄴ Boolean Type(boolean) ㄴ Numeric Type ㄴ Integral Type ㄴ Integer Type(short, int, long) ㄴ Floating Point Type(float, double) ㄴ Character Type(char) ㄴ Reference Type ㄴ Class Type ㄴ Interface Type ㄴ Array Type ㄴ Enum Type ㄴ etc.

래퍼 클래스 (wrapper class) • Boxing • Un. Boxing

래퍼 클래스 (wrapper class) • Boxing • Un. Boxing

래퍼 클래스 (wrapper class) • 래퍼 클래스란 • 기본 자료형 (primitive data types)에 대한

래퍼 클래스 (wrapper class) • 래퍼 클래스란 • 기본 자료형 (primitive data types)에 대한 클래스 표현 기본형 래퍼클래스 Boolean char Charater byte Byte short Short int Integer long Long float Float double Double void Void 생성자

래퍼 클래스 (wrapper class) public class stu 04 { public static void main(String[] args)

래퍼 클래스 (wrapper class) public class stu 04 { public static void main(String[] args) { Integer i. Data = Integer. value. Of(10); System. out. printf("i. Data => %dn", i. Data) } }

자바 Random • 선언. next. Int() -2, 147, 483, 648 ~2, 147, 483, 647

자바 Random • 선언. next. Int() -2, 147, 483, 648 ~2, 147, 483, 647 . next. Int(10) 0 ~ 9 사이의 값 . nex. Int(20) - 10 -10 ~ 9 . next. Float() 0. 0 (포함) ~ 1. 0 (포함안함) . next. Float()*6 0. 0 (포함) ~ 5. 999999

자바 Random import java. util. Random; public class RN 02 { public static void

자바 Random import java. util. Random; public class RN 02 { public static void main(String[] args) { Random generater = new Random(); int dice; dice = generater. next. Int(6) + 1; // 1, . . . , 6 System. out. printf("dice => %dn", dice); } }

문제 • 번호 • 010 -1234 • 이메일 • sleep 4725@naver. com • 아이피

문제 • 번호 • 010 -1234 • 이메일 • sleep 4725@naver. com • 아이피 • 192. 168. 10. 155

풀이 • 번호 import java. util. regex. Pattern; public class STU 7 { public

풀이 • 번호 import java. util. regex. Pattern; public class STU 7 { public static void main(String[] args) { String reg. Exp = "(02|010)-\d{3, 4}-\d{4}"; String data = "010 -4725 -5886"; boolean result = Pattern. matches(reg. Exp, data); if (result) { System. out. println("패턴과 일치"); } else { System. out. println("패턴과 일치 하지 않습니다. "); } } }

풀이 • 이메일 import java. util. regex. Matcher; import java. util. regex. Pattern; public

풀이 • 이메일 import java. util. regex. Matcher; import java. util. regex. Pattern; public class STU 8 { public static void main(String[] args) { String reg. Exp = "\w+@\w+(\. \w+)"; String target. Email = "sleep 4725@naver. com"; boolean result = Pattern. matches(reg. Exp, target. Email); if (result) { System. out. println("일치"); } else { System. out. println("불일치"); } } }

풀이 • 아이피 import java. util. regex. Pattern; public class STU 9 { public

풀이 • 아이피 import java. util. regex. Pattern; public class STU 9 { public static void main(String[] args) { // 192. 168. 1. 123 String reg. Exp = "(\d{3})\. (\d{1, 3})"; String target. IP = "192. 168. 1. 123"; boolean result = Pattern. matches(reg. Exp, target. IP); if (result) { System. out. println("일치"); } else { System. out. println("불일치"); } } }

자바 정규식 regex import java. util. regex. *; public class RN 03 { public

자바 정규식 regex import java. util. regex. *; public class RN 03 { public static void main(String[] args) { //Pattern p = Pattern. compile(". S") System. out. println(Pattern. matches(". s", "as")); System. out. println(Pattern. matches(". s", "mk")); } }

자바 정규식 regex public class RN 05 { public static void main(String[] args) {

자바 정규식 regex public class RN 05 { public static void main(String[] args) { Pattern p = Pattern. compile("^[A-Za-z]{2}"); System. out. println(p. matcher("AApple")); } }

자바 정규식 regex import java. util. regex. *; public class RN 06 { public

자바 정규식 regex import java. util. regex. *; public class RN 06 { public static void main(String[] args) { Pattern p = Pattern. compile("(\d{6})-(\d{6})"); System. out. println(p. matcher("880120 -0000000")); } }

Date, Calendar • Date 클래스 • 날짜를 표현하는 클래스 1 import java. util. Date;

Date, Calendar • Date 클래스 • 날짜를 표현하는 클래스 1 import java. util. Date; public class STU 1 { public static void main(String[] args) { System. out. println("hello world"); Date today = new Date(); // 객체 생성 String str. Now = today. to. String(); System. out. println(str. Now); } } 2

Date, Calendar • Simple. Date. Format yyyy 2018 hh 7 MM 10 mm 41

Date, Calendar • Simple. Date. Format yyyy 2018 hh 7 MM 10 mm 41 dd 28 ss 34 import java. text. Simple. Date. Format; import java. util. Date; public class STU 2 { public static void main(String[] args) { Simple. Date. Format sdf = new Simple. Date. Format("yyyy-MM-dd hh: mm: ss"); Date today = new Date(); String str. Data = sdf. format(today); System. out. println(str. Data); } }

디렉토리 • 생성 (mkdir) import java. io. File; . . mkdir(); public static void

디렉토리 • 생성 (mkdir) import java. io. File; . . mkdir(); public static void main(String[] args) { File new. File = new File("C: \Users\sleep\Desktop\test. Study. Dir"); try { new. File. mkdir(); System. out. println("디렉토리 생성 성공"); } catch (Exception e) { System. out. println(e); } }

디렉토리 • 삭제 (delete) public static void main(String[] args) { File new. File =

디렉토리 • 삭제 (delete) public static void main(String[] args) { File new. File = new File("C: \Users\sleep\Desktop\test. Study. Dir"); try { new. File. delete(); } catch (Exception e) { System. out. println(e); }

디렉토리 • 디렉토리 조회 (ls) import java. io. File; public class STU 4 {

디렉토리 • 디렉토리 조회 (ls) import java. io. File; public class STU 4 { public static void main(String[] args) { File new. File = new File("C: \Users\sleep\Desktop\Java. Script"); File[] list. Of. Files = new. File. list. Files(); for (File f : list. Of. Files) { if (f. is. Directory()) { // 디렉토리 System. out. println("directory : " + f. get. Name()); } else if (f. is. File()) { // 일반 파일 System. out. println("file : " + f. get. Name()); } }

Calendar 클래스 • Calendar • 달력을 표현한 클래스 • 추상 (abstract) 클래스이므로 new 연산자를

Calendar 클래스 • Calendar • 달력을 표현한 클래스 • 추상 (abstract) 클래스이므로 new 연산자를 사용해서 인스턴스 생성 불가 import java. util. Calendar; Calendar now = Calendar. get. Instance(); now. get(Calendar. YEAR) 년도를 리턴 now. get(Calendar. MONTH)+1 월을 리턴 now. get(Calendar. DAY_OF_MONTH) 일을 리턴 now. get(Calendar. DAY_OF_WEEK) 요일을 리턴

Calendar 클래스 • Calendar now. get(Calendar. AM_PM) 0 : 오전 / 1 : 오후

Calendar 클래스 • Calendar now. get(Calendar. AM_PM) 0 : 오전 / 1 : 오후 now. get(Calendar. HOUR) 현재 시간 리턴 now. get(Calendar. MINUTE) 분 리턴 now. get(Calendar. SECOND) 초 리턴

My. SQL

My. SQL