1.개발 도구와 자바 플랫폼
-> JDK와 JRE
-> bin 디렉터리에 들어있는 주요 개발 소프트웨어(javac, javap, javadoc, jar...)
2. 자바의 특징
-> 플랫폼 독립성
-> 객체 지향
-> 클래스로 캡슐화
-> 소스와 클래스 파일
-> 실행 코드 배포
-> 패키지
-> 멀티스래드
-> 가비지 컬렉션
-> 실시간 응용 시스템에 부적합 (왜냐하면, 실행 도중 예측할 수 없는 시점에 가비지 컬렉션이 실행되기 때문)
-> 자바 프로그램은 안전하다
-> 프로그램 작성이 쉽다
-> 실행 속도를 개선하기 위해 JIT 컴파일러가 사용된다
3. 자바 기본 프로그래밍
3-1) 좋은 이름 붙이는 관습
-> 클래스 이름 (대문자 시작, Camel Case)
public class HelloWorld
class AutoVendingMachine
-> 변수, 메소드 이름 (소문자 시작, Camel Case)
int myAge;
boolean isSingle;
char myScore;
4. 문자열, 정수 리터럴, 실수 리터럴, 문자 리터럴
public class LecturePractice {
public static void main(String[] args) {
String toolName = "JDK";
double version = 17.1;
System.out.println(toolName + version); // JDK17.1 출력
System.out.println(version + toolName); // 17.1JDK 출력
System.out.println("ABC" + 3); // ABC3 출력
System.out.println("ABC" + 3 + 5); // ABC35 출력
System.out.println("(" + 3 + "," + 5 + ")"); // (3,5) 출력
char a = 'A';
char b = '글';
char c = '\u0041'; // 문자 'A'의 유니코드 값 사용
char d = '\uae00'; // 문자 '글'의 유니코드 값 사용
System.out.println(a); // A
System.out.println(b); // 글
System.out.println(c); // A
System.out.println(d); // 글
}
}
5. 변수, 리터럴, 상수 활용
public class CircleArea {
public static void main(String[] args) {
final double PI = 3.14;
double radius = 10.0;
double circleArea = radius * radius * PI;
System.out.println("원의 면적 = " + circleArea);
}
}
5. 타입 변환
public class TypeConversion {
public static void main(String[] args) {
byte b = 127;
int i = 100;
System.out.println(b+i); // 227
System.out.println(10/4); // 2
System.out.println(10.0/4); // 2.5
System.out.println((char)0x12340041); // A
System.out.println((byte)(b+i)); // -29
System.out.println((byte)(b) + i); // 227
System.out.println((int)2.9 + 1.8); // 3.8
System.out.println((int)(2.9 + 1.8)); // 4
System.out.println((int)2.9 + (int)1.8); // 3
}
}
-> 예제에는 없지만 (byte)(b) + i 를 하는 경우
byte의 범위는 -128에서 127 사이
따라서 (byte)(b)는 그대로 127
결과적으로 (byte)(b) + i 는 127 + 100 = 227이 출력된다
예제출처: 명품 JAVA Programming(개정 5판), 생능출판사
'학교 > 2-2학기(Java)' 카테고리의 다른 글
[5주차] 9/30(월) 강의내용 (0) | 2024.09.30 |
---|---|
[4주차] 9/25(수) 강의내용 (1) | 2024.09.25 |
[4주차] 9/23(월) 강의내용 (0) | 2024.09.23 |
[2주차] 9/11 강의내용 (0) | 2024.09.11 |
[1주차] 9/4(수) 강의내용 (1) | 2024.09.08 |
댓글