Programing/JAVA

getOrDefault( Object key,V defaultValue ) - Java 8에서 추가된 Collection API 함수들 중 일부이다. 찾는 key가 존재한다면 찾는 key의 value를 반환하고, 없거나 null이면 default 값을 반환한다. package four.one; import java.util.HashMap; import java.util.Scanner; public class test { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str=in.next(); HashMap map=new HashMap(); for(char x : str.toCharArray()){ m..
InputAge = 2012-01-10 public String getAge(String InputAge) { //현재 년도 구하기 Calendar now = Calendar.getInstance(); //년월일시분초 Integer currentYear = now.get(Calendar.YEAR); //태어난년도를 위한 세팅 SimpleDateFormat format = new SimpleDateFormat("yyyy"); String stringBirthYear = format.format(InputAge); //년도만받기 //태어난 년도 Integer birthYear = Integer.parseInt(stringBirthYear); // 현재 년도 - 태어난 년도 => 나이 (만나이X) int ag..
로그를 보다가 어떤 값에 null 이 들어온 것을 보고 null 체크를 하려고 기존에 되어있던 if ( test != null || !"".equals(test) ) { ~ } else { ~ } 이런 식으로 코드를 짜서 했는데 생각대로 안되길래 하나하나 뜯어보려고 public void nullCheck() { String test1 = null; log.info(".equals(test1) >> " + ("".equals(test1)) ); log.info("null==test1" + (null==test1) ); String test2 = ""; log.info(".equals(test2) >> " + ("".equals(test2)) ); log.info("null==test2" + (null==t..
- DecimalFormat class 를 사용 String value = "5000000"; int int_value = Integer.parseInt(value); DecimalFormat decimalFormat = new DecimalFormat("###,###"); String DecValue = decimalFormat.format(int_value); log.info("DecValue >> " + DecValue);
lombok 를 사용해서 Getter / Setter 를 사용 중인데 @Data public class test_VO { @Param(description ="테스트아이디", required=false, sample="") private String testId; @Param(description ="테스트이름", required=false, sample="") private String testName; @Param(description ="테스트test", required=false, sample="") private String tEstTest; } 이런 식으로 만들어서 사용 중인데 testId, testName 은 데이터가 잘 들어오는데 tEstTest 는 데이터가 들어오지가 않았다... 확인해 ..
import java.util.HashMap; import java.util.Iterator; import java.util.Map; public class MapIterationSample { public static void main(String[] args) { HashMap hashMap = new HashMap(); hashMap.put("test3", "name5"); hashMap.put("test4", "name2"); hashMap.put("test5", "name1"); hashMap.put("test1", "name3"); hashMap.put("test2", "name4"); System.out.println("=================Type1================="..
코드 package com.example; import java.io.IOException; import java.net.Inet4Address; import java.net.ServerSocket; import java.net.UnknownHostException; public class ip { private ServerSocket serversock; public ip(int port) { try { System.out.println("[ip] : "+Inet4Address.getLocalHost().getHostAddress()); serversock = new ServerSocket(port); System.out.println("[iport] : "+port); } catch (UnknownH..
소켓 통신을 공부하다가 잘 정리된 글을 발견하여 참조하기 위해서 공유합니다. 참조한 블로그 : https://m.blog.naver.com/highkrs/220840680504 [Java 강의91] 자바 소켓 통신 안녕하세요 모프 입니다. 이번엔 자바에서 TCP/IP 소켓 통신을 배워보려고 합니다. 강의를 하기 이전... blog.naver.com Server 쪽 소스코드 package socket.server; import java.io.IOException; import java.io.OutputStream; import java.net.ServerSocket; import java.net.Socket; public class MainServer { public static void main(Stri..
Java에서 파일 생성을 하는 방법 1. FileWriter를 이용한 파일 생성 import java.io.*; public class test { public static void main(String[] args) { String txt = "테스트입니다!!" ; String fileName = "/Users/hyunchang/Downloads/logTestFile.log" ; try{ // 파일 객체 생성 File file = new File(fileName) ; // true 지정시 파일의 기존 내용에 이어서 작성 FileWriter fw = new FileWriter(file, true) ; // 파일안에 문자열 쓰기 fw.write(txt); fw.flush(); // 객체 닫기 fw.clos..
import java.net.InetAddress; public class IpDisplay { public static void main(String[] args) { // TODO Auto-generated method stub try{ InetAddress ip = InetAddress.getLocalHost(); // => 컴퓨터명/IP 출력 String source_id = ip.getHostAddress(); // => IP 출력 }catch(Exception e){ System.out.println(e.getMessage()); } }
Java에서 스케줄링을 할 때 Quartz를 많이 사용합니다. Quartz에서 사용하는 Trigger는 SimpleTrigger와 CronTrigger가 있는데요. 간단하게 특징을 보면 다음과 같습니다. SimpleTrigger : 간단하며 interval, delay, repeat times 등을 설정할 수 있습니다. 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 org.quartz.simpl.SimpleThreadPool 5 4 org.quartz.simpl.RAMJobStore 60000 Colored by Color Scriptercs CronTrigger : Linux에서 사용하는 cr..
- 광속거북이 -
'Programing/JAVA' 카테고리의 글 목록