Microsoft PowerPoint - java2-lecture4.ppt [호환 모드]

Size: px
Start display at page:

Download "Microsoft PowerPoint - java2-lecture4.ppt [호환 모드]"

Transcription

1 인터페이스의필요성 Interface, Collections, Lambda 년가을학기 3/29/2017 박경신 인터페이스를이용하여다중상속구현 자바에서클래스다중상속불가 인터페이스는명세서와같음 인터페이스만선언하고구현을분리하여, 작업자마다다양한구현을할수있음 사용자는구현의내용은모르지만, 인터페이스에선언된메소드가구현되어있기때문에호출하여사용하기만하면됨 110v 전원아울렛처럼규격에맞기만하면, 어떻게만들어졌는지알필요없이전원연결에사용하기만하면됨 사용자 인터페이스 구현 1 구현 2 자바의인터페이스 인터페이스 (interface) 모든메소드가추상메소드인클래스 인터페이스선언 interface 키워드로선언 ex) public interface SerialDriver { 인터페이스의특징 인터페이스의메소드 public abstract 타입으로생략가능 인터페이스의상수 public static final 타입으로생략가능 인터페이스의객체생성불가 인터페이스에대한레퍼런스변수는선언가능 인터페이스선언 인터페이스구성멤버 상수필드 (constant field) 추상메소드 (abstract method) 디폴트메소드 (default method) 정적메소드 (static method) public interface 인터페이스명 { // 상수 (constant fields) 타입상수명 = 값 ; // 추상메소드 (abstract method) 리턴타입메소드명 ( 매개변수,..); // 디폴트메소드 (default method) default 리턴타입메소드명 ( 매개변수,..) {.. 내부구현.. // 정적메소드 (static method) static 리턴타입메소드명 ( 매개변수,..) {.. 내부구현..

2 인터페이스선언 public interface RemoteControl { int MAX_VOLUME = 10; // 상수 (constant fields) int MIN_VOLUME = 0; // 상수 (constant fields) // 추상메소드 (abstract method) void turnon(); void turnoff(); void setvolume(int volume); // 디폴트메소드 (default method) default void setmute(boolean mute) { if(mute) System.out.println(" 무음처리합니다."); else System.out.println(" 무음해제합니다."); // 정적메소드 (static method) static void changebattery() { System.out.println(" 건전지를교환합니다."); 인터페이스상속 인터페이스간에도상속가능 인터페이스를상속하여확장된인터페이스작성가능 인터페이스다중상속허용 interface MobilePhone { boolean sendcall(); boolean receivecall(); boolean sendsms(); boolean receivesms(); interface MP3 { void play(); void stop(); interface MusicPhone extends MobilePhone, MP3 { void playmp3ringtone(); public class MyPhone implements MusicPhone { public boolean sendcall() { ; public boolean receivecall() { ; public boolean sendsms() { ; public boolean receivesms() {.; public void play() {..; public void stop() {.; void playmp3ringtone() {.; 인터페이스구현 구현클래스정의 자신의객체가인터페이스타입으로사용할수있음 implements 키워드사용 여러개의인터페이스동시구현가능 상속과구현이동시에가능 public class 클래스명 implements 인터페이스명 { // 인터페이스에선언된추상메소드의실체메소드구현 추상메소드의실체메소드를작성하는방법 메소드의선언부가정확히일치해야함 인터페이스의모든추상메소드를재정의하는실체메소드를작성해야함 일부추상메소드만재정의할경우, 구현클래스는추상클래스 인터페이스구현및사용 public class Television implements RemoteControl { private int volume; // 필드 //turnon() 추상메소드의구현 public void turnon() { System.out.println("TV를켭니다."); //turnoff() 추상메소드의구현 public void turnoff() { System.out.println("TV를끕니다."); //setvolume() 추상메소드의구현 public void setvolume(int volume) { if(volume>remotecontrol.max_volume) { this.volume = RemoteControl.MAX_VOLUME; else if(volume<remotecontrol.min_volume) { this.volume = RemoteControl.MIN_VOLUME; else { this.volume = volume; System.out.println(" 현재 TV 볼륨 : " + volume); public class RemoteControlExample { public static void main(string[] args) { RemoteControl rc; rc = new Television(); rc = new Audio(); // 구현객체 // 구현객체

3 인터페이스구현및사용 public class Audio implements RemoteControl { private boolean mute; // // 필요시디폴트메소드재정의 public void setmute(boolean mute) { this.mute = mute; if(mute) { System.out.println("Audio 무음처리합니다."); else { System.out.println("Audio 무음해제합니다."); public class RemoteControlExample { public static void main(string[] args) { RemoteControl rc = null; rc = new Television(); rc.turnon(); // use abstract method rc.setmute(true); // use default method rc = new Audio(); rc.turnon(); // use abstract method rc.setmute(true); // use default method RemoteControl.changeBattery(); // use static method 인터페이스구현 익명구현객체 명시적인구현클래스작성생략하고바로구현객체를얻는방법 이름없는구현클래스선언과동시에객체생성 인터페이스명변수 = new 인터페이스명 () { // 인터페이스에선언된추상메소드의실체메소드구현 인터페이스의추상메소드들을모두재정의하는실체메소드가있어야 추가적으로필드와메소드선언가능하나익명객체안에서만사용 인터페이스변수로접근불가 public class RemoteControlExample { public static void main(string[] args) { RemoteControl rc = new RemoteControl() { // anonymous class public void turnon() { /* 실행문 */ public void turnoff() { /* 실행문 */ public void setvolume(int volume) { /* 실행문 */ ; 인터페이스의다중구현 다중인터페이스 (multi-interface) 구현클래스 구현클래스는다수의인터페이스를모두구현 객체는다수의인터페이스타입으로사용 public class 클래스명 implements 인터페이스명 A, 인터페이스명 B { // 인터페이스 A 에선언된추상메소드의실체메소드구현 // 인터페이스 B 에선언된추상메소드의실체메소드구현 인터페이스의다중구현 interface USBMouseInterface { void mousemove(); void mouseclick(); interface RollMouseInterface { void roll(); public class MouseDriver implements RollMouseInterface, USBMouseInterface { public void mousemove() {... public void mouseclick() {... public void roll() {... // 추가적으로다른메소드를작성할수있다. int getstatus() {... int getbutton() {...

4 인터페이스사용 인터페이스의사용 클래스의필드 (field) 생성자또는메소드의매개변수 (parameter) 생성자또는메소드의로컬변수 (local variable) MyClass mc = new MyClass( new public class MyClass { Television() ); // field RemoteControl rc = new Television(); // constructor parameter MyClass(RemoteControl rc) { this.rc = rc; // method public method() { // local variable RemoteControl rc = new Audio(); Comparable 인터페이스 Comparable 인터페이스는객체의비교를위한인터페이스로객체간의순서나정렬을하기위해서사용 public interface Comparable { // 이객체가다른객체보다크면 1, 같으면 0, 작으면 -1 을반환한다. int compareto(object other); class Person implements Comparable { public int compareto(object other) { Person p = (Person)other; if (this.age == p.age) return 0; else if (this.age > p.age) return 1; else return -1; Ex : Comparable 인터페이스 Ex : Comparable 인터페이스 public class Rectangle implements Comparable { public int width = 0; public int height = public String tostring() { return "Rect [w=" + width + ", h=" + height + "]"; public Rectangle(int w, int h) { width = w; height = h; System.out.println(this); public int getarea() { return width * public int compareto(object other) { Rectangle otherrect = (Rectangle)other; if (this.getarea() < otherrect.getarea()) return -1; else if (this.getarea() > otherrect.getarea()) return 1; else return 0; public class RectangleTest { public static void main(string[] args) { Rectangle r1 = new Rectangle(100, 30); Rectangle r2 = new Rectangle(200, 10); int result = r1.compareto(r2); if (result == 1) System.out.println(r1 + " 가더큽니다."); else if (result == 0) System.out.println(" 같습니다 "); else System.out.println(r2 + " 가더큽니다.");

5 Comparator 인터페이스 Comparator 인터페이스는다른두개의객체를비교하기위한인터페이스 public interface Comparator { // o1가 o2보다크면 1, 같으면 0, 작으면 -1을반환한다. int compare(object o1, Object o2); class AgeComparator implements Comparator { public int compare(object o1, Object o2) { Person p1 = (Person)o1; Person p2 = (Person)o2; if (s1.age == s2.age) return 0; else if (s1.age > s2.age) return 1; else return -1; 컬렉션 (collection) 의개념 컬렉션 요소 (element) 라고불리는가변개수의객체들의저장소 객체들의컨테이너라고도불림 요소의개수에따라크기자동조절 요소의삽입, 삭제에따른요소의위치자동이동 고정크기의배열을다루는어려움해소 다양한객체들의삽입, 삭제, 검색등의관리용이 컬렉션인터페이스와클래스 Collection<E> Map<K, V> Set<E> List<E> Queue<E> 인터페이스 클래스 HashSet<E> ArrayList<E> Vector<E> LinkedList<E> HashMap<K, V> Stack<E> Collection 인터페이스메소드 Method Description boolean add(object element) is used to insert an element in this collection. boolean addall(collection c) is used to insert the specified collection elements in the coll ection. boolean remove(object element) is used to delete an element from this collection. boolean removeall(collection c) is used to delete all the elements of specified collection fro m the collection. boolean retainall(collection c) is used to delete all the elements of invoking collection exce pt the specified collection. int size() return the total number of elements in the collection. void clear() removes the total no of element from the collection. boolean contains(object element) is used to search an element. boolean containsall(collection c) is used to search the specified collection in this collection. Iterator iterator() returns an iterator. Object[] toarray() converts collection into array. boolean isempty() checks if collection is empty. boolean equals(object element) matches two collection. int hashcode() returns the hashcode number for collection.

6 List 인터페이스메소드 Method Description void add(int index, Object elemen is used to insert an element into the list at index passed in t t) he index. boolean addall(int index, Collecti on c) is used to insert all elements of c into the list at the index p assed in the index. object get(int index) is used to return the object stored at the specified index wit hin the collection. object set(int index, Object eleme is used to assign element to the location specified by index nt) within the list. object remove(int index) is used to delete all the elements of invoking collection exce pt the specified collection. ListIterator listiterator() is used to return an iterator to the start of the list. ListIterator listiterator(int index) is used to return an iterator to the list that begins at the sp ecified index. 컬렉션과제네릭 컬렉션은제네릭 (Generics) 기법으로구현됨 컬렉션의요소는객체만가능 기본적으로 int, char, double 등의기본타입사용불가 JDK 1.5 부터자동박싱 / 언박싱기능으로기본타입사용가능 제네릭 (Generics) 특정타입만다루지않고, 여러종류의타입으로변신할수있도록클래스나메소드를일반화시키는기법 <E>, <K>, <V> : 타입매개변수 요소타입을일반화한타입 제네릭클래스사례 제네릭벡터 : Vector<E> E 에특정타입으로구체화 정수만다루는벡터 Vector<Integer> 문자열만다루는벡터 Vector<String> 컬렉션과자동박싱 / 언박싱 JDK 1.5 이전 기본타입데이터를 Wrapper 클래스를이용하여객체로만들어사용 Vector<Integer> v = new Vector<Integer>(); v.add(new Integer(4)); 컬렉션으로부터요소를얻어올때, Wrapper 클래스로캐스팅필요 Integer n = (Integer)v.get(0); int k = n.intvalue(); // k = 4 JDK 1.5부터 자동박싱 / 언박싱이작동하여기본타입값사용가능 Vector<Integer> v = new Vector<Integer> (); v.add(4); // 4 new Integer(4) 로자동박싱 int k = v.get(0); // Integer 타입이 int 타입으로자동언박싱, k = 4 제네릭의타입매개변수를기본타입으로구체화할수는없음 Vector<int> v = new Vector<int> (); // 오류 Vector<E> Vector<E> 의특성 java.util.vector <E> 에서 E 대신요소로사용할특정타입으로구체화 여러객체들을삽입, 삭제, 검색하는컨테이너클래스 배열의길이제한극복 원소의개수가넘쳐나면자동으로길이조절 Vector 에삽입가능한것 객체, null 기본타입은박싱 / 언박싱으로 Wrapper 객체로만들어저장 Vector 에객체삽입 벡터의맨뒤에객체추가 벡터중간에객체삽입 Vector 에서객체삭제 임의의위치에있는객체삭제가능 : 객체삭제후자동자리이동

7 Vector<E> 클래스의주요메소드 ArrayList<E> ArrayList<E> 의특성 java.util.arraylist, 가변크기배열을구현한클래스 <E> 에서 E 대신요소로사용할특정타입으로구체화 ArrayList 에삽입가능한것 객체, null 기본타입은박싱 / 언박싱으로 Wrapper 객체로만들어저장 ArrayList 에객체삽입 / 삭제 리스트의맨뒤에객체추가 리스트의중간에객체삽입 임의의위치에있는객체삭제가능 벡터와달리스레드동기화기능없음 다수스레드가동시에 ArrayList 에접근할때동기화되지않음 개발자가스레드동기화코드작성 ArrayList<E> 클래스의주요메소드 HashMap<K,V> HashMap<K,V> 키 (key) 와값 (value) 의쌍으로구성되는요소를다루는컬렉션 java.util.hashmap K는키로사용할요소의타입, V는값으로사용할요소의타입지정 키와값이한쌍으로삽입 키는해시맵에삽입되는위치결정에사용 값을검색하기위해서는반드시키이용 삽입및검색이빠른특징 요소삽입 : put() 메소드 요소검색 : get() 메소드 예 ) HashMap<String, String> 생성, 요소삽입, 요소검색 HashMap<String, String> h = new HashMap<String, String>(); h.put("apple", " 사과 "); // "apple" 키와 " 사과 " 값의쌍을해시맵에삽입 String kor = h.get("apple"); // "apple" 키로값검색. kor 는 " 사과

8 HashMap<K,V> 의주요메소드 LinkedList<E> LinkedList<E> 의특성 java.util.linkedlist E 에요소로사용할타입지정하여구체와 List 인터페이스를구현한컬렉션클래스 Vector, ArrayList 클래스와매우유사하게작동 요소객체들은양방향으로연결되어관리됨 요소객체는맨앞, 맨뒤에추가가능 요소객체는인덱스를이용하여중간에삽입가능 맨앞이나맨뒤에요소를추가하거나삭제할수있어스택이나큐로사용가능 컬렉션순차검색을위한 Iterator 인터페이스 Iterator<E> 인터페이스 Vector<E>, ArrayList<E>, LinkedList<E> 가상속받는인터페이스 리스트구조의컬렉션에서요소의순차검색을위한메소드포함 Iterator<E> 인터페이스메소드 컬렉션의순차검색을위한 Iterator Vector<Integer> v = new Vector<Integer>(); Iterator<Integer> it = v.iterator(); while(it.hasnext()) { // 모든요소방문 int n = it.next(); // 다음요소리턴... 또는 iterator() 메소드 iterator() 를호출하면 Iterator 객체반환 Iterator 객체를이용하여인덱스없이순차적검색가능 for (int n : v) {

9 Custom 클래스에대한 sort 메소드사용 개인적으로만든클래스에대해서컬렉션에추가하고, Collections.sort 기능을이용해서정렬하고싶다면 java.lang.comparable 인터페이스를구현해주어야함 public interface Comparable<T> { int compareto(t o); CompareTo(T o) 메소드는현객체를인자로주어진 o 와비교해서순서를정한후에정수 (int) 값을반환함 만약현객체가주어진인자보다작다면음수를반환 만약현객체가주어진인자와동일하다면 0 을반환 만약현객체가주어진인자보다크다면양수를반환 Custom 클래스에대한 sort 메소드사용 import java.util.collections; class A implements java.lang.comparable<a> { int num; String s; public A(String s, int n) { this.s = s; num = n; public int compareto(a a) { if (s.compareto(a.s) == 0) { if (num > a.num) return 1; else if (num < a.num) return -1; else return 0; else { return s.compareto(a.s); public String tostring() { return "String: " + s + "\t num = " + num; 람다식 람다식 (lambda expression) 은나중에실행될목적으로다른곳에전달될수있는코드블록이다. 람다식을이용하면메소드가필요한곳에간단히메소드를보낼수있다. 람다식의구문 람다식은 (argument-list) -> {body 구문사용하여작성 람다식의예 () -> System.out.println("Hello World"); (String s) -> { System.out.println(s); () -> 69 () -> { return ; ; (String s) -> { return Hello, + s; ;

10 람다식을사용한 sort 무명클래스를사용한방식 Comparator<Person> byname = new Comparator<Person>() public int compare(person o1, Person o2) { return o1.getname().compareto(o2.getname()); ; 람다식를사용한방식 Comparator<Person> byname = (Person o1, Person o2) -> o1.getname().compareto(o2.getname()); ; 람다식을사용한 sort 무명클래스를사용한방식 List<Person> plist = getpersonlist(); // sort by age plist.sort(new Comparator<Person>() public int compare(person o1, Person o2) { return o1.getage() - o2.getage(); ); 람다식을사용한방식 // sort by age plist.sort( (Person o1, Person o2) -> o1.getage() - o2.getage() ); plist.foreach( (person) -> System.out.println(person) );

Microsoft PowerPoint - java1-lecture6.ppt [호환 모드]

Microsoft PowerPoint - java1-lecture6.ppt [호환 모드] 실세계의인터페이스와인터페이스의필요성 인터페이스, 람다식 514760-1 2017 년가을학기 10/2/2017 박경신 정해진규격 ( 인터페이스 ) 에맞기만하면연결가능. 각회사마다구현방법은다름 정해진규격 ( 인터페이스 ) 에맞지않으면연결불가 인터페이스의필요성 인터페이스를이용하여다중상속구현 자바에서클래스다중상속불가 인터페이스는명세서와같음 인터페이스만선언하고구현을분리하여,

More information

Microsoft PowerPoint - java1-lecture6.ppt [호환 모드]

Microsoft PowerPoint - java1-lecture6.ppt [호환 모드] Class 접근제어 인터페이스 514760-1 2019 년봄학기 4/9/2019 박경신 Protected 는같은패키지내와파생클래스에서사용가능 public class Car { private boolean disel; // private은파생클래스에서사용하지못함 protected boolean gasoline; protected int wheel = 4; protected

More information

JAVA PROGRAMMING 실습 08.다형성

JAVA PROGRAMMING 실습 08.다형성 2015 학년도 2 학기 1. 추상메소드 선언은되어있으나코드구현되어있지않은메소드 abstract 키워드사용 메소드타입, 이름, 매개변수리스트만선언 public abstract String getname(); public abstract void setname(string s); 2. 추상클래스 abstract 키워드로선언한클래스 종류 추상메소드를포함하는클래스

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 명품 JAVA Essential 1 2 학습목표 1. 컬렉션과제네릭개념 2. Vector 활용 3. ArrayList 활용 4. HashMap 활용 5. Iterator 활용 6. 사용자제네릭클래스만들기 컬렉션 (collection) 의개념 3 컬렉션 요소 (element) 라고불리는가변개수의객체들의저장소 객체들의컨테이너라고도불림 요소의개수에따라크기자동조절

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 제네릭 배효철 th1g@nate.com 1 목차 제네릭 컬렉션 백터 ArrayList HashMap LinkedList Collections 클래스 제네릭만들기 컬렉션과자동박싱 / 언박싱 제네릭의장점 2 제네릭 특정타입만다루지않고, 여러종류의타입으로변신할수있도록클래스나메소드를일반화시키는기법 , , : 타입매개변수 요소타입을일반화한타입 제네릭클래스사례

More information

PowerPoint Presentation

PowerPoint Presentation 객체지향프로그래밍 인터페이스, 람다식, 패키지 ( 실습 ) 손시운 ssw5176@kangwon.ac.kr 예제 1. 홈네트워킹 public interface RemoteControl { public void turnon(); // 가전제품을켠다. public void turnoff(); // 가전제품을끈다. 인터페이스를구현 public class Television

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 인터페이스 배효철 th1g@nate.com 1 목차 인터페이스의역할 인터페이스선언 인터페이스구현 인터페이스사용 타입변환과다형성 인터페이스상속 디폴트메소드와인터페이스확장 2 인터페이스의역할 인터페이스란? 개발코드와객체가서로통신하는접점 개발코드는인터페이스의메소드만알고있으면 OK 인터페이스의역할 개발코드가객체에종속되지않게 -> 객체교체할수있도록하는역할 개발코드변경없이리턴값또는실행내용이다양해질수있음

More information

Microsoft PowerPoint - java2-lecture3.ppt [호환 모드]

Microsoft PowerPoint - java2-lecture3.ppt [호환 모드] 컬렉션 (collection) 의개념 Collections, Generic 514770 2018 년가을학기 10/1/2018 박경신 컬렉션 요소 (element) 라고불리는가변개수의객체들의저장소 객체들의컨테이너라고도불림 요소의개수에따라크기자동조절 요소의삽입, 삭제에따른요소의위치자동이동 고정크기의배열을다루는어려움해소 다양한객체들의삽입, 삭제, 검색등의관리용이

More information

(Microsoft PowerPoint - java1-lecture9.ppt [\310\243\310\257 \270\360\265\345])

(Microsoft PowerPoint - java1-lecture9.ppt [\310\243\310\257 \270\360\265\345]) 컬렉션 (collection) 의개념 Collections, Generic 514760-1 2016 년가을학기 11/24/2016 박경신 컬렉션 요소 (element) 라고불리는가변개수의객체들의저장소 객체들의컨테이너라고도불림 요소의개수에따라크기자동조절 요소의삽입, 삭제에따른요소의위치자동이동 고정크기의배열을다루는어려움해소 다양한객체들의삽입, 삭제, 검색등의관리용이

More information

Microsoft PowerPoint - java1-lecture8.ppt [호환 모드]

Microsoft PowerPoint - java1-lecture8.ppt [호환 모드] 컬렉션 (collection) 의개념 Collections, Generic 514760-1 2018 년봄학기 5/1/2018 박경신 컬렉션 요소 (element) 라고불리는가변개수의객체들의저장소 객체들의컨테이너라고도불림 요소의개수에따라크기자동조절 요소의삽입, 삭제에따른요소의위치자동이동 고정크기의배열을다루는어려움해소 다양한객체들의삽입, 삭제, 검색등의관리용이

More information

Microsoft PowerPoint - java1-lecture8.ppt [호환 모드]

Microsoft PowerPoint - java1-lecture8.ppt [호환 모드] 컬렉션 (collection) 의개념 Collections, Generic 514760-1 2019 년봄학기 4/30/2019 박경신 컬렉션 요소 (element) 라고불리는가변개수의객체들의저장소 객체들의컨테이너라고도불림 요소의개수에따라크기자동조절 요소의삽입, 삭제에따른요소의위치자동이동 고정크기의배열을다루는어려움해소 다양한객체들의삽입, 삭제, 검색등의관리용이

More information

Microsoft PowerPoint - java1-lecture8.ppt [호환 모드]

Microsoft PowerPoint - java1-lecture8.ppt [호환 모드] 컬렉션 (collection) 의개념 Collections, Generic 514760-1 2017 년가을학기 11/6/2017 박경신 컬렉션 요소 (element) 라고불리는가변개수의객체들의저장소 객체들의컨테이너라고도불림 요소의개수에따라크기자동조절 요소의삽입, 삭제에따른요소의위치자동이동 고정크기의배열을다루는어려움해소 다양한객체들의삽입, 삭제, 검색등의관리용이

More information

슬라이드 1

슬라이드 1 컬렉션프레임워크 (Collection Framework) 의정의 - 다수의데이터를쉽게처리할수있는표준화된방법을제공하는클래스들 - 데이터의집합을다루고표현하기위한단일화된구조 (architecture) - JDK 1.2 이전까지는 Vector, Hashtable, Properties와같은컬렉션클래스로서로다른각자의방식으로처리 - 컬렉션프레임워크는다수의데이터를다루는데필요한다양하고풍부한클래스들을제공하므로프로그래머의부담을상당부분덜어준다.

More information

PowerPoint Presentation

PowerPoint Presentation 객체지향프로그래밍 인터페이스, 람다식, 패키지 손시운 ssw5176@kangwon.ac.kr 인터페이스 인터페이스 (interafce) 는서로다른장치들이연결되어서상호데이터를주 고받는규격을의미한다 2 자바인터페이스 클래스와클래스사이의상호작용의규격을나타낸것이인터페이스이다 3 인터페이스의예 스마트홈시스템 (Smart Home System) 4 인터페이스의정의 public

More information

PowerPoint Presentation

PowerPoint Presentation Class - Property Jo, Heeseung 목차 section 1 클래스의일반구조 section 2 클래스선언 section 3 객체의생성 section 4 멤버변수 4-1 객체변수 4-2 클래스변수 4-3 종단 (final) 변수 4-4 멤버변수접근방법 section 5 멤버변수접근한정자 5-1 public 5-2 private 5-3 한정자없음

More information

PowerPoint Presentation

PowerPoint Presentation public class SumTest { public static void main(string a1[]) { int a, b, sum; a = Integer.parseInt(a1[0]); b = Integer.parseInt(a1[1]); sum = a + b ; // 두수를더하는부분입니다 System.out.println(" 두수의합은 " + sum +

More information

PowerPoint Presentation

PowerPoint Presentation 객체지향프로그래밍 클래스, 객체, 메소드 ( 실습 ) 손시운 ssw5176@kangwon.ac.kr 예제 1. 필드만있는클래스 텔레비젼 2 예제 1. 필드만있는클래스 3 예제 2. 여러개의객체생성하기 4 5 예제 3. 메소드가추가된클래스 public class Television { int channel; // 채널번호 int volume; // 볼륨 boolean

More information

(Microsoft PowerPoint - java2-lecture3.ppt [\310\243\310\257 \270\360\265\345])

(Microsoft PowerPoint - java2-lecture3.ppt [\310\243\310\257 \270\360\265\345]) Class Class, Collections 514770-1 2017 년봄학기 3/22/2017 박경신 클래스 (Class) 객체의속성과행위선언 객체의설계도혹은틀 객체 (Object) 클래스의틀로찍어낸실체 메모리공간을갖는구체적인실체 클래스를구체화한객체를인스턴스 (instance) 라고부름 객체와인스턴스는같은뜻으로사용 클래스구조 클래스접근권한, public 다른클래스들에서이클래스를사용하거나접근할수있음을선언

More information

5장.key

5장.key JAVA Programming 1 (inheritance) 2!,!! 4 3 4!!!! 5 public class Person {... public class Student extends Person { // Person Student... public class StudentWorker extends Student { // Student StudentWorker...!

More information

07 자바의 다양한 클래스.key

07 자바의 다양한 클래스.key [ 07 ] . java.lang Object, Math, String, StringBuffer Byte, Short, Integer, Long, Float, Double, Boolean, Character. java.util Random, StringTokenizer Calendar, GregorianCalendar, Date. Collection, List,

More information

<4D F736F F F696E74202D20C1A63038C0E520C5ACB7A1BDBABFCD20B0B4C3BC4928B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

<4D F736F F F696E74202D20C1A63038C0E520C5ACB7A1BDBABFCD20B0B4C3BC4928B0ADC0C729205BC8A3C8AF20B8F0B5E55D> Power Java 제 8 장클래스와객체 I 이번장에서학습할내용 클래스와객체 객체의일생직접 메소드클래스를 필드작성해 UML 봅시다. QUIZ 1. 객체는 속성과 동작을가지고있다. 2. 자동차가객체라면클래스는 설계도이다. 먼저앞장에서학습한클래스와객체의개념을복습해봅시다. 클래스의구성 클래스 (class) 는객체의설계도라할수있다. 클래스는필드와메소드로이루어진다.

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 Power Java 제 11 장상속 이번장에서학습할내용 상속이란? 상속의사용 메소드재정의 접근지정자 상속과생성자 Object 클래스 종단클래스 상속을코드를재사용하기위한중요한기법입니다. 상속이란? 상속의개념은현실세계에도존재한다. 상속의장점 상속의장점 상속을통하여기존클래스의필드와메소드를재사용 기존클래스의일부변경도가능 상속을이용하게되면복잡한 GUI 프로그램을순식간에작성

More information

PowerPoint Presentation

PowerPoint Presentation 자바프로그래밍 1 클래스와메소드심층연구 ( 실습 ) 손시운 ssw5176@kangwon.ac.kr 예제 1. 접근제어 class A { private int a; int b; public int c; // 전용 // 디폴트 // 공용 public class Test { public static void main(string args[]) { A obj = new

More information

JAVA PROGRAMMING 실습 05. 객체의 활용

JAVA PROGRAMMING 실습 05. 객체의 활용 public class Person{ public String name; public int age; } public Person(){ } public Person(String s, int a){ name = s; age = a; } public String getname(){ return name; } @ 객체의선언 public static void main(string

More information

gnu-lee-oop-kor-lec06-3-chap7

gnu-lee-oop-kor-lec06-3-chap7 어서와 Java 는처음이지! 제 7 장상속 Super 키워드 상속과생성자 상속과다형성 서브클래스의객체가생성될때, 서브클래스의생성자만호출될까? 아니면수퍼클래스의생성자도호출되는가? class Base{ public Base(String msg) { System.out.println("Base() 생성자 "); ; class Derived extends Base

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 Lab 4 ADT Design 클래스로정의됨. 모든객체들은힙영역에할당됨. 캡슐화 (Encapsulation) : Data representation + Operation 정보은닉 (Information Hiding) : Opertion부분은가려져있고, 사용자가 operation으로만사용가능해야함. 클래스정의의형태 public class Person { private

More information

PowerPoint Presentation

PowerPoint Presentation Package Class 1 Heeseung Jo 목차 section 1 패키지개요와패키지의사용 section 2 java.lang 패키지의개요 section 3 Object 클래스 section 4 포장 (Wrapper) 클래스 section 5 문자열의개요 section 6 String 클래스 section 7 StringBuffer 클래스 section

More information

q 이장에서다룰내용 1 객체지향프로그래밍의이해 2 객체지향언어 : 자바 2

q 이장에서다룰내용 1 객체지향프로그래밍의이해 2 객체지향언어 : 자바 2 객체지향프로그래밍 IT CookBook, 자바로배우는쉬운자료구조 q 이장에서다룰내용 1 객체지향프로그래밍의이해 2 객체지향언어 : 자바 2 q 객체지향프로그래밍의이해 v 프로그래밍기법의발달 A 군의사업발전 1 단계 구조적프로그래밍방식 3 q 객체지향프로그래밍의이해 A 군의사업발전 2 단계 객체지향프로그래밍방식 4 q 객체지향프로그래밍의이해 v 객체란무엇인가

More information

Microsoft PowerPoint - 2강

Microsoft PowerPoint - 2강 컴퓨터과학과 김희천교수 학습개요 Java 언어문법의기본사항, 자료형, 변수와상수선언및사용법, 각종연산자사용법, if/switch 등과같은제어문사용법등에대해설명한다. 또한 C++ 언어와선언 / 사용방법이다른 Java의배열선언및사용법에대해서설명한다. Java 언어의효과적인활용을위해서는기본문법을이해하는것이중요하다. 객체지향의기본개념에대해알아보고 Java에서어떻게객체지향적요소를적용하고있는지살펴본다.

More information

Design Issues

Design Issues 11 COMPUTER PROGRAMMING INHERIATANCE CONTENTS OVERVIEW OF INHERITANCE INHERITANCE OF MEMBER VARIABLE RESERVED WORD SUPER METHOD INHERITANCE and OVERRIDING INHERITANCE and CONSTRUCTOR 2 Overview of Inheritance

More information

JAVA 프로그래밍실습 실습 1) 실습목표 - 메소드개념이해하기 - 매개변수이해하기 - 새메소드만들기 - Math 클래스의기존메소드이용하기 ( ) 문제 - 직사각형모양의땅이있다. 이땅의둘레, 면적과대각

JAVA 프로그래밍실습 실습 1) 실습목표 - 메소드개념이해하기 - 매개변수이해하기 - 새메소드만들기 - Math 클래스의기존메소드이용하기 (   ) 문제 - 직사각형모양의땅이있다. 이땅의둘레, 면적과대각 JAVA 프로그래밍실습 실습 1) 실습목표 - 메소드개념이해하기 - 매개변수이해하기 - 새메소드만들기 - Math 클래스의기존메소드이용하기 ( http://java.sun.com/javase/6/docs/api ) 문제 - 직사각형모양의땅이있다. 이땅의둘레, 면적과대각선의길이를계산하는메소드들을작성하라. 직사각형의가로와세로의길이는주어진다. 대각선의길이는 Math클래스의적절한메소드를이용하여구하라.

More information

gnu-lee-oop-kor-lec11-1-chap15

gnu-lee-oop-kor-lec11-1-chap15 어서와 Java 는처음이지! 제 15 장컬렉션 컬렉션 (collection) 은자바에서자료구조를구현한클래스 자료구조로는리스트 (list), 스택 (stack), 큐 (queue), 집합 (set), 해쉬테이블 (hash table) 등이있다. 자바는컬렉션인터페이스와컬렉션클래스로나누어서제공한다. 자바에서는컬렉션인터페이스를구현한클래스도함께제공하므로이것을간단하게사용할수도있고아니면각자필요에맞추어인터페이스를자신의클래스로구현할수도있다.

More information

JAVA PROGRAMMING 실습 02. 표준 입출력

JAVA PROGRAMMING 실습 02. 표준 입출력 # 왜생겼나요..? : 절차지향언어가가진단점을보완하고다음의목적을달성하기위해..! 1. 소프트웨어생산성향상 객체지향소프트웨어를새로만드는경우이미만든개체지향소프트웨어를상속받거나객체를 가져다재사용할수있어부분수정을통해소프트웨어를다시만드는부담줄임. 2. 실세계에대한쉬운모델링 실세계의일은절차나과정보다는일과관련된많은물체들의상호작용으로묘사. 캡슐화 메소드와데이터를클래스내에선언하고구현

More information

Microsoft PowerPoint - java1-lecture6.ppt [호환 모드]

Microsoft PowerPoint - java1-lecture6.ppt [호환 모드] 실세계의인터페이스와인터페이스의필요성 인터페이스, 람다식, 패키지 514760-1 2016 년가을학기 10/13/2016 박경신 정해진규격 ( 인터페이스 ) 에맞기만하면연결가능. 각회사마다구현방법은다름 정해진규격 ( 인터페이스 ) 에맞지않으면연결불가 인터페이스의필요성 인터페이스를이용하여다중상속구현 자바에서클래스다중상속불가 인터페이스는명세서와같음 인터페이스만선언하고구현을분리하여,

More information

(8) getpi() 함수는정적함수이므로 main() 에서호출할수있다. (9) class Circle private double radius; static final double PI= ; // PI 이름으로 로초기화된정적상수 public

(8) getpi() 함수는정적함수이므로 main() 에서호출할수있다. (9) class Circle private double radius; static final double PI= ; // PI 이름으로 로초기화된정적상수 public Chapter 9 Lab 문제정답 1. public class Circle private double radius; static final double PI=3.141592; // PI 이름으로 3.141592 로초기화된정적상수 (1) public Circle(double r) radius = r; (2) public double getradius() return

More information

05-class.key

05-class.key 5 : 2 (method) (public) (private) (interface) 5.1 (Method), (public method) (private method) (constructor), 3 4 5.2 (client). (receiver)., System.out.println("Hello"); (client object) (receiver object)

More information

PowerPoint Presentation

PowerPoint Presentation Package Class 3 Heeseung Jo 목차 section 1 패키지개요와패키지의사용 section 2 java.lang 패키지의개요 section 3 Object 클래스 section 4 포장 (Wrapper) 클래스 section 5 문자열의개요 section 6 String 클래스 section 7 StringBuffer 클래스 section

More information

PowerPoint Presentation

PowerPoint Presentation 객체지향프로그래밍 클래스와메소드심층연구 ( 실습 ) 손시운 ssw5176@kangwon.ac.kr 예제 1. 접근제어 class A { private int a; int b; public int c; // 전용 // 디폴트 // 공용 public class Test { public static void main(string args[]) { A obj = new

More information

JAVA PROGRAMMING 실습 02. 표준 입출력

JAVA PROGRAMMING 실습 02. 표준 입출력 # 메소드의구조자주반복하여사용하는내용에대해특정이름으로정의한묶음 반환형메소드이름 ( 매개변수 ) { 실행문장 1; : 실행문장 N; } 메소드의종류 Call By Name : 메서드의이름에의해호출되는메서드로특정매개변수없이실행 Call By Value : 메서드를이름으로호출할때특정매개변수를전달하여그값을기초로실행하는메서드 Call By Reference : 메서드호출시매개변수로사용되는값이특정위치를참조하는

More information

Microsoft PowerPoint - java1-lab5-ImageProcessorTestOOP.pptx

Microsoft PowerPoint - java1-lab5-ImageProcessorTestOOP.pptx 2018 학년도 1 학기 JAVA 프로그래밍 II 514760-1 2018 년봄학기 5/10/2018 박경신 Lab#1 (ImageTest) Lab#1 은영상파일 (Image) 을읽어서정보를출력 Java Tutorials Lesson: Working with Images https://docs.oracle.com/javase/tutorial/2d/images/index.html

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 @ Lesson 2... ( ). ( ). @ vs. logic data method variable behavior attribute method field Flow (Type), ( ) member @ () : C program Method A ( ) Method B ( ) Method C () program : Java, C++, C# data @ Program

More information

A Tour of Java V

A Tour of Java V A Tour of Java V Sungjoo Ha April 3rd, 2015 Sungjoo Ha 1 / 28 Review First principle 문제가생기면침착하게영어로구글에서찾아본다. 타입은가능한값의집합과연산의집합을정의한다. 기본형이아니라면이름표가메모리에달라붙는다. 클래스로사용자정의타입을만든다. 프로그래밍은복잡도관리가중요하다. OOP 는객체가서로메시지를주고받는방식으로프로그램을구성해서복잡도관리를꾀한다.

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 Power Java 제 9 장생성자와접근제어 이번장에서학습할내용 생성자 정적변수 정적메소드 접근제어 this 클래스간의관계 객체가생성될때초기화를담당하는생성자에대하여살펴봅니다. 생성자 생성자 (contructor): 객체가생성될때에필드에게초기값을제공하고필요한초기화절차를실행하는메소드 생성자의예 class Car { private String color; // 색상

More information

Microsoft PowerPoint - Lect04.pptx

Microsoft PowerPoint - Lect04.pptx OBJECT ORIENTED PROGRAMMING Object Oriented Programming 이강의록은 Power Java 저자의강의록을사용했거나재편집된것입니다. Class 와 object Class 와객체 클래스의일생 메소드 필드 String Object Class 와객체 3 클래스 클래스의구성 클래스 (l (class): 객체를만드는설계도 클래스로부터만들어지는각각의객체를특별히그클래스의인스턴스

More information

Microsoft Word - java19-1-midterm-answer.doc

Microsoft Word - java19-1-midterm-answer.doc 중간고사 담당교수 : 단국대학교응용컴퓨터공학박경신 답은반드시답안지에기술할것. 공간이부족할경우반드시답안지몇쪽의뒤에있다고명기한후기술할것. 그외의경우의답안지뒤쪽이나연습지에기술한내용은답안으로인정안함. 답에는반드시네모를쳐서확실히표시할것. 답안지에학과, 학번, 이름외에본인의암호 (4자리숫자 ) 를기입하면성적공고시학번대신암호를 사용할것임. 1. 다음질문에답을하라. (55

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 제 5 장생성자와접근제어 1. 객체지향기법을이해한다. 2. 클래스를작성할수있다. 3. 클래스에서객체를생성할수있다. 4. 생성자를이용하여객체를초기화할수 있다. 5. 접근자와설정자를사용할수있다. 이번장에서만들어볼프로그램 생성자 생성자 (constructor) 는초기화를담당하는함수 생성자가필요한이유 #include using namespace

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 상속 배효철 th1g@nate.com 1 목차 상속개념 클래스상속 부모생성자호출 메소드재정의 final 클래스와 final 메소드 protected 접근제한자 타입변환과다형성 추상클래스 2 상속개념 상속 (Inheritance) 이란? 현실세계 : 부모가자식에게물려주는행위 부모가자식을선택해서물려줌 객체지향프로그램 : 자식 ( 하위, 파생 ) 클래스가부모 (

More information

10.0pt1height.7depth.3width±â10.0pt1height.7depth.3widthÃÊ10.0pt1height.7depth.3widthÅë10.0pt1height.7depth.3width°è10.0pt1height.7depth.3widthÇÁ10.0pt1height.7depth.3width·Î10.0pt1height.7depth.3width±×10.0pt1height.7depth.3width·¡10.0pt1height.7depth.3width¹Ö pt1height.7depth.3widthŬ10.0pt1height.7depth.3width·¡10.0pt1height.7depth.3width½º, 10.0pt1height.7depth.3width°´10.0pt1height.7depth.3widthü, 10.0pt1height.7depth.3widthº¯10.0pt1height.7depth.3width¼ö, 10.0pt1height.7depth.3width¸Þ10.0pt1height.7depth.3width¼Ò10.0pt1height.7depth.3widthµå

10.0pt1height.7depth.3width±â10.0pt1height.7depth.3widthÃÊ10.0pt1height.7depth.3widthÅë10.0pt1height.7depth.3width°è10.0pt1height.7depth.3widthÇÁ10.0pt1height.7depth.3width·Î10.0pt1height.7depth.3width±×10.0pt1height.7depth.3width·¡10.0pt1height.7depth.3width¹Ö pt1height.7depth.3widthŬ10.0pt1height.7depth.3width·¡10.0pt1height.7depth.3width½º, 10.0pt1height.7depth.3width°´10.0pt1height.7depth.3widthü, 10.0pt1height.7depth.3widthº¯10.0pt1height.7depth.3width¼ö, 10.0pt1height.7depth.3width¸Þ10.0pt1height.7depth.3width¼Ò10.0pt1height.7depth.3widthµå 기초통계프로그래밍 클래스, 객체, 변수, 메소드 hmkang@hallym.ac.kr 금융정보통계학과 강희모 ( 금융정보통계학과 ) 기초통계프로그래밍 1 / 26 자바구성파일 소스파일 소스파일 : 사용자가직접에디터에입력하는파일로자바프로그램언어가제공하는형식으로제작 소스파일의확장자는.java 임 컴파일 : javac 명령어를이용하여프로그래머가만든소스파일을컴파일하여실행파일.class

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 Power Java 제 22 장제네릭과컬렉션 이번장에서학습할내용 제네릭클래스 제네릭메소드 컬렉션 ArrayList LinkedList Set Queue Map Collections 클래스 일반적인하나의코드로다양한자료형을처리하는기법을살펴봅시다. 제네릭이란? 제네릭프로그래밍 (generic programming) 다양한타입의객체를동일한코드로처리하는기법 제네릭은컬렉션라이브러리에많이사용

More information

제11장 프로세스와 쓰레드

제11장 프로세스와 쓰레드 제9장자바쓰레드 9.1 Thread 기초 (1/5) 프로그램 명령어들의연속 (a sequence of instruction) 프로세스 / Thread 실행중인프로그램 (program in execution) 프로세스생성과실행을위한함수들 자바 Thread 2 9.1 Thread 기초 (2/5) 프로세스단위작업의문제점 프로세스생성시오버헤드 컨텍스트스위치오버헤드

More information

PowerPoint Presentation

PowerPoint Presentation Class : Method Jo, Heeseung 목차 section 1 생성자 (Constructor) section 2 생성자오버로딩 (Overloading) section 3 예약어 this section 4 메소드 4-1 접근한정자 4-2 클래스메소드 4-3 final, abstract, synchronized 메소드 4-4 메소드반환값 (return

More information

PowerPoint Presentation

PowerPoint Presentation public class SumTest { public static void main(string a1[]) { int a, b, sum; a = Integer.parseInt(a1[0]); b = Integer.parseInt(a1[1]); sum = a + b ; // 두수를더하는부분입니다 System.out.println(" 두수의합은 " + sum +

More information

untitled

untitled - -, (insert) (delete) - - (insert) (delete) (top ) - - (insert) (rear) (delete) (front) A A B top A B C top push(a) push(b) push(c) A B top pop() top A B D push(d) top #define MAX_STACK_SIZE 100 int

More information

Microsoft PowerPoint 자바-기본문법(Ch2).pptx

Microsoft PowerPoint 자바-기본문법(Ch2).pptx 자바기본문법 1. 기본사항 2. 자료형 3. 변수와상수 4. 연산자 1 주석 (Comments) 이해를돕기위한설명문 종류 // /* */ /** */ 활용예 javadoc HelloApplication.java 2 주석 (Comments) /* File name: HelloApplication.java Created by: Jung Created on: March

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 @ Lesson 4 (Object) (Class) (Instance) (Method) (Constructor) Memory 1 UML 1 @ & 1 (Real World) (Software World) @ &.. () () @ & 2 (Real World) (Software World) OOA/ Modeling Abstraction Instantiation

More information

Spring Boot/JDBC JdbcTemplate/CRUD 예제

Spring Boot/JDBC JdbcTemplate/CRUD 예제 Spring Boot/JDBC JdbcTemplate/CRUD 예제 오라클자바커뮤니티 (ojc.asia, ojcedu.com) Spring Boot, Gradle 과오픈소스인 MariaDB 를이용해서 EMP 테이블을만들고 JdbcTemplate, SimpleJdbcTemplate 을이용하여 CRUD 기능을구현해보자. 마리아 DB 설치는다음 URL 에서확인하자.

More information

자바 프로그래밍

자바 프로그래밍 5 (kkman@mail.sangji.ac.kr) (Class), (template) (Object) public, final, abstract [modifier] class ClassName { // // (, ) Class Circle { int radius, color ; int x, y ; float getarea() { return 3.14159

More information

No Slide Title

No Slide Title 상속 이충기 명지대학교컴퓨터공학과 상속 Q: 건설회사는기존아파트와조금다르거나추가적인특징들을가진새아파트를지을때어떻게하는가? A: 2 상속 상속 (inheritance) 은클래스들을연관시키는자연스럽고계층적인방법이다. 상속은객체지향프로그래밍의가장중요한개념중의하나이다. 상속은 은 이다 라는관계 (is-a relationship) 를나타낸다. 이관계를적용하여클래스들을상하관계로연결하는것이상속이다.

More information

PowerPoint Presentation

PowerPoint Presentation 자바프로그래밍 1 배열 손시운 ssw5176@kangwon.ac.kr 배열이필요한이유 예를들어서학생이 10 명이있고성적의평균을계산한다고가정하자. 학생 이 10 명이므로 10 개의변수가필요하다. int s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; 하지만만약학생이 100 명이라면어떻게해야하는가? int s0, s1, s2, s3, s4,

More information

PowerPoint Presentation

PowerPoint Presentation 객체지향프로그래밍 클래스, 객체, 메소드 손시운 ssw5176@kangwon.ac.kr 실제세계는객체로이루어진다. 2 객체와메시지 3 객체지향이란? 실제세계를모델링하여소프트웨어를개발하는방법 4 객체 5 객체란? 객체 (Object) 는상태와동작을가지고있다. 객체의상태 (state) 는객체의특징값 ( 속성 ) 이다. 객체의동작 (behavior) 또는행동은객체가취할수있는동작

More information

오버라이딩 (Overriding)

오버라이딩 (Overriding) WindowEvent WindowEvent 윈도우가열리거나 (opened) 닫힐때 (closed) 활성화되거나 (activated) 비활성화될때 (deactivated) 최소화되거나 (iconified) 복귀될때 (deiconified) 윈도우닫힘버튼을누를때 (closing) WindowEvent 수신자 abstract class WindowListener

More information

Microsoft PowerPoint - Lect07.pptx

Microsoft PowerPoint - Lect07.pptx 이강의록은 Power Java 저자의강의록을사용했거나재편집된것입니다. Package 개념 Package 묶는방법사용하기기본 Package Utility Package Generic Class Generic Method Collection ArrayList LinkedList Set Queue Map Collection Class 3 패키지 (package)

More information

C# Programming Guide - Types

C# Programming Guide - Types C# Programming Guide - Types 최도경 lifeisforu@wemade.com 이문서는 MSDN 의 Types 를요약하고보충한것입니다. http://msdn.microsoft.com/enus/library/ms173104(v=vs.100).aspx Types, Variables, and Values C# 은 type 에민감한언어이다. 모든

More information

(Microsoft PowerPoint - java1-lecture11.ppt [\310\243\310\257 \270\360\265\345])

(Microsoft PowerPoint - java1-lecture11.ppt [\310\243\310\257 \270\360\265\345]) 예외와예외클래스 예외처리 514760-1 2016 년가을학기 12/08/2016 박경신 오류의종류 에러 (Error) 하드웨어의잘못된동작또는고장으로인한오류 에러가발생되면 JVM실행에문제가있으므로프로그램종료 정상실행상태로돌아갈수없음 예외 (Exception) 사용자의잘못된조작또는개발자의잘못된코딩으로인한오류 예외가발생되면프로그램종료 예외처리 추가하면정상실행상태로돌아갈수있음

More information

교육자료

교육자료 THE SYS4U DODUMENT Java Reflection & Introspection 2012.08.21 김진아사원 2012 SYS4U I&C All rights reserved. 목차 I. 개념 1. Reflection 이란? 2. Introspection 이란? 3. Reflection 과 Introspection 의차이점 II. 실제사용예 1. Instance의생성

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 클래스 ( 계속 ) 배효철 th1g@nate.com 1 목차 인스턴스멤버와 this 객체의소멸과가비지 정적멤버와 static final 필드와상수 패키지 접근제한자 Getter와 Setter 2 목차 인스턴스멤버와 this 객체의소멸과가비지 정적멤버와 static final 필드와상수 패키지 접근제한자 Getter와 Setter 3 인스턴스멤버와 this 인스턴스멤버란?

More information

JVM 메모리구조

JVM 메모리구조 조명이정도면괜찮조! 주제 JVM 메모리구조 설미라자료조사, 자료작성, PPT 작성, 보고서작성. 발표. 조장. 최지성자료조사, 자료작성, PPT 작성, 보고서작성. 발표. 조원 이용열자료조사, 자료작성, PPT 작성, 보고서작성. 이윤경 자료조사, 자료작성, PPT작성, 보고서작성. 이수은 자료조사, 자료작성, PPT작성, 보고서작성. 발표일 2013. 05.

More information

java.lang 패키지 java.util 패키지 java.io 패키지 콜렉션 2

java.lang 패키지 java.util 패키지 java.io 패키지 콜렉션 2 java.lang 패키지 java.util 패키지 java.io 패키지 콜렉션 kkman@sangji.ac.kr 2 서로연관된클래스나인터페이스를하나의단위로묶는방법 자주사용되는클래스나인터페이스를위해패키지를제공 기본패키지 java.lang, java.util, java.io, java.net, java.awt, java.applet,... 사용자정의패키지 패키지이름은소문자로...

More information

<4D F736F F F696E74202D205B4A415641C7C1B7CEB1D7B7A1B9D65D35C0E5BBF3BCD3B0FAB4D9C7FCBCBA>

<4D F736F F F696E74202D205B4A415641C7C1B7CEB1D7B7A1B9D65D35C0E5BBF3BCD3B0FAB4D9C7FCBCBA> 명품 JAVA Programming 1 제 5 장상속과다형성 상속 (inheritance) 2 상속 상위클래스의특성 ( 필드, 메소드 ) 을하위클래스에물려주는것 슈퍼클래스 (superclass) 특성을물려주는상위클래스 서브클래스 (subclass) 특성을물려받는하위클래스 슈퍼클래스에자신만의특성 ( 필드, 메소드 ) 추가 슈퍼클래스의특성 ( 메소드 ) 을수정

More information

chap 5: Trees

chap 5: Trees 5. Threaded Binary Tree 기본개념 n 개의노드를갖는이진트리에는 2n 개의링크가존재 2n 개의링크중에 n + 1 개의링크값은 null Null 링크를다른노드에대한포인터로대체 Threads Thread 의이용 ptr left_child = NULL 일경우, ptr left_child 를 ptr 의 inorder predecessor 를가리키도록변경

More information

PowerPoint Presentation

PowerPoint Presentation public class SumTest { public static void main(string a1[]) { int a, b, sum; a = Integer.parseInt(a1[0]); b = Integer.parseInt(a1[1]); sum = a + b ; // 두수를더하는부분입니다 System.out.println(" 두수의합은 " + sum +

More information

Microsoft PowerPoint - lec12 [호환 모드]

Microsoft PowerPoint - lec12 [호환 모드] 제네릭 제네릭클래스 제네릭인터페이스 제네릭메소드 형매개변수의제한 어노테이션 어노테이션형태시스템정의어노테이션사용자정의어노테이션 kkman@sangji.ac.kr 2 제네릭 (generic) 클래스나메소드에자료형을매개변수형식으로사용할수있는기능 자료형과무관하게알고리즘을기술 예전에작성한알고리즘을쉽게재사용가능 어노테이션 (annotation) 프로그램요소에다양한종류의속성정보를추가하기위해서사용

More information

rmi_박준용_final.PDF

rmi_박준용_final.PDF (RMI) - JSTORM http://wwwjstormpekr (RMI)- Document title: Document file name: Revision number: Issued by: Document Information (RMI)- rmi finaldoc Issue Date: Status:

More information

ilist.add(new Integer(1))과 같이 사용하지 않고 ilist.add(1)과 같이 사용한 것은 자바 5.0에 추가된 기본 자료형과 해당 객체 자료 형과의 오토박싱/언박싱 기능을 사용한 것으로 오토박싱이란 자바 컴파일러가 객체를 요구하는 곳에 기본 자료형

ilist.add(new Integer(1))과 같이 사용하지 않고 ilist.add(1)과 같이 사용한 것은 자바 5.0에 추가된 기본 자료형과 해당 객체 자료 형과의 오토박싱/언박싱 기능을 사용한 것으로 오토박싱이란 자바 컴파일러가 객체를 요구하는 곳에 기본 자료형 바에 제네릭스(generics)를 도입하기 위한 연구는 이미 8년 전인 1996년부터라고 한다. 실제로 자바에 제네릭스를 도입하 는 몇 가지 방안들이 논문으로 나오기 시작한 것이 1998년 초임을 감 안하면 무려 8년이 지난 후에야 자바 5.0에 전격 채택되었다는 것은 이것이 얼마나 어려운 일이었나 하는 것을 보여준다. 자바의 스펙을 결정하는 표준화 절차인

More information

JAVA PROGRAMMING 실습 05. 객체의 활용

JAVA PROGRAMMING 실습 05. 객체의 활용 2015 학년도 2 학기 public class Person{ public String name; public int age; public Person(){ public Person(String s, int a){ name = s; age = a; public String getname(){ return name; @ 객체의선언 public static void

More information

JAVA PROGRAMMING 실습 09. 예외처리

JAVA PROGRAMMING 실습 09. 예외처리 2015 학년도 2 학기 예외? 프로그램실행중에발생하는예기치않은사건 예외가발생하는경우 정수를 0으로나누는경우 배열의크기보다큰인덱스로배열의원소를접근하는경우 파일의마지막부분에서데이터를읽으려고하는경우 예외처리 프로그램에문제를발생시키지않고프로그램을실행할수있게적절한조치를취하는것 자바는예외처리기를이용하여예외처리를할수있는기법제공 자바는예외를객체로취급!! 나뉨수를입력하시오

More information

A Tour of Java IV

A Tour of Java IV A Tour of Java IV Sungjoo Ha March 25th, 2016 Sungjoo Ha 1 / 35 Review First principle 문제가생기면침착하게영어로구글에서찾아본다. 타입은가능한값의집합과연산의집합을정의한다. 기본형이아니라면이름표가메모리에달라붙는다. 클래스로사용자정의타입을만든다. 프로그래밍은복잡도관리가중요하다. OOP 는객체가서로메시지를주고받는방식으로프로그램을구성해서복잡도관리를꾀한다.

More information

선형대수학 Linear Algebra

선형대수학  Linear Algebra 배열, 컬렉션, 인덱서 array, collection, indexer 소프트웨어학과 HCI 프로그래밍강좌 배열 배열 (array) 동일한자료형을다수선언 선언형식 데이터형식 [ ] 배열이름 = new 데이터형식 [ 개수 ]; int[ ] array = new int[5]; 인덱스 (index) 는 0 에서시작 scores[0] = 80; scores[1] =

More information

항상쌍 ( 키, 값 ) 으로만데이터를저장하는클래스 의최고조상 : Map - Map을조상으로하는클래스, HashTable, HashMap, LinkedHashMap, TreeMap 등은데이터를저장할때반드시 키 와 값 의쌍으로저장한다. - Map에저장되는 키 는중복되면안되

항상쌍 ( 키, 값 ) 으로만데이터를저장하는클래스 의최고조상 : Map - Map을조상으로하는클래스, HashTable, HashMap, LinkedHashMap, TreeMap 등은데이터를저장할때반드시 키 와 값 의쌍으로저장한다. - Map에저장되는 키 는중복되면안되 무엇이든다받아주는클래스 2 컬렉션프레임워크에저장된데이터를순차적으로처리하는방법 : Iterator 객체사용 - get() 메서드를사용하면 Iterator 를사용하지않아도원하는위치의데이터를찾을수있다. - get() 메서드는원하는데이터를찾는작업을항상처음데이터부터시작한다. - Iterator 는주소를사용해서현재탐색한위치부터새로운탐색을시작하므로, 위의 get() 메서드보다훨씬처리시

More information

Microsoft PowerPoint 장강의노트.ppt

Microsoft PowerPoint 장강의노트.ppt 클래스와객체 클래스와객체 객체 : 우리주변의어떤대상의모델 - 예 : 사람, 차, TV, 개 객체 = 상태 (state) + 행동 (behavior) - 예 : 개의상태 - 종자, 이름, 색개의행동 - 짖다, 가져오다 상태는변수로행동은메소드로나타냄 객체는클래스에의해정의된다. 클래스는객체가생성되는틀혹은청사진이다. 2 예 : 클래스와객체 질문 : 클래스와객체의다른예는?

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 클래스 ( 계속 ) 배효철 th1g@nate.com 1 목차 인스턴스멤버와 this 객체의소멸과가비지 정적멤버와 static final 필드와상수 패키지 접근제한자 Getter와 Setter 2 목차 인스턴스멤버와 this 객체의소멸과가비지 정적멤버와 static final 필드와상수 패키지 접근제한자 Getter와 Setter 3 인스턴스멤버와 this 인스턴스멤버란?

More information

예제 2) Test.java class A intvar= 10; void method() class B extends A intvar= 20; 1"); void method() 2"); void method1() public class Test 3"); args) A

예제 2) Test.java class A intvar= 10; void method() class B extends A intvar= 20; 1); void method() 2); void method1() public class Test 3); args) A 제 10 장상속 예제 1) ConstructorTest.java class Parent public Parent() super - default"); public Parent(int i) this("hello"); super(int) constructor" + i); public Parent(char c) this(); super(char) constructor

More information

12-file.key

12-file.key 11 2 ,, (Generic) (Collection) : : : :? (String).. java.lang.stringbuffer. s String s = "abcd"; s = s + "e"; a b c d e a b c d e ,., "910359,, " "910359" " " " " (token) (token),, (delimiter). java.util.stringtokenizer

More information

11 템플릿적용 - Java Program Performance Tuning (김명호기술이사)

11 템플릿적용 - Java Program Performance Tuning (김명호기술이사) Java Program Performance Tuning ( ) n (Primes0) static List primes(int n) { List primes = new ArrayList(n); outer: for (int candidate = 2; n > 0; candidate++) { Iterator iter = primes.iterator(); while

More information

JAVA PROGRAMMING 실습 07. 상속

JAVA PROGRAMMING 실습 07. 상속 상속 부모클래스에정의된필드와메소드를자식클래스가물려받는것 슈퍼클래스 (superclass) 특성을물려주는상위클래스 서브클래스 (subclass) 특성을물려받는하위클래스 슈퍼클래스에자신만의특성 ( 필드, 메소드 ) 추가 슈퍼클래스의특성 ( 메소드 ) 을수정 = 오버라이딩구체화 class Phone 전화걸기전화받기 class MobilePhone 전화걸기전화받기무선기지국연결배터리충전하기

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 Power Java 제 7 장클래스와객체 이번장에서학습할내용 객체지향이란? 객체 메시지 클래스 객체지향의장점 String 클래스 객체지향개념을완벽하게이해해야만객체지향설계의이점을활용할수있다. 실제세계는객체로이루어진다. 객체지향이란? 실제세계를모델링하여소프트웨어를개발하는방법 절차지향과객체지향 절차지향프로그래밍 (procedural programming): 문제를해결하는절차를중요하게생각하는방법

More information

슬라이드 1

슬라이드 1 정적메모리할당 (Static memory allocation) 일반적으로프로그램의실행에필요한메모리 ( 변수, 배열, 객체등 ) 는컴파일과정에서결정되고, 실행파일이메모리에로드될때할당되며, 종료후에반환됨 동적메모리할당 (Dynamic memory allocation) 프로그램의실행중에필요한메모리를할당받아사용하고, 사용이끝나면반환함 - 메모리를프로그램이직접관리해야함

More information

Microsoft PowerPoint - 6주차.pptx

Microsoft PowerPoint - 6주차.pptx 1 6 주차 클래스상속 유전적상속과객체지향상속 2 그래요우리를꼭닮았어요 아빠의유산이다. 나를꼭닮았군 유산상속 유전적상속 : 객체지향상속 생물 동물 식물 상속받음 어류사람나무풀 유전적상속과관계된생물분류 C++ 에서의상속 (Inheritance) 3 C++ 에서의상속이란? 클래스사이에서상속관계정의 객체사이에는상속관계없음 기본클래스의속성과기능을파생클래스에물려주는것

More information

슬라이드 1

슬라이드 1 UNIT 16 예외처리 로봇 SW 교육원 3 기 최상훈 학습목표 2 예외처리구문 try-catch-finally 문을사용핛수있다. 프로그램오류 3 프로그램오류의종류 컴파일에러 (compile-time error) : 컴파일실행시발생 럮타임에러 (runtime error) : 프로그램실행시발생 에러 (error) 프로그램코드에의해서해결될수없는심각핚오류 ex)

More information

슬라이드 1

슬라이드 1 -Part3- 제 4 장동적메모리할당과가변인 자 학습목차 4.1 동적메모리할당 4.1 동적메모리할당 4.1 동적메모리할당 배울내용 1 프로세스의메모리공간 2 동적메모리할당의필요성 4.1 동적메모리할당 (1/6) 프로세스의메모리구조 코드영역 : 프로그램실행코드, 함수들이저장되는영역 스택영역 : 매개변수, 지역변수, 중괄호 ( 블록 ) 내부에정의된변수들이저장되는영역

More information

Microsoft PowerPoint - C++ 5 .pptx

Microsoft PowerPoint - C++ 5 .pptx C++ 언어프로그래밍 한밭대학교전자. 제어공학과이승호교수 연산자중복 (operator overloading) 이란? 2 1. 연산자중복이란? 1) 기존에미리정의되어있는연산자 (+, -, /, * 등 ) 들을프로그래머의의도에맞도록새롭게정의하여사용할수있도록지원하는기능 2) 연산자를특정한기능을수행하도록재정의하여사용하면여러가지이점을가질수있음 3) 하나의기능이프로그래머의의도에따라바뀌어동작하는다형성

More information

PowerPoint Presentation

PowerPoint Presentation 객체지향프로그래밍 클래스와메소드심층연구 손시운 ssw5176@kangwon.ac.kr 접근제어 클래스안에변수나메소드들을누구나사용할수있게하면어떻게될까? 많은문제가발생할것이다. ( 예 ) 국가기밀서류를누구나보도록방치하면어떻게될까? 2 접근제어 접근제어 (access control): 다른클래스가특정한필드나메소드에접근하는 것을제어하는것 3 멤버수준에서의접근제어 4

More information

1. 객체의생성과대입 int 형변수 : 선언과동시에초기화하는방법 (C++) int a = 3; int a(3); // 기본타입역시클래스와같이처리가능 객체의생성 ( 복습 ) class CPoint private : int x, y; public : CPoint(int a

1. 객체의생성과대입 int 형변수 : 선언과동시에초기화하는방법 (C++) int a = 3; int a(3); // 기본타입역시클래스와같이처리가능 객체의생성 ( 복습 ) class CPoint private : int x, y; public : CPoint(int a 6 장복사생성자 객체의생성과대입객체의값에의한전달복사생성자디폴트복사생성자복사생성자의재정의객체의값에의한반환임시객체 C++ 프로그래밍입문 1. 객체의생성과대입 int 형변수 : 선언과동시에초기화하는방법 (C++) int a = 3; int a(3); // 기본타입역시클래스와같이처리가능 객체의생성 ( 복습 ) class CPoint private : int x, y;

More information

chap10.PDF

chap10.PDF 10 C++ Hello!! C C C++ C++ C++ 2 C++ 1980 Bell Bjarne Stroustrup C++ C C++ C, C++ C C 3 C C++ (prototype) (type checking) C C++ : C++ 4 C C++ (prototype) (type checking) [ 10-1] #include extern

More information

Network Programming

Network Programming Part 5 확장된 Network Programming 기술 1. Remote Procedure Call 2. Remote Method Invocation 3. Object Request Broker 2. Java RMI

More information

슬라이드 1

슬라이드 1 CHAP 6: 큐 yicho@gachon.ac.kr 1 큐 (QUEUE) 큐 : 먼저들어온데이터가먼저나가는자료구조 선입선출 (FIFO: First-In First-Out) ( 예 ) 매표소의대기열 Ticket Box 전단 () 후단 () 2 큐 ADT 삽입과삭제는 FIFO 순서를따른다. 삽입은큐의후단에서, 삭제는전단에서이루어진다. 객체 : n 개의 element

More information

<4D F736F F F696E74202D2036C0CFC2B05FB0B4C3BCC1F6C7E2C7C1B7CEB1D7B7A1B9D62E707074>

<4D F736F F F696E74202D2036C0CFC2B05FB0B4C3BCC1F6C7E2C7C1B7CEB1D7B7A1B9D62E707074> 객체지향프로그램밍 (Object-Oriented Programming) 1 C++ popular C 객체지향 (object oriented) C++ C : 상위계층언어특징 + 어셈블리언어특징 C++ : 소프트웨어개발플랫폼에객체지향개념제공 객체지향 : 자료와이들자료를어떻게다룰것인지따로생각하지않고단지하나의사물로생각 형 변수가사용하는메모리크기 변수가가질수있는정보

More information

Microsoft PowerPoint - 04-UDP Programming.ppt

Microsoft PowerPoint - 04-UDP Programming.ppt Chapter 4. UDP Dongwon Jeong djeong@kunsan.ac.kr http://ist.kunsan.ac.kr/ Dept. of Informatics & Statistics 목차 UDP 1 1 UDP 개념 자바 UDP 프로그램작성 클라이언트와서버모두 DatagramSocket 클래스로생성 상호간통신은 DatagramPacket 클래스를이용하여

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 명품 JAVA Essential 1 2 학습목표 1. 객체지향상속과자바상속개념이해 2. 클래스상속작성및객체생성 3. protected 접근지정 4. 상속시생성자의실행과정 5. 업캐스팅과 instanceof 연산자 6. 메소드오버라이딩과동적바인딩의이해및활용 7. 추상클래스 8. 인터페이스 상속 (inheritance) 3 객체지향상속 자식이부모유전자를물려받는것과유사한개념

More information

슬라이드 1

슬라이드 1 10. 숫자와정적변수, 정적메소드 학습목표 정적메소드와정적변수상수래퍼클래스포매팅 숫자는정말중요합니다 Math 클래스 출력방식조절 String 을수로변환하는방법 수를 String 으로변환하는방법 정적메소드 정적변수 상수 (static final) Math 메소드 거의 전역메소드 (global method) 인스턴스변수를전혀사용하지않음 인스턴스를만들수없음 Math

More information