728x90

 


Hashtable : 검색이 용이하다.
   
 Key  Value
 "id"  "Object"

Method

  put(key, vlaue)  //Hashtable에서 값을 넣음
  get(key)            //Hashtable에서 값을 가져옴

  int size()  Hashtable의 key갯수 얻기
  boolean contains(Object obj) throws NullPointException  : Hashtable 에 Obj가 포함되어있는가? 
                                                                                                있으면 true 없으면 false 를 리턴
  boolean containsKey(Object key)   : Hashtable 에 key필드가 포함되어 있으면 true를 리턴
  boolean containsValue(Object value)    :  Hashtable에 value가 있으면 true를 리턴


import java.util.*;
class HashtableTest_1
{
 public static void main( String [] args )
 {
  Hashtable ht = new Hashtable();
  ht.put("id","kim");   //  kim을 String 으로 입력해도  객체로 저장됨.
  ht.put("pwd","123");
  ht.put("addr","서울 특별시 노원구 공릉동");
  
  System.out.println(ht.get("id"));
  System.out.println(ht.get("pwd"));
  System.out.println(ht.get("addr"));
  
  Hashtable ht2 = new Hashtable();
  ht2.put("one",new Integer(1));  //값을 객체로 넣어야 되니까..Wrapper쓴다.
  ht2.put("two",new Integer(2));
  ht2.put("three",new Integer(3));

  Integer I3 = (Integer)ht2.get("three");
  System.out.println(I3.toString());
 }// end main
 

}

728x90


String 


  int length() : 문자열 길이 구함..  필드 length와 혼동주의!

  boolean equals(Object obj) : String 클래스 비교
  boolean equalsIgnoreCase(Object obj) : 대소문자 구문 않고 비교

  String substring(int start) : start부터 끝까지 문자열 발췌 subString으로 혼동주의!
  String substring(int start, int end) : start부터 end 직전까지 문자열 발췌

  String concat(String str) : 문자열 결합
  String replace(char old, char new) : old문자을 new문자로 치환

  String toLowerCase() : 소문자로 변환
  String toUpperCase() : 대문자로 변환

  char charAt(int index) : index번째 문자 반환


class StringTest_1
{
 public  static void main(String args[])
 {
  String s1 = "Hello";
  String s2 = "Good";
  System.out.println(s1.length());
  System.out.println(s1.concat(s2)); // s1과s2를 합침
  
  System.out.println(s1.replace('e','a'));
  
  System.out.println(s1.toLowerCase());
  System.out.println(s2.toUpperCase());
  
  String str1 = new String("이름 홍길동");
  System.out.println(str1);
  System.out.println(str1.replace("홍길동","저팔계"));
 }
}



String 비교
같은 내용의 문자열 상수를 하나의 프로그램 소수에서
두번이상 사용하게 되면 한번만 메모리에 할당하고 이를 공유한다.
String str = "hello";

new String()으로 객체 생성하게되면 별도의 기억 공간을 확보한다.
String str = new String("hello");



class StringTest_2
{
 public static void main( String [] args )
 {
  String s1 = "Good";  // s1과 s2 주소가 같다. 왜냐면 문자열 상수이기 때문에... 메모리 절약 차원에서
  String s2 = "Good";
  
  if(s1 == s2)  
  {
   System.out.println("같다");
  }else
  {
   System.out.println("틀리다");
  }
  
  String s3 = new String("hello");  //s1과 s2 주소가 다르다 왜나면  동적할당 했으므로.
  String s4 = new String("hello");
  
  if(s3 == s4)
  {
   System.out.println("같다");
  }else
  {
   System.out.println("틀리다");
  }
 }// end main

}



class StringTest_3
{
 public static void main( String [] args )
 {
  String s1 = new String("Hello");
  String s2 = new String("Hello");
  
  System.out.println("-String형의 레퍼런스 변수가 참조하는 인스턴스가 같은지 비교-");
  
  if(s1 == s2) // 객체가 가리키는 주소값 비교
  {
   System.out.println("같다");
  }else
  {
   System.out.println("같지않다");
  }
  
  System.out.println("- String형의 데이터값(내용) 비교 -");
  
  if(s1.equals(s2)) //객체에 들어있는 내용 비교,  String 클래스 객체는 객체 자체가 문자열이다.
  {
   System.out.println("같다");
  }else
  {
   System.out.println("같지않다.");
  }
 }// end main
}

