AppleTree iOS

java - 12일째(source) 본문

JAVA/기초 JAVA

java - 12일째(source)

사과나무 2010. 7. 23. 16:06

package console.base.cast;

import console.base.cmd.BaseCommand;
import console.base.cmd.OneCmd;
import console.base.cmd.TwoCmd;
import console.base.cmd.ThreeCmd;

 


public class Castex {
 public int intvalue=0;
 
 public void Test(){
  System.out.println("test");
 }
 
 public Castex(){
  System.out.println("Castex 기본생성자호출");
 }
 
 
 public Castex(int intvalue){
  this.intvalue=intvalue;
 }
 
 public Castex(String strvalue){
  //Integer.parseInt(strvalue);
  //문자형값을 정수형값으로 형변환한다 (강제형변환)
  this.intvalue=Integer.parseInt(strvalue);
 }
 
 
 public int Intvalue(){
  return this.intvalue;
 }
 
 
 
 
 public static void main(String args[]) throws Exception{
  //new : 이예약어어는  객체을 만들기위한예약어입니다
  //지금 하고있는거는 기본생성자을 부르고 객체을 부르는 예제입니다
  
  
 /*  
Castex ex=
(Castex)Castex.
class.forName("src.console.base.cast.Castex").newInstance();

ex.Test();

  //args[0] 는 main의 아퀴먼트 (1차배열 아퀴먼트) 고
  //첫번째 인자값을 받을수있습니다
  

  System.out.println("사용자:"+command);
  
  
  Castex cast=new Castex(1);
  Castex cast2=new Castex("1");
  
  
  System.out.println(cast.Intvalue());
  System.out.println(cast2.Intvalue());
*/  
  
  
  String command=args[0];
  
  
  System.out.println("1:"+args[0]);
  System.out.println("2:"+args[1]);
  System.out.println("3:"+args[2]);
  
//기본생성자 호출   
 Castex cast=new Castex(); 

 
//Castex.class.forName는실제 패키지에 클래스을 찾습니다
//newInstance() 패키지에 해당하는 클래스 객체을 생성하면서 기본생성자을 호출합니다


if(args[0].equals("1")){

BaseCommand commandexe=(BaseCommand)new OneCmd();
commandexe.doExecute("홍길동","미국",20);
}
if(args[1].equals("2")){
 BaseCommand commandexe=(BaseCommand)new TwoCmd();
 commandexe.doExecute("김현호","북한",30);
}

if(args[2].equals("3")){
 BaseCommand commandexe=(BaseCommand)new ThreeCmd();
 commandexe.doExecute("아무개","한국",40);
}
 
 
 } 
 
}






package console.base.cast;

public class Castex2 {

 /**
  * @param args
  */
 public static void main(String[] args) {
  //Castex 기본생성자가 없기때문에 호출할수없다
  
  //Castex cast=new Castex();
  //인트형 생성자가 있기때문에 호출 할수있다
  Castex cast=new Castex(1);
 
 }

}







package console.base.cast;

public class ExInteger {
 
 
 //main 메소드는 vm 호출하는데
 //객체보다 static 을 한메소드가 먼저뜬다
 //main 메소드는 static 이므로 static 을 하면 바로 메모리에 로딩된다
 public int intvalue=0;
 
 public int Intvalue(){
 return this.intvalue; 
 }
 
 public ExInteger(int intvalue){
  this.intvalue=intvalue;
 } 
 
 public static void main(String args[]){
 //예약어가 정수형을 만듭니다
 int intvalue=1;
 //wrapper class 는 객체생성을 vm 이 자동으로해준다
 //Integer wrappervalue=1;
 //Integer wrappervalue =new Integer(1);
 //wrapper 클래스가 만든 정수형
 //Integer 1정수형을 담는다
 Integer wrappervalue =new Integer(1);
 //ExInteger 에 1정수형을 담는다
 ExInteger ex=new ExInteger(1);
 //System.out.println(ex);
 //ExInteger 에서 클래스타입구한다
 String exstr=ex.getClass().getName();
 
 //Integer 에서 클래스타입을 구한다
 String exstr2=wrappervalue.getClass().getName();
 
 //vm 에서동작하는원리가이럴것이다
 //왼쪽  instanceof 오른쪽
 //왼쪽 type 형과 오른쪽 타입형이 맞으면 true
 //틀리면flase
 if(ex instanceof  ExInteger){
  if(exstr.equals("src.console.base.cast.ExInteger")){
  System.out.println("vm:"+ex.Intvalue());
  }
 }

 
 if(wrappervalue instanceof  Integer){
  if(exstr2.equals("java.lang.Integer")){
   System.out.println("vm Integer:"+ex.Intvalue());
  }
 }
 
 
 
 
 
 System.out.println(ex.getClass().getName());
 System.out.println(wrappervalue.getClass().getName());
 
 
 
 
 //System.out.println(intvalue);
 //System.out.println(wrappervalue.intValue());
 
 }

}






