1.5 전용 코드(?)를 없앴다고 생각했는데,
jre 1.4로 깔고 코드 수정하면서 느낀점이
java 1.4 에서 1.5로 넘어오면서 여러부분이 바뀌었다는점이다.
(제네릭 지원은 물론이고 String.replace 등의 method 등등)
이번부터 1.4 컨버팅 작업부터 rath님께서 프로젝트에 참여 하셔서 도움을 주셨다.
아래 스샷은 java 1.4에서 jateon 을 실행시킨 모습
보호되어 있는 글입니다. 내용을 보시려면 비밀번호를 입력하세요.
리눅스-_-;;;
$ java test
file.encoding=UTF-8
윈도우
java test
file.encoding=MS949
ArrayList라는걸 한번 써봤다
eclipse 3.2 , jdk 5.0 이어서 그런지
자동완성으로 class<Element>가 자동으로 붙었다!!
[CODE type="java"]
import java.util.ArrayList;
import java.util.ListIterator;
class Buddy{
[tab]protected String loginName = null;
[tab]protected String nickName = null;
[tab]public Buddy() {
[tab][tab]
[tab]}
[tab]public Buddy(String loginName, String nickName) {
[tab][tab]this.loginName = loginName;
[tab][tab]this.nickName = nickName;
[tab]}
[tab]public String toString(){
[tab][tab]return "LName:" + loginName + "/NName:" + nickName;
[tab]}
}
public class DStest {
[tab]
[tab]private ArrayList<Buddy> list = null;
[tab]
[tab]public DStest() {
[tab][tab]list = new ArrayList<Buddy>();
[tab][tab]
[tab]}
[tab]public void add(Buddy e)
[tab]{
[tab][tab]list.add(e);
[tab]}
[tab]public Buddy getBuddy(int idx){
[tab][tab]return list.get(idx);[tab][tab]
[tab]}
[tab]
[tab]
[tab]
[tab]public void sortList(){
[tab][tab]Buddy tmp;
[tab][tab]for(int i=0;i<list.size();i++){
[tab][tab][tab]for(int j=i;j<list.size();j++)
[tab][tab][tab][tab]if(list.get(i).nickName.compareTo(list.get(j).nickName)>0){
[tab][tab][tab][tab][tab]tmp = list.get(i);
[tab][tab][tab][tab][tab]list.set(i, list.get(j));
[tab][tab][tab][tab][tab]list.set(j, tmp);
[tab][tab][tab][tab]}
[tab][tab]}
[tab]}
[tab]
[tab]public void printList(){
[tab][tab]ListIterator<Buddy> li = list.listIterator();
[tab][tab]Buddy cur;
[tab][tab]while(li.hasNext()){
[tab][tab][tab]cur = li.next();
[tab][tab][tab]System.out.println(cur);[tab][tab][tab]
[tab][tab]}
[tab][tab]
[tab]}
[tab]
[tab]public static void main(String args[]){
[tab][tab]DStest test = new DStest();
[tab][tab]test.add(new Buddy("foobar","asdfefef"));
[tab][tab]test.add(new Buddy("thisff","dsfasdfasdf"));
[tab][tab]test.add(new Buddy("asdfaf","asdfae54ewf"));
[tab][tab]test.add(new Buddy("vzxvsd","zxvcxcerqer"));
[tab][tab]test.add(new Buddy("zxcvwe","asdfer2wera"));
[tab][tab]test.add(new Buddy("saerer","zvczxcadfwe"));
[tab][tab]test.add(new Buddy("xvas43","zxvcvawer3r"));
[tab][tab]test.add(new Buddy("cxvaer","cxvaerqwer2"));
[tab][tab]
[tab][tab]test.printList();
[tab][tab]System.out.println("========SORT=============");
[tab][tab]test.sortList();
[tab][tab]
[tab][tab]test.printList();
[tab][tab][tab]
[tab]}
}
[/HTML][/CODE]
실행결과
LName:foobar/NName:asdfefef
LName:thisff/NName:dsfasdfasdf
LName:asdfaf/NName:asdfae54ewf
LName:vzxvsd/NName:zxvcxcerqer
LName:zxcvwe/NName:asdfer2wera
LName:saerer/NName:zvczxcadfwe
LName:xvas43/NName:zxvcvawer3r
LName:cxvaer/NName:cxvaerqwer2
========SORT=============
LName:asdfaf/NName:asdfae54ewf
LName:foobar/NName:asdfefef
LName:zxcvwe/NName:asdfer2wera
LName:cxvaer/NName:cxvaerqwer2
LName:thisff/NName:dsfasdfasdf
LName:saerer/NName:zvczxcadfwe
LName:xvas43/NName:zxvcvawer3r
LName:vzxvsd/NName:zxvcxcerqer
[##_1C|cfile6.uf.1753A5544DC50E8C2EB28B.png|width="400" height="174" alt=""|_##]
디카나 메모리카드 등에 있는 사진파일(JPG)들을,
특정위치로 복사하는 프로그램이다.
캐논 포토브라우저인가 뭔가에 내장되있는
사진 복사하기 기능을 썼었는데
다 좋은데(?)
정작 포토브라우저 로딩시간이 엄청나게 느리다
(사진 모아둔 곳에서 시작하다보니 그 내용들을 다 표시하는데 시간이 걸린다··)
-_-a
반나절 삽질끝에 이 프로그램을 만들었다.
처음 실행시후에 Dc2Hdd.conf파일이 생성되는데
마지막 설정이 저장되므로,
프로그램 인자로 -f 를 주면 따로 묻지 않고,
바로 copy 해버리는 기능이 있다.
exe다운받기↓↓
[##_1L|2280692376.xxx||_##]
jar다운받기 ↓↓ [##_1L|cfile8.uf.174D17474DC50E8C27EC2A.jar||_##]
[CODE type="java"]
/** 쓰레드 연습 **/
class Data{
[tab]
[tab]private String data;
[tab]private boolean is_saved = false;
[tab]
[tab]public synchronized void setData(String arg){
[tab][tab]
[tab][tab] try{
[tab][tab][tab]
[tab][tab][tab]
[tab][tab][tab] if(is_saved){
[tab][tab][tab][tab] wait();
[tab][tab][tab] }
[tab][tab] }
[tab][tab] catch (Exception e) {
[tab][tab][tab] System.out.println("SET error");
[tab][tab] }
[tab][tab]
[tab][tab] data = arg;
[tab][tab] is_saved = true;
[tab][tab] notify();
[tab][tab]
[tab]}
[tab]public synchronized String getData(){
[tab][tab]
[tab][tab] try{
[tab][tab][tab] if(!is_saved)
[tab][tab][tab][tab] wait();
[tab][tab][tab]
[tab][tab] }
[tab][tab] catch (Exception e) {
[tab][tab][tab] System.out.println("GET error");
[tab][tab] }
[tab][tab]
[tab][tab] String r = data;
[tab][tab] data = "";
[tab][tab] is_saved =false;
[tab][tab] notify();
[tab][tab] return r;
[tab]}
[tab]
[tab]
[tab]public boolean is_saved(){
[tab][tab] return is_saved;[tab][tab]
[tab]}
[tab]
}
class Producer extends Thread{
[tab]Data s;
[tab]Producer(String msg, Data ss){
[tab][tab] s=ss;
[tab][tab] System.out.println(msg);[tab][tab]
[tab]}
[tab]public void run(){
[tab][tab] int i=0;
[tab][tab] while(i<10){
[tab][tab][tab] try{
[tab][tab][tab] sleep((long)(Math.random()*1000));
[tab][tab][tab] }
[tab][tab][tab] catch (Exception e) {
[tab][tab][tab][tab] // TODO: handle exception
[tab][tab][tab] }
[tab][tab][tab]
[tab][tab][tab] System.out.println( "producer is running : " +i);
[tab][tab][tab] s.setData("DATA ("+i+"): " + produce());
[tab][tab][tab][tab] i++;
[tab][tab]
[tab][tab] }//end while
[tab]}//end run
[tab]
[tab]private String produce(){
[tab][tab] int r ;
[tab][tab] r =(int)( Math.random()*10);
[tab][tab] return "" + r;
[tab]}
[tab]
}
class Consumer extends Thread{
[tab]Data s;[tab]
[tab]
[tab]Consumer(String msg,Data ss){
[tab][tab] s = ss;
[tab]
[tab][tab] System.out.println(msg);
[tab]}
[tab]
[tab]public void run(){
[tab][tab] int i=0;
[tab][tab] String data="";
[tab][tab] while(i<10){
[tab][tab][tab] try{
[tab][tab][tab][tab] sleep((long)(Math.random()*1000));
[tab][tab][tab][tab] }
[tab][tab][tab][tab] catch (Exception e) {
[tab][tab][tab][tab][tab] // TODO: handle exception
[tab][tab][tab][tab] }
[tab][tab][tab][tab]
[tab][tab][tab] System.out.println( "consumer is running : " + i);
[tab][tab][tab] data =s.getData();
[tab][tab][tab] System.out.println(">> " + data);
[tab][tab][tab] i++;
[tab][tab][tab]
[tab][tab] }//end while
[tab]}//end run[tab]
}
class Ttest{
[tab]public static void main(String args[])
[tab]{
[tab][tab] Data data = new Data();
[tab][tab] Producer t1 = new Producer("P thread is ready", data);
[tab][tab] Consumer c1 = new Consumer("C thread is ready", data);
[tab][tab]
[tab][tab]
[tab][tab] t1.start();
[tab][tab] c1.start();
[tab][tab]
[tab][tab]
[tab][tab]
[tab][tab][tab][tab]
[tab]}[tab][tab]
}
/**
class Data{
[tab]
[tab]private String data;
[tab]private boolean is_saved = false;
[tab]
[tab]public void setData(String arg){
[tab][tab] data = arg;
[tab][tab] is_saved = true;
[tab]}
[tab]public String getData(){
[tab][tab] String r = data;
[tab][tab] data = "";
[tab][tab] is_saved =false;
[tab][tab] return r;
[tab]}
[tab]
[tab]
[tab]public boolean is_saved(){
[tab][tab] return is_saved;[tab][tab]
[tab]}
[tab]
}
class Producer extends Thread{
[tab]Data s;
[tab]Producer(String msg, Data ss){
[tab][tab] s=ss;
[tab][tab] System.out.println(msg);[tab][tab]
[tab]}
[tab]public void run(){
[tab][tab] int i=0;
[tab][tab] try{
[tab][tab][tab] while(i<10){
[tab][tab][tab][tab]
[tab][tab][tab][tab] System.out.println( "producer is running : " +i);
[tab][tab][tab][tab] if(s.is_saved()){
[tab][tab][tab][tab][tab] yield();
[tab][tab][tab][tab] }
[tab][tab][tab][tab] else{
[tab][tab][tab][tab][tab] s.setData("DATA ("+i+"): " + produce());
[tab][tab][tab][tab][tab] i++;
[tab][tab][tab][tab] }
[tab][tab][tab][tab]
[tab][tab][tab] }//end while
[tab][tab] }
[tab][tab] catch (Exception e) {
[tab][tab][tab] System.out.println(e);
[tab][tab][tab] // TODO: handle exception
[tab][tab] }
[tab]}//end run
[tab]
[tab]private String produce(){
[tab][tab] int r ;
[tab][tab] r =(int)( Math.random()*10);
[tab][tab] return "" + r;
[tab]}
[tab]
}
class Consumer extends Thread{
[tab]Data s;[tab]
[tab]
[tab]Consumer(String msg,Data ss){
[tab][tab] s = ss;
[tab]
[tab][tab] System.out.println(msg);
[tab]}
[tab]
[tab]public void run(){
[tab][tab] int i=0;
[tab][tab] String data="";
[tab][tab] try{
[tab][tab][tab] while(i<10){
[tab][tab][tab][tab] System.out.println( "consumer is running : " + i);
[tab][tab][tab][tab] if(s.is_saved()){
[tab][tab][tab][tab][tab][tab] data =s.getData();
[tab][tab][tab][tab][tab][tab] System.out.println(">> " + data);
[tab][tab][tab][tab][tab][tab] //notifyAll();
[tab][tab][tab][tab][tab][tab] i++;
[tab][tab][tab][tab] }
[tab][tab][tab][tab] else{
[tab][tab][tab][tab][tab] yield();
[tab][tab][tab][tab][tab] yield();
[tab][tab][tab][tab][tab]
[tab][tab][tab][tab][tab] //this.wait();
[tab][tab][tab][tab][tab] //this.suspend();
[tab][tab][tab][tab] }
[tab][tab][tab][tab]
[tab][tab][tab] }//end while
[tab][tab] }
[tab][tab] catch (Exception e) {
[tab][tab][tab] System.out.println(e);
[tab][tab][tab] // TODO: handle exception
[tab][tab] }
[tab]}//end run[tab]
}
class Ttest{
[tab]public static void main(String args[])
[tab]{
[tab][tab] Data data = new Data();
[tab][tab] Producer t1 = new Producer("P thread is ready", data);
[tab][tab] Consumer c1 = new Consumer("C thread is ready", data);
[tab][tab]
[tab][tab]
[tab][tab] t1.start();
[tab][tab] c1.start();
[tab][tab]
[tab][tab]
[tab][tab]
[tab][tab][tab][tab]
[tab]}[tab][tab]
}
**/
[/HTML][/CODE]