본문 바로가기

연습문제/JAVA

(66)
Java- FileExample4번 (p487) //p 487 import java.io.ByteArrayOutputStream; import java.io.IOException; public class Main { //ByteArrayOutPutStream 테스트 public static void main(String[] args) { String msg = "ByteArrayOutputStream test"; ByteArrayOutputStream bao = null; try{ bao = new ByteArrayOutputStream(); //bao는 ByteArrayOutPutStream 타입 변수 //ByteArrayOutputStream : Byte 계열 데이터를 출력하는 기능 bao.write(msg.getBytes()); //bao 문자열..
JAVA - FileExample3번 import java.io.FileOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; //p 485 public class FileOutputStreamTest { //FileOutputStream 테스트 public static void main(String[] args) { FileOutputStream fo = null; String msg = "안녕안녕안녕안녕"; byte [] byteArray = msg.getBytes(StandardCharsets.UTF_8); //문자열 msg를 byte로 가져온다 . // StandarCharsets.UTF_8을 넣어서 안전하게 한글도 사용가능하게 try{ /..
JAVA - FileExample2번 import java.io.FileInputStream; import java.io.IOException; //p 478 479 //예제의 의도 : 파일의 컨텐츠를 어떻게 핸들링? public class FileInputStreamTest { //FileInputStream 테스트 public static void main(String[] args) { FileInputStream fIn=null; try{ // C, C++ : 메모리에 객체를 적재 명령을 하면, 런타임에서 해당 객체를 다 쓰고 난 뒤에 '해제'하는 코드를 넣어야한다 // Java : GARBEGE COLLECTOR (쓰레기 수집기) : new Instance(); 객체를 메모리에 적재하고 GC가 '알아서'메모리 해제 // C, C++ ..
JAVA - FileExample1번 import java.io.File; import java.io.FilenameFilter; import java.io.IOException; //p 471 file예제 public class FileTest1 { public static class ImageNameFilter implements FilenameFilter{ @Override public boolean accept(File dir, String name) { return name.endsWith(".jpg"); } } // File 클래스의 메소드 사용하기 public static void main(String[] args) { System.out.println("C: 드라이브의 전체 파일 출력"); File file = new File..
Java InterfacePractice2 (인터페이스 예제2 - 0811) ======================인터페이스 예제============================ //p 274 ~ 275 public class BusinessLogic { // 웹 어플리케이션이 실제 비즈니스 로직 (DB의 데이터에 따라 처리를 달리 해야하는 경우) 을 수행하는 코드. // //getConnector 호출해서 값을 하나씩 줘서 하나씩 생성. 그래서 팩토리 패턴이다 public static void main(String[] args){ Connector oracleConnector = ConnectorFactory.getConnector("oracle"); oracleConnector.connect(); Connector mySQLConnector = Conn..
Java ExtendsPractice(상속예제 0811) =====================상속 예제====================== //p219 ~ 220 public class Main { public static void main(String[] arg){ Salesman2 sales2 = new Salesman2("오정원", "영업부", 100000000,70000000); System.out.println(sales2.getEmployeeInfo()); } } class Employee2 { String name; String dept; int salary; public Employee2(String name, String dept, int salary) { this.name = name; this.dept = dept; this.salar..
Java 와 DB 연동-2 내가 참고할 코드 (0806) / github 커맨드 수업내용중 github-------------------------------------------------------------- 커맨드) git add . : 파일안에 있는 내용 전부를 add시켜라 git comit -m "initial commit : 커밋하고 커밋내용은 initial commit 여러개 수정파일 커밋 나눠서 해야할경우) 코드뭉치 스테이지에 올리기 > 코드를보고 원하는 파일만 커밋가능 ----------------------------------------------------------------------------------- ==Main== import kr.ac.daegu.ysy.db.DbProcess; import kr.ac.daegu.ysy.input.InputUtil..
Java 와 DB 연동-1 내가 참고할 코드 (0805) Main---------------------------------------------------------------------------------------------------------- public class Main { public static void main(String[] args) throws Exception { // 사용자의 입력을 Scanner로 받아 (clear) // "1" 이외 데이터가 입력될 경우 "다시 입력해 주세요" 하고 다시 입력받을 수 있도록 한다. (clear) // "1" 을 입력받을 경우 mariadb 에서 정의한 Student 테이블의 데이터를 모두 조회하여 출력 한다. // "2" 를 입력 받을 경우 새로운 학생을 추가 한다. String selected..