일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- php
- redis
- jenkins
- javascript
- jsp
- ReactJS
- 맛집
- MySQL
- JVM
- Spring
- Oracle
- IntelliJ
- it
- 요리
- tool
- laravel
- Web Server
- Spring Batch
- elasticsearch
- devops
- Design Patterns
- Gradle
- db
- java
- ubuntu
- AWS
- Git
- Spring Boot
- linux
- springboot
- Today
- Total
목록Java & Kotlin/Java (110)
아무거나
입력과 출력 앱이 실행중에 입력받기 첫번째 // 자바 라이브러리 import java.util.Scanner; public class ScannerD { public static void main(String[] args) { // System.in : 사용자가 입력할 값 // new Scanner(); : 사용자가 입력한 값을 알아내는 객체 (파일일 경우 파일을 읽을 수 있다.) Scanner sc = new Scanner(System.in); // nextInt(); : 실행되면 자바는 사용자의 입력이 있을 때 까지 변수 i에 값을 // 할당하지 않고 대기상태에 있게 된다. 키보드로 데이터를 입력하고 // 엔터를 누르면 I에 값이 담기면서 나머지 아래 연산을 계산하여 출력해준다.( 대기상태에서 동작..
public : 접근제어자 static : 메소드가 메모리에 인스턴스되는 공간의 주소가 모두 똑같음을 의미 -> static키워드는 매번 자바 언어에서 객체들이 생성되고 이용되는 과정에서 메모리의 기억 장소를 이용한다. 매번 객체들이 생기고 저장되고 참조하는 과정들이 무진장 일어난다. 그래서 메모리를 많이 잡아먹게 된다. 이런 메모리 점유를 조금이나마 줄이고 수행 속도의 증가를 위해 static 키워드를 지정함으로서 static으로 지정된 객체나 메소드에 대해서는 메모리의 똑같은 자리(주소)를 계속해서 사용하므로 메모리의 낭비를 막을 수 있다. 그러나 이런 객체나 메소드는 정적으로 이용되므로 같은 static 객체나 메소드에 의해 호출이되며, 클래스의 초기화시 맨 처음으로 메모리에 적재된다. void :..
import java.utill.*; public class MapEx { // Map은 키값(K)와 Value(V)값을 선언 할 수 있다. Map myMap = new HashMap(); myMap.put(1, "JAVA"); myMap.put(2, "JSP"); myMap.put(3, "Servlet"); // myMap.containsKey (key값 검색해서 같은 키값이 있으면) if ( myMap.containsKey(1) ) { // 1번 키값에 해당하는 value를 리턴함 String str = myMap.get(1); System.out.println(str); } System.out.println("\n====================="); // values() : Map 타입의 ..
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class DateCompare { public static void main(String [] args) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date day1 = null; Date day2 = null; try { day1 = format.parse("2012-12-16"); day2 = format.parse("2012-12-17"); } catch (ParseException e) { e.printStackTrace(); } int compare..
String to Date String from = "2013-04-08 10:10:10"; SimpleDateFormat transFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date to = transFormat.parse(from); Date to String Date from = new Date(); SimpleDateFormat transFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String to = transFormat.format(from);
java.util.Date date = new Date("Sat Dec 01 00:00:00 GMT 2012"); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); // yyyy-MM-dd HH:mm:ss String format = formatter.format(date); System.out.println(format);
[코드예제] import java.text.SimpleDateFormat; import java.util.Calendar; Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, 1); SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd"); // Output "Wed Sep 26 14:23:28 EST 2012" System.out.println(cal.getTime()); String formatted = format1.format(cal.getTime()); // Output "2012-09-26" System.out.println(formatted); // Output "Wed Sep 2..
배포 시스템을 만들때 리눅스 서버에 원격명령을 내리기 위하여 사용했다. import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import org.springframework.stereotype.Repository; import com.jcraft.jsch.Channel; import com.jcraft.jsch.ChannelExec; import com.jcraft.jsch.ChannelS..
switch는 몇가지 제한된 데이터 타입만 사용이 가능하다. byte, short, char, int, enum, String, Character, Byte, Short, Integer
문자와 문자를 비교할 때는 '=='를 사용하지 않고 .equals를 사용한다고 일단은 알아둬야 한다. ( equals는 주소값 비교를 하기 때문에 명확하다 ) String a = "Hoit"; String aa = new String("Hoit"); 이 두가지가 내부에서는 처리하는것이 어떻게 다를까? 먼저 String a = "Hoit"; 이렇게 선언을 하면 메모리 영역중 Heap Area의 Permanent Area에 String Pool로 등록된다. 이렇게 String Pool에 등록되면 프로세스가 종료될때까지 계속 유지된다. String은 사용될때 먼저 String Pool에 등록되있는지 체크하고 처음 등록된 것을 사용하게 된다. 위의 것과는 다르게 String aa = new String("Ho..