Day 9 of sharing what I’ve learned🚀 Type Casting in Java Type casting is the process of converting a value from one data type to another. In Java, type casting is mainly of two types: 🔹 Implicit Casting (Widening Conversion) Converts a smaller data type to a larger data type Done automatically by the Java compiler No data loss / no precision loss Order of Implicit Casting (Primitives): byte → short → int → long → float → double char → int → long → float → double Example: byte a = 45; double b = a; Why this works? byte uses 1 byte double uses 8 bytes A smaller value easily fits into a larger container ✔ Safe conversion ✔ No explicit syntax required 🔹 Explicit Casting (Narrowing Conversion) Converts a larger data type to a smaller data type Must be done manually by the programmer May cause data loss Example (without casting – ❌ error): double a = 45.5; byte b = a; // Compilation error Correct way (with casting): double a = 45.5; byte b = (byte) a; What happens here? double → byte Decimal part (.5) is discarded Final value of b = 45 ⚠ Possible loss of precision ⚠ Risk of overflow for large values 🔑 Key Takeaways Implicit casting is safe and automatic Explicit casting is manual and risky Always be cautious when narrowing data types Java prioritizes type safety over convenience More coming soon. ✨ #Programming #ComputerScience #SoftwareDevelopment #Developers #Coding #Tech #Engineering #Binary #CPU #Microprocessors #SoftwareEngineer #CSFundamentals #Day9 TAP Academy Sharath R
Java Type Casting: Implicit & Explicit Conversion
More Relevant Posts
-
Understanding Typecasting in Java: Implicit vs Explicit Typecasting is the process of converting one data type into another. It is an essential concept in Java that ensures data compatibility during operations. 🔹 Implicit Typecasting (Widening) This type of casting is done automatically by Java. It converts a smaller data type into a larger data type, making it safe and preventing data loss. Example: int → long → float → double ✅ Automatic ✅ Safe ✅ No data loss 🔹 Explicit Typecasting (Narrowing) This type of casting is done manually by the programmer. It converts a larger data type into a smaller data type, which may result in data loss. Example: double → float → long → int ⚠️ Manual ⚠️ May cause data loss 📌 Key Difference: Implicit casting is automatic and safe, while explicit casting is manual and may cause data loss. Understanding typecasting helps developers write efficient and error-free programs. #Java #Programming #Coding #ComputerScience #SoftwareDevelopment #JavaLearning #Developers
To view or add a comment, sign in
-
-
Today I practiced Implicit and Explicit Typecasting in Java. ✔ Implicit Casting (Widening) – Automatic conversion from smaller to larger data types. ✔ Explicit Casting (Narrowing) – Manual conversion from larger to smaller data types (may cause data loss). Key Learning: byte → int → float (Safe conversion) int → byte (Possible overflow) float → byte (Data loss possible) Strong fundamentals make strong developers 💻🔥 #Java #CoreJava #TypeCasting #JavaDeveloper #Programming #BackendDeveloper #CodingJourney
To view or add a comment, sign in
-
📘 Daily Learning – Day 5 | Java Full Stack Training Today I learned about Type Casting in Java. 🔹 What is Type Casting? Type casting is the process of converting one data type into another data type. There are two types of type casting in Java: 1️⃣ Widening Casting (Implicit Casting) Converting a smaller data type into a larger data type. Done automatically by Java. Example: byte → int //Example for implicity// class Test { public static void main(String[] args) { byte b=10; int i=b; System.out.println(b); System.out.println(i); } } 2️⃣ Narrowing Casting (Explicit Casting) Converting a larger data type into a smaller data type. Must be done manually by the programmer. Example: int → byte //example for Explicity// class Test { public static void main(String[] args) { int i = 20; byte b = (byte) i; System.out.println(i); System.out.println(b); } } #Day5Learning #Java #TypeCasting #FullStackJourney
To view or add a comment, sign in
-
🚀 Learning Core Java – Understanding Type Casting While learning Core Java, I explored the concept of Type Casting, which is the process of converting one data type into another. In Java, there are two types of type casting: ⸻ 🔹 1️⃣ Implicit Casting (Widening) Widening happens when we convert a smaller data type into a larger data type. Java handles this automatically because there is no risk of data loss. byte → short → int → long → float → double 🔹 2️⃣ Explicit Casting (Narrowing) Narrowing happens when we convert a larger data type into a smaller data type. Java does NOT do this automatically because it may cause data loss. The programmer must explicitly mention the target data type. Understanding type casting is important to avoid unexpected data loss and to write more precise Java programs. Excited to continue strengthening my Java fundamentals! 🚀 #CoreJava #JavaLearning #TypeCasting #ProgrammingFundamentals #JavaDeveloper #StudentDeveloper #LearningJourney #CodeNewbie
To view or add a comment, sign in
-
-
Day 6 | Full Stack Development with Java Today’s learning made me realize how important data conversion is while working with Java programs. I explored Type Casting — a concept that controls how data moves between different data types. What is Type Casting? Type casting is the process of converting one data type into another. In Java, this becomes important because Java is a strongly typed language. Two Types of Type Casting I Learned Today: Implicit Casting (Widening) – Automatic Happens when converting a smaller data type to a larger one. No data loss occurs. Example flow: byte → short → int → long → float → double The compiler handles it automatically. Explicit Casting (Narrowing) – Manual Used when converting a larger data type into a smaller one. Requires programmer intervention. Syntax example: byte b = (byte) a; May cause loss of precision, so it must be used carefully. Realization of the Day Understanding type casting helped me see how Java manages memory and prevents unexpected behavior during calculations. Even a small conversion can change program output — which shows why fundamentals matter so much in backend development. Learning step by step and connecting theory with real code is making this journey more interesting every day. #Day6 #Java #TypeCasting #FullStackDevelopment #LearningInPublic #ProgrammingJourney #SoftwareDevelopment
To view or add a comment, sign in
-
-
🚀 Day 4/30 – Java DSA Challenge 🔎 Problem 32: 1343. Number of Sub-arrays of Size K and Average ≥ Threshold (LeetCode – Medium) Today’s problem is a classic Sliding Window (Fixed Size) pattern 🔥 🧠 Problem Statement Given: An integer array arr An integer k (window size) An integer threshold We must return the number of subarrays of size k whose average ≥ threshold. 💡 Key Insight Instead of calculating average every time: 👉 We maintain a running window sum 👉 When window size becomes k, check: (sum/k)≥threshold Even better optimization: Instead of dividing every time, we can compare: sum≥k×threshold This avoids division and makes it faster. ⏱ Time Complexity O(n) → Each element enters and leaves the window once 📦 Space Complexity O(1) → No extra data structures used 📌 Key Learning Fixed-size sliding window avoids recalculating sums Converting average condition to sum comparison improves efficiency Medium problems often test pattern clarity, not complexity 32 Problems Completed 🔥 Day 4 Going Strong 💪🚀 #Day4 #30DaysOfCode #Java #DSA #LeetCode #SlidingWindow #Arrays #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🔄 Bubble Sort Implementation in Java... Today, I implemented the Bubble Sort algorithm in Java to understand sorting logic at a deeper level. Sorting is one of the fundamental concepts in Data Structures, and implementing it manually helps strengthen problem-solving skills. 📌 What This Program Does: ✔️ Takes array input from the user ✔️ Uses nested loops to compare adjacent elements ✔️ Swaps elements if they are in the wrong order ✔️ Sorts the array in ascending order ✔️ Prints the final sorted array 🧠 Logic Behind Bubble Sort: 🔹 Compare arr[j] and arr[j+1] 🔹 If arr[j] > arr[j+1] → Swap 🔹 Repeat the process for n-1 passes 🔹 After each pass, the largest element "bubbles up" to its correct position That’s why it is called Bubble Sort. ⚙️ Concepts Used: 🔸 Arrays 🔸 Nested Loops 🔸 Swapping Technique 🔸 Object-Oriented Programming (Separate Sort Class) 🔸 User Input using Scanner. ⏱️ Complexity Analysis: Time Complexity: 🔹 Worst Case: O(n²) 🔹 Best Case: O(n²) Space Complexity: O(1) (In-place sorting) Implementing basic algorithms manually builds a strong foundation in Data Structures and improves logical thinking step by step. Every small concept learned today becomes confidence tomorrow. 💻✨. 🙏 Grateful to my mentor Anand Kumar Buddarapu sir for continuous guidance and support in strengthening my programming fundamentals. Thanks also to: Saketh Kallepu Uppugundla Sairam #Java #DataStructures #SortingAlgorithms #BubbleSort #Programming #CodingJourney #Learning #JavaDeveloper #BTech
To view or add a comment, sign in
-
-
📘 Day 9 Learning Update | Data Types in Java (Continuation) On Day 9, I continued learning Data Types in Java, focusing on real numbers, character data, boolean values, and different integer representations. 🔹 Real Number Data Types Real numbers are used to store decimal values and are categorized into two types: 🔸 float Size: 4 bytes Precision: Single precision Range: −3.4 × 10³⁸ to +3.4 × 10³⁸ Requires an f suffix to avoid data overflow 🔸 double Size: 8 bytes Precision: Double precision Range: −1.7 × 10³⁰⁸ to +1.7 × 10³⁰⁸ Used when higher accuracy is required 📌 Both float and double values are stored in memory using the IEEE floating-point format. 🔹 Character Data Type Data type: char Size: 2 bytes Characters are stored using Unicode values Internally, characters are converted into binary (base-2) format before being stored in RAM 📌 ASCII (American Standard Code for Information Interchange) is used for basic character representation Example: 'A' → 65 🔹 Boolean Data Type Used to store true / false or yes / no Does not have a fixed size Size is JVM-dependent 🔹 Integer Literals Representation Java supports multiple ways to represent integer values: Decimal Integer – Base 10 (default) Octal Integer – Base 8 Starts with 0 Uses 3-bit representation Hexadecimal Integer – Base 16 Starts with 0x or 0X Uses 4-bit representation Binary Integer – Base 2 Starts with 0b or 0B This session helped me understand how different types of data are represented, stored, and processed at the memory level in Java, strengthening my foundation in core programming concepts. 🚀 Continuing to build strong fundamentals in Java step by step. #Java #DataTypes #JavaBasics #FloatingPoint #CharacterData #Boolean #ProgrammingFundamentals #LearningJourney #Day9Learning
To view or add a comment, sign in
-
-
Was watching a Java video recently where procedural programming was being compared with other paradigms. I think there’s a common misconception around functional programming, especially about data hiding and code reusability. FP is often seen as weak here because it doesn’t use classes or private fields. But in practice, data is hidden by not exposing it at all — only functions are exposed, and data stays immutable behind them. Reusability works differently too. Instead of inheritance, FP leans on small pure functions, higher-order functions, and composition to reuse behavior. Same goals, different mindset.
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development