220516 - API 확인문제, 멀티 스레드(스레드 생성, 우선순위, 동기화 메소드, 상태)
API 확인문제 6번 문제 1 2 3 4 5 6 7 8 9 10 11 public class BytesToStringEx { public static void main(String[] args) { byte[] bytes = {73,32,108,111,118,101,32,121,111,117}; String str = new String(bytes); System.out.println(str); } } Colored by Color Scripter cs // I love you 7번 문제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 public class FindAndReplaceEx { public static void main(String[] args) { String ..
220513 - API - Arrays, Wrapper, Math, Random, Date, Calendar, Format 클래스, Java.time 패키지, 확인문제 + Class 클래스
Arrays 클래스 binarySearch() : 배열 내 입력문자 위치 찾아줌 1 2 3 4 5 6 7 8 9 10 11 12 13 import java.util.Arrays; public class ArraysEx2 { public static void main(String[] args) { int[] scores = {96,80,90,60,70}; int index=Arrays.binarySearch(scores, 60); System.out.println(index); } } Colored by Color Scripter cs // -1 => sort 메소드 실행 안 할 때 오류 1 2 3 4 5 6 7 8 9 10 11 12 13 14 import java.util.Arrays; public c..
220503 - 6장 클래스 확인문제, 상속(extends), 오버라이딩(재정의)
6장 클래스 확인문제 객체, 클래스 개념 하나의 클래스로 여러 객체 생성 가능 (하나의 객체만 가능 => 싱글톤) 클래스 => 생성자, 메소드, 필드 필수( 생략 시 디폴트 생성) 필드 => 통상적으로 생성자 선언 전에 선언 (필수X) 필드 => 생략 시 기본값으로 자동 초기화됨 객체 생성=> 생성자 호출 필수 생성자=>다른 생성자 호출 위해 this() 사용 가능 메소드 오버로딩 : 동일 이름 메소드 여러 개 선언 => 매개변수의 타입, 수, 순서 다르게 해야 함 정적 필드,메소드 => 객체 생성 없이, 클래스 통해 접근 가능 인스턴스 필드, 메소드 => 객체 생성 필수 패키지 선언 필수 (ex. package ~;) 문제 15 1. boolean login 메소드 (매개값 String id, Stri..
220502 - throw, 다른 생성자 호출, 메소드 오버로딩, 캡슐화(private), getter와 setter, static final, 매개변수 수 모를 경우, 정적 필드와 메소드, 싱글톤, import문, 접근제한자
throw => 인위적 Exception => 클래스파일에서 발생 가능한 에러에 미리 대비 => 메인메소드에서 try, catch문으로 실행 account int withdraw(int amount) throws Exception { if (balance 한 생성자에만 집중 => 중복 코드 예방 생성자의 첫 줄에서만 허용 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 public class Car{ //필드 String compnay="현대"; String model; String color; int maxSpeed; //생성자 Car(){} Car(String model){ this(model, "은색", 250); //호출 } C..