패키지
정의 : 연관된 클래스들을 묶는 기법.
장점 : 관련된 클래스들을 쉽게 파악, 클래스 쉽게 찾을 수 있음
같은 클래스 이름을 여러패키지가 사용가능, 패키지별 접근 제약 가능
이름 : 인터넷 도메인 이름을 역순으로 사용한다. ex) com.company.test라는 패키지 이름은 도메인 이름 company.com에서의 test라는 프로젝트를 의미
소속된 패키지 없음 : 디폴트패키지 혹은 현재 작업하는 소스파일과 같은패키지가 아닌 곳에 위치한 클래스를 사용하려면 풀패키명으로 접근 혹은 import를 해야됨.
public class Test {
public static void main(String[] args) {
System.out.println(System.currentTimeMillis());
System.out.println(System.nanoTime());
System.exit(0);
}
}
import java.util.Scanner;
public class Test2 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("몇번째꺼 구할래?");
int num = scan.nextInt();
int n1 = 0;
int n2 = 1;
int n3 = 0;
long start = System.currentTimeMillis();
for(int i = 3; i <= num; i++){
n3 = n1 + n2;
n1 = n2;
n2 = n3;
System.out.println(n3);
}
long end = System.currentTimeMillis();
long gap = end - start;
System.out.println("걸린시간 : "+ gap + "ms");
System.out.println(num + "번째 피보나치수 : "+ n3);
}
}
import java.util.Scanner;
public class Test3 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("두 수를 입력하시오");
String n1 = scan.nextLine();
String n2 = scan.nextLine();
int num1 = Integer.parseInt(n1);
int num2 = Integer.parseInt(n2);
int result = num1 + num2;
System.out.println(result);
}
}
public class Hello { public static void main(String[] args) { StringBuffer sb = new StringBuffer(); sb.append("Hello"); sb.append(" world"); sb.append("\n"); sb.append("Welcome"); sb.append(" to hell"); String str = sb.toString(); System.out.println(str); |
public class Hello { public static void main(String[] args) { StringBuffer sb = new StringBuffer(); //StringBuilder = new StringBuilder(); String str = sb.append("Hello") .append(" world") .append("\n") .append("Welcome") .append(" to hell") .toString(); System.out.println(str); |
메소드 체인기법 = 빌더패턴 : 메소드의 반환값이 자기자신객체, 그래서 메소드 호출 결과에 다시한번 메소드 호출을 반복
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateTest {
public static void main(String[] args) {
// Date d = new Date();
// System.out.println(d);
// System.out.println(d.getTime());
// Date.dd = new Date(System.currentTimeMillis());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd:hh.mm.ss");
String str = sdf.format(new Date());
System.out.println(str);
// System.out.println(d.getYear() + 1900);
// System.out.println(d.getMonth() + 1 );
// System.out.println(d.getDate());
//
// d.setHours(12);
// d.setMinutes(00); //시간정보를 관리할 객체타입은 util.Date
// d.setSeconds(38); // 직접 시분초 연월일을 접근/조작 no
//Date타입의 시간 -> timemillis시간 -> 문자열시간
// <- <-
// System.out.println(d);
}
}
//Date 객체 -> Calendar 객체로
//c.set(new Date());
//Calendar 객체 -> Date 객체
//Date d = c.getTime();
import java.util.Scanner;
import java.util.StringTokenizer;
public class Token {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("아이디와 입력을 하시오 : ex) iddd//pwww");
String idpw = scan.nextLine();
// StringTokenizer st = new StringTokenizer(idpw, "//");
// System.out.print("당신의 아이디는 " + st.nextToken()+ "이고");
// System.out.println(" 비번은 "+ st.nextToken()+ " 입니다.");
String[] str = idpw.split("//");
System.out.print("당신의 아이디는 " + str[0]+ "이고");
System.out.print(" 비번은 "+ str[1]+ " 입니다.");
' IOT 기반 응용 SW과정 > Java, Eclipse ' 카테고리의 다른 글
Day18 예외처리 (0) | 2016.04.06 |
---|---|
Day17 제네릭과 컬렉션 (0) | 2016.04.05 |
Day15 전략패턴 (0) | 2016.04.01 |
Day 14 형변환 , 추상클래스 (0) | 2016.03.31 |
Day13 상속 (0) | 2016.03.30 |