● Study period: 3/6 to 3/12
● Study scope: Chapter02_sec02

While starting my Java journey, the first thing I noticed was the absolute "Honesty" of the computer. Unlike human conversation, where context and nuance fill the gaps, a computer refuses to work (throws an error) if even the smallest rule is broken.
Understanding "Types" is the key to giving this honest machine clear instructions. Here’s what I’ve learned about how Java handles data.
1. Why is English the Language of IT? (ASCII & Unicode)
I grew curious: "Why are most programming languages based on English?"
Beyond historical reasons, I found the 'Economic Efficiency of the Alphabet' fascinating. Unlike complex characters in Korean or Chinese, the English alphabet fits perfectly within 128 characters (ASCII), making it optimal for early computing environments with limited memory.
This curiosity motivated me to understand Java’s char type (2 bytes, Unicode), which was designed to bridge that gap and embrace global languages.
2. [Key Point] Types are "Glasses" for Data
The most interesting part was the relationship between char and int.
char var1 = 'A'; // Stores Unicode 65
int var2 = 'A'; // Stores Unicode 65
System.out.println(var1); // Output: A
System.out.println(var2); // Output: 65
Internally, both variables store the number 65. However, Java interprets this data through the "glasses" of its Type:
-
charglasses: "Find Unicode 65 and show me the character shape 'A'!" -
intglasses: "This is an integer, so just show me the number 65."
I realized that single quotes (' ') act as a Translation Switch, telling Java to handle the character mapping for us so we don't have to memorize every Unicode number.
3. Why double is the Default for Decimals: Reliability > Efficiency
While int (4 bytes) is the default for integers, why is the 8-byte double the default for decimals instead of the 4-byte float?
The answer is Precision. In decimal calculations, accuracy is everything. Java chooses data reliability over saving a few bytes of memory. Using suffixes like L or f is a way of giving Java explicit guidance—a habit I’m building to write clearer code for my future teammates.
4. char vs. String: Fundamentally Different
I learned that handling a single character (char) and a string of text (String) are entirely different concepts in Java:
-
char: A Primitive Type. Stored as a Unicode number, allowing for calculations. Uses' '. -
String: A Reference Type. Treated as an Object and fundamentally different from numbers. Uses" ".
Understanding that comparing their "size" (e.g., char < String) is logically impossible was a crucial takeaway.
Final Thoughts
Computers are honest and literal. By mastering data types, I’m learning how to communicate with them without any "lost in translation" moments. My goal is to move beyond just writing code that works, toward writing code that is explicit and reliable.
Top comments (0)