일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 26 | 27 | 28 |
- bubble-sort
- class
- 디렉티브
- 클래스 패스
- 백준 알고리즘
- 연결된 예외
- OOP
- try&catch
- 자료구조
- 공개키 암호
- 객체지향
- 재귀호출기본
- 객체
- JSP
- 백준
- BufferedWrite
- LANG
- 소수판정
- 프로그래밍
- 예외처리
- lang package
- HTML
- jvm
- 형변환 연산자
- 현대암호
- 2884
- java
- 자동 형변환
- 암호론
- 알고리즘
- Today
- Total
목록Java (41)
코드일기장

Iterator는 컬렉션에 저장된 요소를 접근하는 데 사용되는 인터페이스이다. Iterator의 구버전은 Enumeration이고 Iterator의 기능을 확장시킨 것은 ListIterator이다. Iterator는 Collection interface의 요소를 접근하기 위한 인터페이스라는 건 우리가 알고 있는 사실이다. 따라서 Iterator를 구현하는 iterator() 메서드는 Collection의 자식인 List와 Set에서도 사용할 수 있다. Iterator의 메서드는 4가지가 있다. public interface Iterator { boolean hasNext(); E next(); default void remove(){ throw new UnsupportedOperationException..

추상클래스 추상클래스는 미완성 클래스라고 보면 된다. 말 그대로 완성되지 않은 클래스이다. abstract class Game{ //추상클래스(미완성 클래스) abstract void play(int pos); //추상 메서드 (몸통 {}이 없는 미완성메서드) abstract int score(); } public class ArrayListEx1 { public static void main(String[] args)throws IOException { Game g = new Game(); } } main메서드에 Game객체를 생성한다면 에러가 날 것이다. 추상 클래스는 추상클래스만으로 객체를 생성할 수 없다. 추상클래스의 용도는 다른 클래스에게 영향을 주기 위함이다. 추상클래스는 상속을 통해 미완성된..

instanceof 연산자는 객체 타입을 확인하는 연산자이다. 그리고 참조변수의 형변환 가능 여부 확인에 사용한다. 가능하면 true를 반환해준다. instanceof의 왼쪽에는 참조변수를 오른쪽에는 타입(클래스명) 피연산자를 위치한다. 다시 말해 instanceof 연산결과 true가 나온다면 참조변수가 검사한 타입으로 형변환 가능하다는 것이다. public class TimeSe { public static void main(String[] args) { Parent p = new Parent(); Child c = new Child(); System.out.println(p instanceof Child); //false System.out.println(p instanceof Parent); //..

- 사용할 수 있는 멤버의 개수를 조절하는 것 형변환이 가능할 때는 조상 자손 관계의 참조 변수는 서로 형 변환 가능 (서로 상속관계에 있는 타입 간의 형 변환만 가능) 자손 타입에서 조상 타입으로 형변환하는 경우, 형변환 생략 가능 자손 타입-> 조상 타입 (Up-casting) :형변환 생략 가능 조상 타입-> 자손 타입(Down-casting): 형변환 생략 불가 public class OOP { public static void main(String[] args) { dog d = new dog(); animals a = (animals)d; //Up-casting조상인 animals타입으로 형변환 (생략가능) animals a= d dog d2 = (dog)a;//Down-casting자손인 d..

Date와 Calendar만으로 날짜 데이터를 원하는 형태로 다양하게 출력하는 것은 불편하다. 그런 불편함을 해소하고자 만들어진 것이 SimpleDateFormat이다. - 날짜와 시간을 다양한 형식으로 출력할 수 있게 해 준다. import java.text.SimpleDateFormat; import java.util.Date; public class DecimalClass { public static void main(String[] args){ Date today = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); System.out.println(sdf.format(today)); } } 2022-03-06 기호 의미..

java.text 패키지의 DecimalFormat, SimpleDateFormat - 숫자와 날짜를 원하는 형식으로 쉽게 출력이 가능하다. (숫자, 날짜 -> 형식 문자열) import java.text.DecimalFormat; double number = 1234567.89; DecimalFormat df = new DecimalFormat("#.#E0"); String str = df.format(number); //str="1.2E6" DecimalFormat 클래스의 format 메서드를 이용하면 숫자형이 문자열로 바뀔 수 있다. 이 반대도 가능하다. - 형식 문자열에서 숫자와 날짜를 뽑아내는 기능(형식 문자열->숫자, 날짜) DecimalFormat df2 = new DecimalFormat..

다형성(polymorphism) 여러 가지 형태를 가질 수 있는 능력 조상 타입 참조 변수로 자손 타입 객체를 다루는 것 Parent p = new Parent(); //타입일치 Child c = new Child(); //타입일치 Parent p2 = new Child(); //타입불일치 위 3행 코드처럼 조상 타입 참조 변수로 자손 타입 객체를 다루는 것이 가능하다. (참고로 Child는 Parent에게 상속받았다.) class MainClass{ public static void main(String[] args) { Parent p = new Parent(); //타입일치 Child c = new Child(); //타입일치 Parent p2 = new Child(); //타입불일치 } } cla..