검색결과 리스트
JAVA에 해당되는 글 6건
- 2014.02.18 String class의 split
- 2014.02.15 JAVA의 Timer와 TimerTask
- 2014.02.12 ArrayList를 String[]으로 변환하기
- 2014.02.07 SOAP 이용하여 MySQL DB연동할때 유의점
- 2014.01.11 게임1
글
String class의 split
JAVA
2014. 2. 18. 13:54
spilt method를 이용하여서 string을 분리할수 있다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public class Mytest { public static void main(String[] args) { String teststring = "fuck_suck"; String[] temp; temp = teststring.split("_"); for(String sam : temp){ System.out.println(sam); } } } |
글
JAVA의 Timer와 TimerTask
JAVA
2014. 2. 15. 11:30
Timer와 TimerTask를 이용하면 일정시간이 지난후에 해당 task가 실행되도록 해준다.
c의 sleep과의차이점은 sleep은 그 시간동안 아무것도 안하고 기다리는것에 비해
timertask를 이용하면 다른일을 하고 있다가 지정시간이 지난후 해당 task를 실행하므로
용도의차이가 있다.
결과:
코드:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | package pkg1; import java.util.ArrayList; import java.util.List; import java.util.Timer; import java.util.TimerTask; class Remotecon{ boolean open; Remotecon(){ this.open = false; } public void pressButton() { open = open?false:true; } public void close(){ this.open = false; } public void open(){ this.open = true; System.out.println("The door opens"); final Timer timer = new Timer(); TimerTask timertask = new TimerTask(){ public void run() { close(); System.out.println("The door closes"); timer.cancel(); } }; timer.schedule(timertask, 1000); } } public class Mytest { public static void main(String[] args) { Remotecon remotecon = new Remotecon(); remotecon.open(); System.out.println("HI"); } } |
글
ArrayList를 String[]으로 변환하기
JAVA
2014. 2. 12. 15:02
이게 되는구나 구지 힘들게 클래스를 이용하여 Gson을 이용하지 않아도 되겠다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | package pkg1; import java.util.ArrayList; import java.util.List; public class Mytest { public static String[] hello(){ List<String> mylist = new ArrayList<String>(); mylist.add("FUCK"); mylist.add("SUNOFBEACH"); return (String[])mylist.toArray(new String[mylist.size()]); } public static void main(String[] args) { String[] a = hello(); System.out.println(a[0]); System.out.println(a[1]); } } |
글
SOAP 이용하여 MySQL DB연동할때 유의점
JAVA
2014. 2. 7. 16:01
[ SOAP Client ] <------> [SOAP Server] <-------> [MySQL DB]
를 구현하려고 하였다.
그런데
그냥 Java Project에서 MySQL로는 잘만되는데
SOAP server가 추가된 위의 경우에는 JDBC Driver를 못찾는다는 에러가 계속 떠서 황당했다.
분명 mysql-connector또한 넣고 build path또한 지정해줬는데도 말이다.
하지만 알고보니 SOAPserver구성시에는 mysql-connector를 임의의 폴더말고, 특정 경로에 넣어줘야하는것이였다
위 그림의 경로에 mysql-connector를 넣어줘야함을 유의하자.
[추가: Gson도 여기에 넣어야하네 ㅠㅠㅠ 그동안 안됬던게 이것때문인가 ]
글
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | package Java1; import java.util.Scanner; class Point{ int x; Point pt; int num; Point(int num){ this.num = num; x = (int)(Math.random()*10%5); if(num>0) pt = new Point(num-1, x+1); } Point(int num, int x){ this.x = x; if(num>0) pt = new Point(num-1, x+1); } Point Delete_pt(Point Ori, Point Current){ Point pOld = null; Point pNew = Ori; for( ; pNew!=null; pNew = pNew.pt){ if(Current.equals(pNew)){ if(pOld==null) { Ori=Ori.pt; break; } pOld.pt = pOld.pt.pt; break; } pOld = pNew; } return Ori; } Point findLoc(Point pt, int value){ Point Loc = pt; Point pTemp = pt; for( ; pTemp!=null; pTemp = pTemp.pt){ if(pTemp.x == value) return Loc; else Loc=Loc.pt; } return null; } } public class DotCom{ public static void main(String[] args) { Point pt = new Point(2); Point temp_pt = pt; for(int i=0; i<3; i++,temp_pt=temp_pt.pt){ System.out.println(temp_pt.x); //값 표시 } Scanner s = new Scanner(System.in); int Loc ; int hit=0; while(hit!=3){ Loc = Integer.parseInt(s.next()); if(pt.findLoc(pt, Loc)!=null){ pt = pt.Delete_pt(pt, pt.findLoc(pt, Loc)); System.out.println("hit"); hit++; }else{ System.out.println("miss"); } } System.out.println("kill"); } } /* class Grid{ boolean[][] grid = new boolean[7][7]; boolean rotate(){ int temp = (int)Math.random()*10; if(temp<5){return false;} else{ return true;} } void check_position(Point ori_pt){ } Point getPt(Point pt, int numofelements){ if(pt == null){ pt = new Point(); pt.x = (int) Math.random()*10%7; pt.y = (int) Math.random()*10%7; Point.count++; pt.next = getPt(pt, numofelements); return pt; }else{ if(Point.count!=numofelements-1){ Point pNew = new Point(); return getPt(); } } } void setDotcom(){ Point p = new Point(); } } class Point{ int x, y; static int count; Point left, right; Point next; } class Input{ String key_value; void get_key_value(Point p){ Scanner s = new Scanner(System.in); while(true){ key_value = s.next(); if(key_value.length()!=2){ System.out.println("잘못입력하셨습니다. 다시입력하세요"); }else{ break; } } s.close(); key_value = key_value.toUpperCase(); p.x = Integer.parseInt(key_value.substring(1, 2)); switch(key_value.substring(0, 1)){ case "A": p.y = 0; case "B": p.y = 1; case "C": p.y = 2; case "D": p.y = 3; case "E": p.y = 4; case "F": p.y = 5; case "G": p.y = 6; } } } public class Dotcom { public static void main(String[] args) { Input In = new Input(); Point p = new Point(); In.get_key_value(p); } } */ |