본문 바로가기

전체 글

(220)
[JAVA] 예외(Exception) - 로그파일 만들기 Exception 발생시 로그파일 생성 로그파일 생성 예제 import java.io.*; import java.util.*; class ExceptionEx { public static void main(String args[]) { PrintStream ps = null; FileOutputStream fos=null; try { fos = new FileOutputStream("error.log",true); // error.log파일에 출력 준비 ps=new PrintStream(fos); // err의 출력을 화면이 아닌, error.log파일로 변경 System.setErr(ps); System.out.println(1); System.out.println(2); System.out.print..
[JAVA] 파일 클래스(File Class) File class 예제 import java.io.*; public class FileEx{ public static void main(String[] args) throws IOException{ String filePath = "C:\\java_choi\\study"; File f1 = new File(filePath); String list[] = f1.list(); for(int i=0;i
[JAVA] Calendar, Date, SimpleDateFormat 날짜 호출 Date 매서드에 SimpleDateFormat 매서드를 이용해 원하는 양식으로 호출 SimpleDateFormat 예제 import java.util.calendar import java.text.*; class DateFormatEx1{ public static void main(String[] args){ Date today = new Date(); SimpleDateFormat sdf1, sdf2, sdf3, sdf4; sdf1 = new SimpleDateFormat("yyyy-MM-dd"); sdf2 = new SimpleDateFormat("yy년 MMM dd일 E요일"); sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); sdf4 = new..
[JAVA] ArrayList ArrayList: 배열의 크기가 고정적이지 않아 주로 동적으로 데이터를 받아 처리할 경우 사용 ArrayList 예제 import java.util.ArrayList; public class AllTest { public static void main(String[] args) { ArrayList arrList = new ArrayList(); //: 제네릭스 arrList.add("AAA"); //0 arrList.add("BBB"); //1 arrList.add("CCC"); //2 System.out.println(arrList); //리스트 출력 System.out.println("----------"); for(int i = 0; i < arrList.size(); i++){ System.o..
[JAVA] 해쉬맵(HashMap) HashMap 특징 1. Map interface를 implements 한 클래스로 중복 허용 안함 2. key, value 쌍으로 이루어지며 null 허용 3. 가장 처음 넣은 데이터가 index 0 (FIFO) HashMap 예제1 import static java.lang.System.out; import java.util.HashMap; import java.util.Set; class MapEx1 { public static void main(String[] args) { String[] msg = { "Berlin", "Dortmund", "Frankfurt", "Gelsenkirchen","Hamburg" }; HashMap map = new HashMap(); // HashMap생성 for..
[JAVA] Autoboxing / Unboxing 개념 AutoBoxing: 변수를 객체에 대입 UnBoxing: 객체를 변수에 대입 랩퍼클래스와 기본데이터타입간에만 성립 래퍼클래스(Wrapper Class)란? https://coding-house.tistory.com/87 [JAVA] 래퍼 클래스(Wrapper Class) 래퍼클래스(Wrapper Class): 기본이되는 데이터 타입의 클래스 //래퍼클래스(Wrapper Class) //boolean, char, byte, short, int, long, float, double //Boolean, Character, Byte, Short, Integer, Long, Float.. coding-house.tistory.com AutoBoxing, UnBoxing 예제 class AutoboxingEx {..
[JAVA] 래퍼 클래스(Wrapper Class) 래퍼클래스(Wrapper Class): 기본이되는 데이터 타입의 클래스 //래퍼클래스(Wrapper Class) //boolean, char, byte, short, int, long, float, double //Boolean, Character, Byte, Short, Integer, Long, Float, Double class WrapperEx1{ public static void main(String[] args){ boolean b = true; Boolean wrap_b = new Boolean(b); System.out.println("문자열의 값 :"+wrap_b.toString()); //다른타입을 String타입으로 변경 char c = 'A'; Character wrap_c = ne..
[JAVA] 추상클래스와 인터페이스 차이 추상클래스 (abstract class): 추상클래스는 추상메서드를 포함하고 있는 점을 제외하고 일반 클래스와 다른것은 없음 인터페이스 (interface): 오직 추상메서드와 상수만을 멤버로 가질수 있음 차이점: 둘다 추상메서드를 사용하지만 추상클래스는 추상메서드도 사용하는 것이고, 인터페이스는 추상메서드만 사용한다. 참고 인터페이스의 모든 멤버변수는 public static final이 붙어야한다. (생략가능) 인터페이스의 모든 메서드는 public abstract를 붙여야한다. (생략가능)