프로그래밍/Java 7

시간(Time) 관련 함수 및 처리 방법

시간(Time) 관련 함수 및 처리 방법 * 현재 시간 얻기long time = System.currentTimeMillis(); * 날짜 및 시간 출력SimpleDateFormat dateTime = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss"); String str = dateTime.format(new Date(time));시간 설정시 hh는 12시간으로 표시, HH는 24시간으로 표시 * 시간 비교Date date1 = new Date(System.currentTimeMillis()); Date date2 = new Date(System.currentTimeMillis()); if(date1.compareTo(date2) < 0) { System.out.printl..

System.getProperty()

System.getProperty()System.getProperty() 함수의 인자에 아래 Key를 입력하면 해당하는 문자열을 결과로 얻을 수 있다.KeyMeaning"file.separator"Character that separates components of a file path. This is "/" on UNIX and "\" on Windows."java.class.path"Path used to find directories and JAR archives containing class files. Elements of the class path are separated by a platform-specific character specified in thepath.separator prop..

Java/Google Protocol Buffer 사용법

Google의 Protocol Buffer 사용법 * TutorialC++ Tutorial : https://developers.google.com/protocol-buffers/docs/cpptutorialJava Tutorial : https://developers.google.com/protocol-buffers/docs/javatutorialPython Tutorial : https://developers.google.com/protocol-buffers/docs/pythontutorial * 사용순서 1. 컴파일러와 protocol buffer 소스코드 다운로드 2. proto 파일 작성 3. proto 파일을 다운받은 컴파일러로 컴파일 하여 API 코드 생성 4. 생성된 API 코드와 prot..

Java/enum 열거형

enum 열거형 * 기본타입enum SEASON { SPRING, SUMMER, FALL, WINTER } 마지막에 세미콜론(;)을 붙이지 않는다. * 값 설정 및 사용하기 enum SEASON { SPRING(3), SUMMER(5), FALL(2), WINTER(4); final int num; private SEASON(int num) { this.num = num; } public int getNum() { return num; } } public class Exam { public static void main(String[] ar) { System.out.println(SEASON.SPRING); System.out.println(SEASON.SPRING.ordinal()); System.ou..

public 클래스, default 클래스

* Public 클래스 - 해당 소스를 대표하는 클래스라는 상징적 의미가 큼. - 다른 패키지에서 인스턴스 생성이 가능. - 해당 소스 파일에서 하나의 클래스만 public으로 선언이 가능함. - 소스파일 이름과 클래스 이름이 동일해야 함. - 선언시 클래스 앞에 "public"을 추가함. * Default 클래스 - 동일한 패키지 내에 정의된 클래스에서만 인스턴스 생성이 가능. - "public"으로 선언되지 않은 모든 클래스는 default 클래스 임.