일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
- 후기
- SQL
- mssql
- oracle
- mysql
- java
- 리눅스
- IntelliJ
- 책
- MariaDB
- docker
- Linux
- pandas
- 독서
- git
- 인터페이스
- 오블완
- github
- 넥사크로
- 명령어
- springboot
- 네트워크
- Python
- 인덱스
- 책추천
- spring
- 티스토리챌린지
- PostgreSQL
- Javascript
- DBMS
- Today
- Total
목록JAVA (61)
hanker
LocalDate Class 안에 plusMonths() 메서드 * 날짜범위를 벗어난 경우 DateTimeException 발생 LocalDate date = LocalDate.of(2023, 1, 1); LocalDate mon = date.plusMonths(1); 결과 : mon = 2023-02-01 LocalDate mon = date.plusMonths(2); 결과 : mon = 2023-03-01 LocalDate mon = date.plusMonths(3); 결과 : mon = 2023-04-01 LocalDate mon = date.plusMonths(4); 결과 : mon = 2023-05-01

beforeDate - 이전 날짜 nowDate - 현재 날짜 public void monthValue(LocalDateTime beforeDate, LocalDateTime nowDate) { int monthA = beforeDate.getYear() * 12 + beforeDate.getMonthValue(); int monthB = nowDate.getYear() * 12 + nowDate.getMonthValue(); return monthB - monthA; }
메소드 또는 변수를 구현(implements)하는가 그대로 사용(extends)하는가에 따라서 형태가 갈린다. extends(상속) 상속의 대표적인 형태 부모의 메소드를 그대로 사용 오버라이딩(재정의)할 필요 없이 부모에 구현되있는 것을 직접 사용 가능 JAVA는 다중상속을 지원하지 않는다. 그래서 implements를 사용(상속이라고 말한 순 없지만..) implements (상속) 부모의 메소드를 반드시 오버라이딩(재정의)해야 함 다중상속을 대신해준다.

toString Object 클래스가 가진 메소드 객체가 가지고 있는 정보나 값들을 문자열로 만들어 리턴하는 메소드 Spring boot VO(DTO)클래스에서 사용하는 toString 메소드는 Object클래스에 있는 toString() 메소드를 오버라이딩하여 사용(재정의) toString 사용 및 재정의 한번 실행해보자 뭔가 출력되긴 했지만 무슨 값인지 확인이 안된다. 이때 재정의를 해서 사용한다. Favorite.java에서 toString() 메서드 추가 결과
import org.json.JSONException; import org.json.JSONObject; import java.io.*; import java.net.URL; import java.nio.charset.Charset; public class JsonParseTest { public static void main(String ar[]) throws Exception{ String url = "Json Data를 가져올 URL"; JSONObject json = readJsonFromUrl(url); System.out.println(json.toString()); } private static String jsonReadAll(Reader reader) throws IOException{ ..
String to Date (String → Date) String에서 Date로 형변환 SimpleDateFormat transFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date to = transFormat.parse("Date로 변환할 String Data"); Date to String (Date → String) Date에서 String으로 형변환 SimpleDateFormat transFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String to = transFormat.format("String으로 변환할 Date data");
pom.xml에 org.json 을 추가한다. org.json json 20180130 json 추가가 완료되면 테스트 코드를 작성한다. import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import org.apache.commons.io.IOUtils; import org.json.JSONObject; import org.json.XML; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; public class xmltoJson { public static vo..
public static void zipDirectory(String dir, String zipfile) throws IOException, IllegalArgumentException{ //파일리스트 가져오기 위해 객체 생성 File d = new File(dir); //디렉토리 존재유무 if(!d.isDirectory()) throw new IllegalArgumentException("Not a directory : " + dir); //해당 경로의 파일을 배열로 가져옴 String[] entries = d.list(); //파일 복사를 위한 버퍼 byte[] buffer = new byte[4096]; int bytesRead; //zip파일을 생성하기 위한 객체 생성 ZipOutputStrea..
- ssh Keygen 등록되었다는 가정하에 소스 (기존 ssh 명령어를 통해 외부서버 접속 시 password 입력을 해야하지만 keygen 등록 시 패스워드 없이 서버 접속가능) (ssh keygen 등록 시) public static void main(String ar[]) throws Exception{ String execStr = "ssh 접속서버계정@서버IP Command"; // ex) "ssh test@1.1.1.1 rm -r /data/reData/text.txt"; Process ps = Runtime.getRuntime().exec(execStr); ps.getErrorStream(); ps.getInputStream(); ps.getOutputStream(); ps.waitFor(..