728x90

 


자바 모든 클래스는 내부적으로 Object를 상속 받는다.

메서드
  getClass() : 객체의 클래스 이름을 class형으로 반환
  hashCode() : 자바 객체를 식별하는 정수값인 hashcode를 반환
  toString() : 객체의 문자열을 반환

  Object clone() : 객체복사
  boolean equals(Object obj) : 두 객체의 내용이 동일한지 비교할때 사용

  void notify()  :  현제 스레드가 일을 다 했는지 알려준다, 그러면 대기하고 있던 스레드가 수행된다.
  void notifyAll() : 현제 스레드가 일을 다했다는 것을 모두에게 알려준다, 그러면 대기하고 있던 스레드가 수행된다.
  void wait() :  스레드를 기다리게 한다.  

  void finalize() : 객체를 더이상 사용하지 않을때 가비지컬랙션 기능 수행한다. 


class Point
{
 
}

class ObjectTest
{
 public static void main( String [] args )
 {
  System.out.println("-----startPt 객체 정보-----");
  Point startPt = new Point();
  System.out.println("클래스 이름: "+ startPt.getClass());//클래스이름을 구한다.
  System.out.println("해쉬코드 :" + startPt.hashCode());//자바는 객체를 식별하기 위해 해쉬코드를 같는다.
                                                        //해쉬코드는 검색이 용이하다.
  System.out.println("객체 문자열 :"+startPt.toString()); // 객체를 문자열로 반환.
  
  System.out.println();
  System.out.println("------------endPt객체 정보------------");
  Point endPt = new Point();
  System.out.println("클래스 이름: " +endPt.getClass());
  System.out.println("해쉬코드 : " +endPt.hashCode()); //자바 JVM은 hashcode로 객체를 관리함.
  System.out.println("객체 문자열 : "+endPt.toString());
  
 }// end main
}

class Test
{
 public String toString()
 {
  return "오늘은 목요일 입니다";
 }
}
class ObjectTest_2
{
 public static void main( String [] args )
 {
  ObjectTest_2 obj = new ObjectTest_2(); //객체 생성
  System.out.println("클래스이름:" + obj.getClass());
  System.out.println("해시코드:" + obj.hashCode());
  System.out.println("객체문자열:" + obj.toString());
  
  Test test = new Test();
  System.out.println(test.toString());
 }// end main

}


728x90

Properties 클래스는 말그대로 속성을 모아서 하나의 객체로 만들어 제공한다.
이런 클래스가 필요한 이유는 프로그램이 시작되기 전에 여러개의 속성들중 원하는
속성들을 미리 인식하게 하여 전반적인 실행환경을 조율하고 좀더 신속한 처리속도를
가져오는데 목적이 있다.

Method

put("key","value");
getProperty("key"); key에 해당하는 값을 얻는다.
list(printWriter out);  인자로 전달된 출력스트림에 속성 목록을 출력한다.

import java.util.*;
import static java.lang.System.out;

class PropertiesTest
{
 public static void main( String [] args )
 {
  Properties prop = new Properties();
  
  prop.put("user","scott");
  prop.put("pwd","tiger");
  prop.put("driver","oracle.jdbc.driver.OracleDriver");  //오라클 드라이버도 모두 클래스
  
  String user = prop.getProperty("user");
  String pwd = prop.getProperty("pwd");
  String db_driver = prop.getProperty("driver");
  
  out.println("===================keys================");
  
  // 키값들만 얻어 내기
  Enumeration en = prop.propertyNames();
  while(en.hasMoreElements());
  {
   out.println(en.nextElement());
  }
  
  out.println("=============prop.list(System.out)==========");
  prop.list(System.out); //모두 출력
  
 }// end main
 

}


 

+ Recent posts