패키지



정의 : 연관된 클래스들을 묶는 기법. 


장점 : 관련된 클래스들을 쉽게 파악, 클래스 쉽게 찾을 수 있음


같은 클래스 이름을 여러패키지가 사용가능, 패키지별 접근 제약 가능



이름 : 인터넷 도메인 이름을 역순으로 사용한다. 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

지역변수 : 메소드내에서 생성하는 변수 -> 메소드 종료시 사라짐, 스택영역에 생성됨.






멤버변수(필드) = 인스턴스변수 : 클래스 내부에 정의, 해당 클래스가 객체화 될때마다 각 객체내에 생성됨, 

  해당 객체가 소멸될때 같이 사라짐.







정적변수 = 클래스변수 : 모든객체를 통틀어서 하나만 있는변수 , 해당클래스로 객체를 하나도 안만들었어도 1개만 존재하고 

객체를 계속 만들어도 1개만 존재. 클래스 내부에 static 키워드를 포함해서 정의하며, 프로그램이 실행될때 생성되서, 

프로그램이 종료될때 사라짐.





public static int numberOfCars; //  private static int numberOfCars;






정적메소드의 활용용도 - > 정적변수에 대한 게터,세터를 만들거나 객체의 상태와 상관없는 동작을 수행하는 메소드를 정의할때 사용.

                                       정적 함수에서는 멤버변수에 접근할수 없음.





toString이 우리가 만들지 않아도 원래 존재함, 해당 객체가 문자열화 될때 어떻게 문자열로 바뀔지를 결정하는 기능, 이미 존재하지만 똑같은 이름으로 toSring을 다시 만들어주면, 해당 객체가 문자열화 될때 우리가 정의한 내용에 맞게 문자열됨.


finalize도 원래 존재함, 객체가 소멸되기 직전에 호출되는 메소드, 우리가 똑같은 이름으로 다시 정의하면 해당객체가 소멸될때 우리가 정의한 함수내용을 실행함.


System.gc();

System.runFinalization(); // 가비지컬렉터를 강제로 일시키기 (사용x)


this : 자기 자신을 참조하는 키워드







//* 곱셈 실수부 -> (a*c) - (b*d)    나눗셈 실수부 ->(a*c)/(c*c+d*d) + (b*d)/(c*c+d*d)

   곱셈 허수부 -> (a*d) + (b*c)    나눗셈 허수부 ->(a*d)/(c*c+d*d) - (a*d)/(c*c+d*d) *//

 






' IOT 기반 응용 SW과정 > Java, Eclipse ' 카테고리의 다른 글

Day 14 형변환 , 추상클래스  (0) 2016.03.31
Day13 상속  (0) 2016.03.30
Day11  (0) 2016.03.28
Day10 public/private  (0) 2016.03.25
Day09 객체지향  (0) 2016.03.24

+ Recent posts