package console.base.cast;

public class ExString {

}




package console.base.cast;

public class ExStringBuffer {

}






package console.base.cmd;

public interface BaseCommand {

 //모든명령을내리는 부모 인테페이스
 public  void doExecute(String name,String address,int age);
 
 
 //->BaseCommand(command)->CommandFactory(abstract class)(명령에대한 객체생성)
 //->(OneCmd,TwoCmd,ThreeCmd)class 객체의 메소드가 실행이됩니다

}





package console.base.cmd;


//BaseCommand 지시을 하면 자동으로 찍어주는 공장 클래스

public abstract class CommandFactory implements BaseCommand{
 
 
 @Override
 public void doExecute(String name, String address, int age) {
  System.out.println("CommandFactory doExecute()");
  
  
 }
 
}








package console.base.cmd;

import java.lang.String;
import java.lang.Integer;
import java.lang.Object;

 

public class OneCmd extends CommandFactory{

 @Override
public void doExecute(String name, String address, int age) {
  System.out.println("OneCmd doExecute()");
}
 
 
 
 public static void main(String args[]){
 
  //오른쪽에 OneCmd 클래스을 인터페이스 BaseCommand형(type)으로
  //형변환 (암시적형변환,묵시적형변환)합니다
  //부모=(부모)자식-> 형변환 (암시적형변환,묵시적형변환)합니다
  BaseCommand command=(BaseCommand)new  OneCmd();
  
  //커서: cursor -> 오라클 에서는 table datarow 의 행의 위치을
  //가리키는 말입니다
  //현재 어느부모냐 을 가리키는 말입니다
  
  command.doExecute("아무개", "대한민국", 10);
  
  
  
  
  
  /*
  String intstr2="";
  int  strint2=0;
   
  String intstr="1";
  int  strint=1;
  //static String valueOf(int i) 
  //static: 클래스명.메소드혹은 변수명
  //strint 는 정수형 값 1이다
  //정수형을 스트링형(문자열)로 바꿀려면
  //String.valueOf(int i)
  //을통해서 강제형변환바뀔수있다
  
  intstr2=String.valueOf(strint);
  //Wrapper class
  //int->Integer Char->Charset boolean->Boolean float->Float
  //dobule->Double
  //jdk1.4 는 에약어와 wrapper 은 같지않습니다
  //jdk1.5 는 에약어와 wrapper 은 같습니다
  
  //String기본적으로 객체을 vm 에서 생성을합니다
  //ex)String name="김현호"
  String str=new String("김현호");
  System.out.println(str);
  Integer in=new Integer(1);
  Integer in2=new Integer("1");
  
  //Integer in2=new Integer();
  
  //정수형값을쳘력
  System.out.println("정수형:"+in.intValue());
  //스트링문자열을 정수형 문자열로 형변환해서 출력 
  
  
  System.out.println("문자형->정수형 :"+in2.intValue());
   
  
  String wrapperex=String.valueOf(in.intValue());
  System.out.println(wrapperex);
  */
  
  
 
}

}







package console.base.cmd;

public class TwoCmd extends CommandFactory{

 @Override
 public void doExecute(String name, String address, int age) {
  System.out.println("TwoCmd doExecute");

  
 }
 
}






package console.base.cmd;

public class ThreeCmd extends CommandFactory{

 @Override
 public void doExecute(String name, String address, int age) {
  System.out.println("threeCmd doExecute");
  
 }
 
}








'JAVA > 기초 JAVA' 카테고리의 다른 글

Address 비교 선생님꺼 내꺼  (0) 2010.07.27
java - 13일째(source)  (0) 2010.07.26
java - 11일째(source)  (0) 2010.07.22
java - 10일째(source)  (0) 2010.07.21
java - 9일쩨(source)  (0) 2010.07.20
Comments