자바기초2008. 10. 31. 20:25

class ArrayParam {
 // 배열 복사를 위한 메모리를 메서드 내에서 생성
 public int[] copyArray(int[] src){
  int[] des = new int[src.length];
  for(int i=0; i<src.length; i++)
   des[i] = src[i];
  return des;
 }
 
 // 배열 복사를 위한 메모리를 매개변수로 받음
 public void copyArray(int[] src, int[] des){
  for(int i=0; i<src.length; i++){
   des[i] = src[i];
  }
 }
}
public class ArrayParamMain{
 public static void main(String[] args){
  ArrayParam p = new ArrayParam();

  int[] source = new int[]{1,2,3,4,5};
  
  int[] result = p.copyArray(source);
  
  for(int i=0; i<result.length; i++){
   System.out.println("result["+i+"] : "+ result[i]);
  }
  System.out.println();
  
  int[] target = new int[source.length];
  p.copyArray(source,target);
  
  
  
  for(int i=0; i<target.length; i++){
   System.out.println("target["+i+"] : "+target[i]);
  }
  
 }
}

Posted by 아마데우스
자바기초2008. 10. 31. 17:29
int[] source = new int[]{5,4,6,7,9,9};
int[] target = {100,200,300,400,500,600,700};
System.arraycopy(source, 2, target, 3, 4);
// 소스의 2번째부터 target의 3번째 위치부터... 4개를 복사한다.

또는

int[] target = (int[])source.clone();
// clone()을 이용한 메모리 복사
Posted by 아마데우스
자바기초2008. 10. 31. 16:17

eclipse.exe -vm c:\Sun\SDK\jdk\bin\javaw.exe

javaw.exe 파일의 위치를 맞춰주면 된다.
Posted by 아마데우스
자바기초2008. 10. 29. 17:51
** 자바에서 상속은 extends 라는 키워드를 사용한다.
** 단일 상속만 허용한다.
** 다중 상속의 대한으로 interface를 지원한다.
** 상속을 받으면 부모의 생성자 먼저 호출된다.
Posted by 아마데우스
자바기초2008. 10. 29. 17:26

** 생성자는 마음대로 호출할 수 없다.
** 생성자도 오버로딩할 수 있다.
** 생성자를 정의하지 않으면 디폴트 생성자가 호출되며 그가 하는 일은 없다.
** 생성자는 리턴타입이 없다. void도 넣으면 안된다. (아무튼 안되더라.. ^^)

Posted by 아마데우스