java compile된 시간 찍기 (compile timestamp)

2009/01/07 09:25 게시판/Computer
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;


public class TestCompileTime {

    public TestCompileTime() {
        try {
            System.out.println("build date:>>"+TestCompileTime.getCompileTimeStamp(this.getClass()));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new TestCompileTime();
    }

    /**
     * get date a class was compiled by looking at the corresponding class file in the jar.
     * @author Zig
    */
    public static Date getCompileTimeStamp( Class<?> cls ) throws IOException
    {
       ClassLoader loader = cls.getClassLoader();
       String filename = cls.getName().replace('.', '/') + ".class";
       // get the corresponding class file as a Resource.
       URL resource=( loader!=null ) ?
                    loader.getResource( filename ) :
                    ClassLoader.getSystemResource( filename );
       URLConnection connection = resource.openConnection();
       // Note, we are using Connection.getLastModified not File.lastModifed.
       // This will then work both or members of jars or standalone class files.
       long time = connection.getLastModified();
       return( time != 0L ) ? new Date( time ) : null;
    }
}



2009/01/07 09:25 2009/01/07 09:25

리눅스에서 자바 버전 표시가 설치한 버전으로 안나올경우

2008/05/23 13:54 게시판/Computer
자바 최신버전 1.5 나 1.6등을 깔고
java -version을 해보면 1.4.2 와 같이 상이한 버전이 표시될 경우에
/etc/profile등에 export해도 제대로 표시 안될때가 있다.
이럴경우는
아래와 같이 설정하도록 하면 쉽게 끝!!~

# alternatives --install /usr/bin/java java /usr/local/jdk1.5.0_13/bin/java 2
# alternatives --config java
이런후 설치한 자바를 선택한 후 엔터!~

#java -version

해보면 제대로 나오는걸 알 수 있다.

2008/05/23 13:54 2008/05/23 13:54

자바 리스너 기본

2008/01/17 23:25 게시판/Computer

사용자 삽입 이미지
자바에서 클래스의 행동을 다른클래스에 알려주는 방법이다.
잘만 구현하면 좋은 프로그램을 만들수있겠다~~ ^0^





[Test.java]
interface Listener
{
    public void  startListener(String log);
    public void runListener(String log);
}

class Test2 implements Listener {
    public synchronized void startListener(String log) {
     System.out.println("Bclass started:"+log);
    }
    public synchronized void runListener(String log) {
     System.out.println("Bclass running:"+log);
    }
   
    Test2() {
     Bclass myb  =  new Bclass(this);
     Thread thread = new Thread(myb);
     thread.start();
    }
    public static void main(String[] args) {
         Test2 t2 = new Test2();
    }
}

----------------------------------------------------------------------------
[Bclass.java]

public class Bclass implements Runnable{
 private Listener listener;
 private int i = 0;
 
    Bclass(Listener l) {
       this.listener = l;
       this.listener.startListener ("메롱이당 ㅋㅋㅋ 요이땅~~~");  
    }
   
    public void run() {
     while (true) {
      this.i++;
      try{Thread.sleep(10);}catch (Exception e) {}
      this.listener.runListener(i+"--나지금 돌고 있니~ ㅋㅋㅋㅋ");
     }
    }
   
}



2008/01/17 23:25 2008/01/17 23:25