본문 바로가기

Dev. Java

(76)
연습문제 - equls 메소드 구현 class Exercise9_1 {public static void main(String[] args){SutdaCard c1 = new SutdaCard(3, true);SutdaCard c2 = new SutdaCard(3, true);System.out.println("c1 = " + c1);System.out.println("c2 = " + c2);System.out.println("c1.equls(c2) = " + c1.equals(c2));} } class SutdaCard{int num;boolean isKwang;SutdaCard(){this(1, true);} SutdaCard(int num, boolean isKwang){this.num = num;this.isKwang = isKwan..
데이터 바인딩의 개념 및 특징 데이터 바인딩이란? - 한줄 정리 : 데이터와 사용자 UI를 연결하는 것 데이터 바인딩이 이루어지기 위해서는 저장 장소에 저장된 데이터를 읽어오는 역할을 수행하는 객체가 필요한데, 이를 데이터 원본(Data Source)라고 한다. 데이터 바인딩이란 무엇인가? .NET 2.0 에서 추가된 기능이다. 컨트롤(Control)의 프로퍼티와 내가 지정한 객체의 프로퍼티를 연결 해준다. - 즉, 컨트롤의 프로퍼티가 변경되면, 내 객체의 프로퍼티도 변경되고, 그 반대도 된다. 주의 해야 할 건, "Property 와 Property"의 연결이라는 것을 알아야 한다., 그래서, 데이터 바인딩은 어떤 일을 할 수 있는가? 하나의 값으로 여러개의 컨트롤 정보(프로퍼티)를 변경 할 수 있다. 화면에 출력되는 컨트롤 말고도..
StringBuffer 인스턴스의 비교 Stringbuffer 는 String으로 변환한 후 비교해야 한다. public class SBEx1 {public static void main(String[] args){StringBuffer sb = new StringBuffer();StringBuffer sb2 = new StringBuffer();if(sb == sb2){System.out.println("sb == sb2 ? true");}else{System.out.println("sb == sb2 ? false");}if(sb.equals(sb2)){System.out.println("sb.equals(sb2) ? true");}else{System.out.println("sb.equals(sb2) ? false");}String s =..
문자열 추출 기본 예제 public class StringEx9 {public static void main(String[] args){String fullName = "Hello.java";// fullName에서 . 의 위치를 찾는다.int index = fullName.indexOf('.');// fullName의 첫번째 글자부터 . 이 있는 곳까지 문자열을 추출한다.String fileName = fullName.substring(0, index);// . 의 다음 문자부터 시작해서 문자열의 끝까지 추출한다.String ext = fullName.substring(index+1); System.out.println(fullName + "의 확장자를 제외한 이름은 " + fileName); System.out.printl..
문자열 기본형 변환 - Integer public class StringEx8 {public static void main(String args[]){String[] numbers = {"1", "2", "3", "4", "5"};String result = "";int result2 = 0;for(int i=0; i< numbers.length; i++){result += numbers[i];result2 += Integer.parseInt(numbers[i]);}System.out.println("result = " + result);System.out.println("result2 = " + result2);} }
String 클래스 intern 메소드 String 클래스의 intern()은 String 인스턴스의 문자열을 'constant pool'에 등록하는 일을 한다.등록하고자 하는 문자열이 'constant pool'에 존재하는 경우에는 그 문자열의 주소값을 반환한다.즉 주소값이 같아져서 같은 객체로 인식하게 된다. public class StringEx3 {public static void main(String args[]){String s1 = "AAA";String s2 = new String("AAA");if(s1 == s2){System.out.println("s1 == s2 ? true");}else{System.out.println("s1 == s2 ? false");}s2 = s2.intern();System.out.println(..
int를 String으로 변환하는 방법 public class StringEX7 {public static void main(String args[]){int value = 100;String strValue = String.valueOf(value);// int를 String으로 변환한다.int value2 = 100;String strValue2 = value2 + "";// int를 String으로 변환하는 또 다른 방법System.out.println(strValue);System.out.println(strValue2);}}
데이터 복제 clone() 메소드 // Cloneable 인터페이스를 구현한 클래스의 인스턴스만 clone()을 통한 복제가 가능함class Point implements Cloneable{int x;int y;Point(int x, int y){this.x = x;this.y = y;}@Overridepublic String toString() {return "Point [x=" + x + ", y=" + y + "]";}public Object clone(){Object obj = null;try{obj = super.clone();}catch(CloneNotSupportedException e) {}return obj;}} public class CloneEx1 {public static void main(String args[])..