본문 바로가기

app/java

(39)
java의 sha1과 python의 sha1의 암호화 값은 다를 수 있습니다. 프로젝트하는 도중 재미있는 현상을 발견하여 글을 써 봅니다. 서로 발급된 키로 sha1으로 암호화 하여 통신하는 api를 개발하는 도중 java 와 python의 sha1의 값이 다르게 나오는것을 발견하였습니다. 아래는 java의 sha1 암호화의 기본 소스 입니다. import java.security.MessageDigest; import java.security.Security; import java.security.NoSuchAlgorithmException; public class HelloWorld{ public static void main(String []args) throws NoSuchAlgorithmException{ String return_sha1 = makeSHA("8101461..
java 재귀함수 다이아몬드 그리기(별표) package test; public class diamond { int total = 0; int width = 1; int count = 0; boolean flag = false; public void dia(int n){ if(flag == false && n == total+1){ width = (n-total)*2-1; count = (total*2)-width-2; flag = true; } if(n == total*2){ return; } if(n 0){ System.out.print(" "); width--; dia(n); }else{ if(count>0){ System.out.print("*"); count--; dia(n); }else{ System.out.println(); n++;..
java 재귀호출 (별표) 피라미드 그리기 class pyramid1 { int total = 0; int width = 1; int count = 0; pyramid1(int i){ this.total = i; } public void pyramid1(int n){ if(n == total+1){ return; } if(width != total){ System.out.print(" "); width++; pyramid1(n); }else{ if(count!=(n*2)-1){ System.out.print("*"); count++; pyramid1(n); }else{ System.out.println(); n++; width = n; count = 0; pyramid1(n); } } } } class pyramid2 { int total = 0..
java 재귀함수 (별표) 삼각형 만들기 class triangle1{ int total = 0; int width = 0; triangle1(int x){ this.total = x; } public void triangle1(int n){ if(n == total+1){ return; } if(width != n){ System.out.print("*"); width++; triangle1(n); }else{ System.out.println(); n++; width = 0; triangle1(n); } } } class triangle2{ int total = 0; int width = 0; triangle2(int x){ this.total = x; } public void triangle2(int n){ if(n == total+1){..
int 배열 1억개를 만들수 있을까? 알고리즘을 하나 생각해본김에 만들고 있었다. 물론 int 배열로 1억개를 만드는것만큼 이상한것은 없지만, 처리 속도 때문에 리스트로 만들다가 배열로 만들어보기로 했다. (알다시피 리스트로 삭제/입력 속도와 배열의 삭제/입력 속도 차이는 엄청나다. 갯수가 늘어갈수록 기하급수적으로 속도차이가 난다. 언젠가 한번 테스트 해보는것도 도움이 될것이다.) 에러 두둥! 힙메모리가 부족하다고 뜬다. 물론 eclipse.ini 파일을 변경하여(1024m으로 변경) 실행해도 결과값은 똑같다.아무래도 32비트에서는 이클립스 메모리 한계치가 있는듯하다. 1억미만 가장 큰 배열은 몇개를 선언할수 있을까? 하는 마음에 소스 수정 public class test {public static void main(String[] args..
could not create the java virtual machine [이클립스 실행시 에러] [갈릴레오 버전] 프로그램 특성상 이클립스에서 java 실행시 메모리사용량을 변경했더니 위와 같은 에러가 발생한다.(발생 이유는 다양할수 있습니다.)간단하게 해결가능. 이클립스가 설치된 폴더로 들어가 보면 eclipse.ini 라는 설정파일이 있습니다. 이 설정파일을 열어보시면(메모장으로 열으셔도 됩니다.) openFile 란에 위와 같이 -vm 표기와 javaw.exe의 경로(사용PC/ java버전 마다 경로가 다르겠지요?)를 넣어주고 저장.-vmC:\Program Files\Java\jdk1.7.0_21\bin\javaw.exe 실행하면 잘됩니다. [juno 버전] 주노버전에서는 위와 같이 failed to create the java virtual machine 라고 뜨면서 안됩니다.(신기하네요. ..
java 생성자에 대한 고찰 재미있는 퀴즈를 내겠습니다. public class typetest { public static void main(String[] args) {typetest tt = new typetest();}public void typetest(){System.out.println("void");}public typetest(){System.out.println("null");}} 1. 위의 소스를 컴파일 한다면 에러나 날까요?2. 만일 에러가 안난다면 결과값은 무엇일까요? 생각해 보셨나요? 아래의 정답과 비교해 보시기 바랍니다.1. 정상적으로 컴파일이 된다.(에러가 나지 않는다.)2. null 1번 물음은 클래스안에 똑같은 함수의 이름이 두개가 있습니다. 물론 오버로딩도 오버라이딩도 아닙니다.단지 리턴표시만 다름..
Swing jtable Thread 원본 : http://stackoverflow.com/questions/11891457/java-update-jtable-row-from-another-thread 에서 thread 종료와 마우스 이벤트 추가(클릭이벤트)를 해 보았습니다. Begin 버튼을 눌러주면 Thread를 생성하여 칼럼값을 계속 바꿔줍니다.마우스로 해당 로우를 클릭하고 finish 버튼을 눌러주면 해당 Thread가 죽습니다. 일단 원본 소스에 있던 SwingUtilities.invokeLater는 제외하였습니다.(굳이 사용이유가 없었습니다.) 각각의 Thread를 구분하기 위해서 Thread가 생성된 객체를 벡터에 넣고 마우스 이벤트로 해당 벡터의 위치를 알아낸뒤Thread.interrupt()함수를 통해서 Thread를 멈춥니..