본문 바로가기

프로그래밍/JAVA22

sonarQube - Public constants and fields initialized at declaration should be "static final" rather than merely "final" sonarQube - Public constants and fields initialized at declaration should be "static final" rather than merely "final" Making a public constant just final as opposed to static final leads to duplicating its value for every instance of the class, uselessly increasing the amount of memory required to execute the application. Further, when a non-public, final field isn’t also static, it implies tha.. 2022. 7. 22.
sonarQube - Field names should comply with a naming convention. code smell - Field names should comply with a naming convention. Sharing some naming conventions is a key point to make it possible for a team to efficiently collaborate. This rule allows to check that field names match a provided regular expression. Noncompliant Code Example With the default regular expression ^[a-z][a-zA-Z0-9]*$: sonarQube 정적분석에 code smell가 떠서 수정중에 있다. 문제 class MyClass { priva.. 2022. 7. 22.
java8 stream의 쉬운 사용방법 (map, filter, collect) java8 stream의 쉬운 사용방법 (map, filter, collect) java8부터 지원 되는 대표적인 API인 stream에 대해 알아보려고 한다. Stream은 컬렉션, 배열에 저장되어 있는 요소들을 하나씩 참조하며 반복적인 처리를 가능하게 한다. Stream과 람다표현식을 사용하면 for문과 if문을 사용하지 않고도 깔끔하고 직관적이게 코드를 변경 할수있다. 몰라도 당연히 처리 할수 있지만, Strame이 생겨서 컬렉션 배열 계열의 처리가 간단하게 할수 있다 이런말로 요약할수 있다. Stream 특징 몇가지만 알아보자!! 1. Stream은 원본 데이터를 읽기만 하지, 원본데이터 변경을 하지 않는다. 2. Stream은 정렬된 결과를 컬레션이나 배열에 담아 반환 할수있다. ( collec.. 2022. 6. 10.
자바 문자열을 날짜로 변환하기 자바 문자열을 날짜로 변환하기 String -> Date 객체로 변환 import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Test { public static void main(String[] args) { Date date = null; try { date = getDateFromString("20220531111430", "yyyyMMddHHmmss"); } catch (Exception e) { e.printStackTrace(); } System.out.println(date); } public static Date getDateFromString(String dt, Stri.. 2022. 5. 31.
모든 파라미터를 받아 그대로 POST submit 하는 JSP 페이지 모든 파라미터를 받아 그대로 POST submit 하는 JSP 페이지 GET, POST 와 파라미터 갯수에 상관없이 a.jsp를 호출했을때 b.jsp로 POST form submit 하는 jsp를 만들려고 한다. a.jsp 를 통해서 session 처리를 추가하거나 파라미터 유효성검사를 한다거나, 파라미터를 암복호화 처리 하거나, 미리 response.setHeader와 같은 header설정을 진행하고 실제 결과 페이지인 b.jsp로 넘기는 과정이 필요하거나 아래와같은 코드를 통해서 받은 파라미터를 처리할수 있다. a.jsp example 2022. 5. 31.
JAVA REST API 호출, oauth2 연동, example code JAVA REST API 호출, oauth2 연동, example code 최근에 서버사이드 java코드에서 oauth2를 연동할일이 있었는데, java로 호출샘플 코드를 남겨 놓는다. sendPost를 함수 통해 RESTAPI를 호출 하거나, oauth2 연동 호출 하는데 사용하면 되겠다. import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.security.KeyManagementException; import java.security.KeyStoreException; import java.security.NoSuchA.. 2022. 2. 18.