Java Data Types & Operators: Understanding Evaluation & Casting

🚀 Day 12 – Java Full Stack Journey | Deep Dive into Data Types & Operators Today’s session was all about understanding how Java actually evaluates expressions behind the scenes. Not just writing code — but thinking like the compiler. 🧠 --- 🔹 1️⃣ Integer Division & Truncation int a = 25; int b = 2; System.out.println(a / b); // 12 ✔ int / int → result is always int ✔ Decimal part gets truncated (12.5 → 12) Java does not round — it truncates. --- 🔹 2️⃣ Type Promotion in Arithmetic Operations In Java, when arithmetic operators are used: > The result is promoted to the larger data type. byte x = 5; x = x * 10; // ❌ Error Why? Because x * 10 becomes int, and Java cannot store int into byte without explicit casting. --- 🔹 3️⃣ Assignment Operators (+=, -=, *=, /=) byte x = 5; x += 10; // ✅ Works ✔ Assignment operators automatically handle implicit casting. ✔ Important difference from normal arithmetic expressions. --- 🔹 4️⃣ Pre & Post Increment – Real Understanding ++x // Pre → Change first, then use x++ // Post → Use first, then change Mastering this avoids logical mistakes in complex expressions. --- 🔹 5️⃣ Octal & Integer Literals Trap int y = 010; // Octal → Decimal 8 ✔ A leading 0 makes it octal ✔ Small details can completely change the output --- 💡 Today’s Realization Java is strict about: • Data types • Type casting • Operator behavior • Expression evaluation Small misunderstandings can lead to wrong outputs — especially in interviews. Learning to analyze before assuming the output. 🚀 TAP Academy #Day12 #Java #FullStackJourney #CoreJava #DataTypes #TypeCasting #JavaDeveloper #LearningInPublic #100DaysOfCode

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories