자바에서 데이터 타입은 크게 기본 타입(primitive type)과 참조 타입(reference type)으로 구분된다.이번 포스팅에서는 이 참조 타입에 대해서 좀 더 자세히 다뤄보도록하자. 🟩 데이터 타입의 분류기본 타입으로 선언된 변수와 참조 타입으로 선언된 변수의 차이점은 저장되는 값이다.기본 타입으로 선언된 변수는 값 자체를 저장하고 있지만,참조 타입으로 선언된 변수는 객체가 생성된 메모리 *번지를 저장한다.( *번지란?데이터가 저장되어 있는 기억 장소의 위치)예를 들어보자.// 기본 타입 변수int age = 25;double price 100.5;// 참조 타입 변수String name = "신용권";String hobby = "독서";이렇게 변수들을 선언했을 때, 메모리 상에서 이 변수..
🟩 switch 문 (how to handle multiple case)- No swich expressions (before Java 12) If you omitted break keyword in case, the following case executes in a row. In this case, it executes regardless of the value of case. ex) int currentTime = (int) (Math.random() * 11) + 7; // 7 8 9 10 11 12 13 14 15 16 17 switch (currentTime) { case 7 : System.out.println("출근 시간!"); break; case 8: case..
🟩 부호 연산자부호 연산자는 말그대로 변수의 부호를 유지하거나 변경한다. 부호연산자에는 +, - 가 있는데, 각각 피연산자의 부호 유지, 피연산자의 부호 변경의 기능이 있다. byte a = 100;int result = -a;( 여기서, byte result = -a; 라고 하면 에러난다!! 왜냐하면 정수 타입(byte, short, int)의 연산 결과는 int타입이기 때문이다. ) 부호연산자 +는 잘 사용되지 않고, - 연산자는 변수값의 부호를 변경할 때 사용된다. 🟩 증감 연산자증감 연산자는 ++과 -- 두개가 있다. 각각 변수의 값을 1증가, 1감소 시킨다.이때, 변수 단독으로 증감 연산자가 사용될 경우에는 변수의 앞뒤 어디에 붙어도 결과는 동일하다.즉, ++i, i++ 모두 i = i ..
The bitwise AND operation with 255 is really helpful in keeping the lowest 8 bits and remeoves the negaitive sign bits added during int conversion. For example, A C program in Embedded System is trying to send some data to external java program. C has uint8_t type, this type is 1byte and has value of 0~255 range. If the C program sent the 136 in binary, uini8_t type, java read this binary as -1..
"이것이 자바다(신용권, 임경균)(1권)" 참고함.--------------------------------------------- 자바에서 말하는 타입 변환에는 두 가지가 있다. (자동 타입 변환, 강제 타입 변환) 각각 설명해보자면,🟩 자동 타입 변환 : 말 그래도 자동으로 타입 변환이 일어나는 것을 말한다.자동 타입 변환은 값의 허용 범위가 작은 타입이 허용 범위가 큰 타입으로 대입될 때 발생한다. 기본 타입을 허용 범위 순으로 나열하면 다음과 같다.byte char 아래는 자동 타입 변환의 예시이다. (int타입이 byte타입보다 허용 범위가 더 크기 때문 --> 자동 타입 변환!)byte byteVar = 10;int intVar = byteVar; // 자동 타입 변환! 또 정수 타입이..
이번 글에서는 자바의 primitive 타입 8개 중에서 내가 몰랐던, 또는 애매하게 알고 있었던 부분을 정리하려고 한다. 내용은 "이것이 자바다(신용권, 임경균)" 책(1권)을 참고하였다. 🟩 변수가 메모리에 할당되는 순간 변수가 메모리에 할당되는 순간 = 변수 초기화 순간 이다. 보충설명을 하겠다. 여기서 말한 변수 초기화라는 건, 변수에 최초로 값이 대입될 때를 말한다. 즉, 아래코드를 보면 mathScore은 변수에 최초로 값이 대입되었으니, 변수 초기화가 이루어진 것이고, 해당 변수는 메모리에 할당된다. 반면에 englishScore은 변수 초기화가 이루지지않고, 단순히 변수 선언(= 저장되는 값의 타입과 이름만 결정하는 행위)만을 한 것이므로, 메모리에 할당되지 않았다. class Hell..
To understand teh difference of Primitive Data type and Reference Data (Non-Primitive Data) type in java,We need to understand the concept of a Pointer in C.🟩 What is a Pointer in C ? A pointer is a variable that stores the memory address of another variable. Instead of holding a direct value, it holds the address where the value of the variable is stored in memory. Accessing the pointer direc..
What is Java Anonymous Class?An anonymous class is a class without a name. It is created and used at the same time.You often use anonymous classes to override methods of an existing class or interface,without writing a separate class with extends or implement keyword. When to Use Anonymous Classes?Use anonymous classes when you need to create a short class for one-time use. For example:Overridin..