DAY 03
✍️ 이클립스 사용법
- src -> 소스코드 / bin -> class
이클립스 단축키
1) main + ctrl + space => public static void main
2) syso + ctrl + space => System.out.println
3) ctrl + space + s => 자동정렬
.java -> class -> package -> project -> jar
✍️ 변수, 함수, 메소드
test -> 변수
test() -> 함수 function()
Test.test -> 메소드 method()
변수 : 지역변수, 전역변수
- 지역변수 : 메소드 안에 선언하는 변수 , 반드시 초기화
- 전역변수 : 클래스안에 선언하는 변수
✍️ 클래스
-class = 자료형 = 실행단위
-class = 값 + 기능
-class = 속성 + 메소드
-class = static final + user_method()
[선언]
접근제한자 [abstract, final] class userName{
속성 (값) + 메소드 (기능) _[static,non-static],[abstract,final = 상속],[void, data type]
}
public static final void Prn(){}
public void Disp(){}
public int Prn(){return 100};
✏️ 클래스 멤버 중 static void 형 메소드
[형식]
접근제한자 static void userName(매개인자...){
명령;
}
[호출]
class명.userName(); // 클래스명.메소드명()
✍️ static , non-static
- static : 클래스명.메소드명()
- non-static : 객체.메소드명()
- non-static일 경우에는 주소가 생성되지 않음 -> 호출 불가 (주소 만들어야 됨)
- static은 생성될 때 주소가 할당되므로 호출 가능
✍️ 자바의 식별자 규칙
- 클래스이름, 인터페이스이름, 메소드이름, 변수이름, 상수이름 등을 구별할 수 있는 규칙
자바의 클래스명은 대문자로 시작한다.
✍️ 기본형변수
- boolean , 정수, 실수, 문자, 문자열
boolean : true, false
정수 : 소수 없는 수
실수 : 소수점 지수
문자 : ' '
문자열 : " "
✍️ 값을 출력하는 표준 출력 메소드
print() : 줄바꿈 X
println : 줄바꿈 O
printf : 포맷지정 => public PrintStream printf(String format, object...arg)
* +는 " " 를 만나면 연결 문자열이 된다.
ex) System.out.print(true + "\n"); // \n은 줄바꿈
* "와 같은 특수문자 앞에 \를 주면 단순한 문자, value로 본다.
✍️ 자료형
byte(1byte) -> short(2) -> int (4) -> long (8) -> float(4) -> double(8)
char(2)
0,1 -> bit *8 = 8bit = 1byte =-128 ~127
ex) 2라는 숫자를 byte방에 b1이라는 이름으로 저장하고 싶다. // 데이터타입 변수이름 = 값
byte b1 = 2; // b1이라는 지역 변수에 2라는 값을 대입했다.
byte b2 = 129; // byte는 127까지만 가능하므로 오류
byte b2 = (byte)129 ; // 오버플로우 되면 역으로 돌아가 -127출력
int ai = 100;
System.out.println(ai);
ai = 300 ; // 재대입
System.out.println(ai);
long l = 100L;
System.out.println(l);
double d = 92.8D; // 접미어
System.out.println(d);
float f = 92.8f;
System.out.println(f);
char ch = 'c';
System.out.println(ch);
String str = "abcd";
System.out.println(str);
✍️ 형변환
✏️ 명시형변환 ( double -> byte 방향)
- 큰 데이터 타입의 자료형을 작은 데이터 타입의 변수에게 전달할 때 해당 데이터 타입으로 선언해 주는 것
✏️ 자동형변환 (byte -> double 방향)
- 작은 데이터 타입의 자료형을 큰 데이터 타입의 변수에 전달이 자동으로 이루어 지는 것
ex) double d = 100; d(8byte) = 100 (4byte);
float f = (float) 90.4 // f (4byte) = 90.4 (8byte);
Formatter
StringBuilder sb = new StringBuilder(); // non-static
Formatter formatter = new Formatter (sb,Locale.US);
// class명 클래스 변수 = new 생성자(); -> 주소 생성
✍️ 연산자
✏️ | (or), &(and), ^(xor)
A | B | A|B | A&B | A^B |
---|---|---|---|---|
0 | 0 | 0 | 0 | 0 |
1 | 0 | 1 | 0 | 1 |
0 | 1 | 1 | 0 | 1 |
1 | 1 | 1 | 1 | 0 |
✏️ && , || 연산자
✏️ >> , << (shift 연산자)
ex) a = 2;
b = a>>2;
c = a<<2;
a 00000000 00000000 00000000 00000010
b 00000000 00000000 00000000 00000000 // 0으로 채움
c 00000000 00000000 00000000 00001000