Primitive : 원어, 원시의, 원시적인
- Primitive types are the most basic data types available within the Java language.
Reference : 참조, 언급, 관련
- A reference type is a data type that's based on a class rather than on one of the primitive types that are built in to the Java language.
The new keyword isn't used when initializing a variable of a primitive type.
public class Test {
int a;
public void test() {
System.out.println(a);
}
}
> Console : 0
It stores the address where the value is being stored.
String veryImpressive = "영수증";
Happy todayHappy = new Happy();
> 값이 저장되어 있는 곳의 주소값 저장.
switch (------Enum.getByValue(---------)) {
case MYSQL :
outVo = ----.selectStaffByMysql(inVo);
break;
case ORACLE :
outVo = ----.selectStaffByOracle(inVo);
break;
default :
outVo = null;
break;
}
public enum ------Enum implements IEnum {
MYSQL("MYSQL"), ORACLE("ORACLE"), OCEANBASE("OCEANBASE");
---
}
> Class가 아닌 Enum
단순 문법상의 에러
public class Test {
long looooong;
public void test() {
System.out.println(looooong);
}
}
> Compile error : Insert ";" to complete BlockStatements.
지역변수
public class Test {
public void test() {
int a;
System.out.println(a);
}
}
> Compile error : The local variable a may not have been initialized.
런타임 에러
public class Test {
int[] arr;
public void test() {
for (int num : arr) {
System.out.println(num);
}
}
}
> NullPointerException: Cannot read the array length because "this.arr" is null.
List<int> intList; // 불가능
List<Integer> integerList; // 가능
List<String> strList; // 가능
> List나 Map을 쓸 때 무심코 Integer를 넣었다.
> 왜?
> List는 E를 필요로 한다.
> E는, 클래스 객체이기만 하면 어떤 객체라도 받을 수 있다는 의미
int M = Integer.valueOf(br.readLine()); // 불가능
int N = Integer.parseInt(br.readLine()); // 가능
Integer ii = new Integer( i );
> 값 형식 -> 참조 형식(암시적)
> new가 붙어 있다!
int i = ii.intValue();
> 참조 형식 -> 값 형식(명시적)
int i = 1;
Integer integer = i; // int -> Integer (Auto boxing)
int i2 = integer; // Integer -> int (Auto unboxing)
> 통상 Auto boxing/unboxing을 해준다.
public interface SampleRepository extends JpaRepository<Sample, Long>, JpaSpecificationExecutor<Sample>{
Optional<Sample> findOneByTitle(String title);
Page<Sample> findAllByTitle(String title, Pageable pageable);
List<Sample> findAllByTitle(String title);
}
> 다르다.
public class Test {
int a = 1;
Integer b = 1;
}
> F3 눌러도 int는 아무 일도 없다...
> Integer를 클릭하면?
> 약 1,800줄의 Integer class가 등장한다.
ORACLE Java Documentation/Primitive Data Types
WIKIPEDIA/Value type and reference type
Stackoverflow
Tistory 개발새발 blog - 사전적 의미 캡처 발췌
Tistory includestudio blog - int와 Integer의 차이 본문 및 캡처 발췌