100 Days of Code 💻 Day 6 of 100: Java Backend Path 📚⚡ Type Conversion Today’s challenge focused on one of those deceptively simple concepts in Java: type conversion. It may look straightforward when you’re converting "300" into an integer, but in real backend systems, proper type handling is the difference between stable applications and hours of debugging chaos. Trust me, I've had to deal with it. For today’s task, I built a small conversion program that demonstrates four essential operations: ✔️ Converting a String → Integer ✔️ Converting a String → Float ✔️ Converting an Integer → String using valueOf() ✔️ Converting an Integer → String using toString() To complete the challenge, I used the following structure 1. Each conversion is separated into its own clean, single-responsibility method. 2. The program prints the results directly so it's easy to track what occured. 3. And most importantly, the code mirrors patterns used in real backend workflows — not just basic exercises. Working with type conversion might seem trivial at this scale, but it plays a massive role in larger systems. During my backend training at Sber, safe type handling was essential when passing data between different application layers — especially where user input, APIs, or database operations were involved. A small mismatch (like treating a numeric string as a number without validation) could lead to wrong calculations, system errors, or even security flaws. So even with a simple "300" today, the principle is the same: Clean conversions create predictable behavior which, in turn, leads to reliable systems. Tomorrow I move on to the next challenge — one more building block in the journey to becoming a stronger Java backend developer🙌 #100DaysOfCode #Java #BackendDevelopment #TypeConversion #SoftwareEngineering #CodingJourney #LearnInPublic
Java Backend Path: Mastering Type Conversion
More Relevant Posts
-
☕ 𝐁𝐫𝐞𝐚𝐤𝐢𝐧𝐠 𝐃𝐨𝐰𝐧 𝐄𝐱𝐜𝐞𝐩𝐭𝐢𝐨𝐧 𝐁𝐞𝐬𝐭 𝐏𝐫𝐚𝐜𝐭𝐢𝐜𝐞𝐬 𝐢𝐧 𝐉𝐚𝐯𝐚! Ever felt like your Java applications are playing a game of “catch” with unexpected errors? 😅 Mastering exception handling isn’t just about catching errors — it’s about building robust, resilient applications that can gracefully recover when things go wrong. Let’s explore some key best practices that elevate your Java code quality 👇 🧩 𝐂𝐡𝐞𝐜𝐤𝐞𝐝 𝐯𝐬. 𝐔𝐧𝐜𝐡𝐞𝐜𝐤𝐞𝐝 𝐄𝐱𝐜𝐞𝐩𝐭𝐢𝐨𝐧𝐬 Java’s exceptions come in two flavors: 𝐂𝐡𝐞𝐜𝐤𝐞𝐝 𝐄𝐱𝐜𝐞𝐩𝐭𝐢𝐨𝐧𝐬: Compile-time warnings for predictable issues (e.g., IOException). Think of them as a “heads-up” to handle expected failures. 𝐔𝐧𝐜𝐡𝐞𝐜𝐤𝐞𝐝 𝐄𝐱𝐜𝐞𝐩𝐭𝐢𝐨𝐧𝐬: Runtime issues (e.g., NullPointerException). These often signal programming bugs rather than recoverable errors. 💡 𝐄𝐱𝐚𝐦𝐩𝐥𝐞: Trying to open a non-existent file → checked exception Accessing a null object → unchecked exception 🛠 Crafting Custom Exceptions When generic ones don’t cut it, define your own! Subclass Exception or RuntimeException to make your code expressive and self-documenting. For example: InvalidUserCredentialsException > IllegalArgumentException ✅ Improves readability and domain clarity. 🔒 𝐓𝐫𝐲-𝐖𝐢𝐭𝐡-𝐑𝐞𝐬𝐨𝐮𝐫𝐜𝐞𝐬: 𝐓𝐡𝐞 𝐌𝐨𝐝𝐞𝐫𝐧 𝐖𝐚𝐲 Handling files, streams, or database connections? Use try-with-resources (Java 7+). It automatically closes resources — cleaner, safer, and no leaks. 💡 𝐓𝐢𝐩: Replace try-catch-finally blocks with try (FileReader fr = new FileReader("file.txt")) { … }. 🧠 Key Takeaways ✔ Choose between checked & unchecked exceptions wisely. ✔ Create custom exceptions for domain-specific clarity. ✔ Use try-with-resources for all AutoCloseable objects. ✔ Never swallow exceptions — log or rethrow them. ✔ Catch specific exceptions, not generic Exception. Building solid exception handling practices is a hallmark of professional Java development. It transforms fragile code into resilient systems. 💪 𝐇𝐚𝐩𝐩𝐲 𝐂𝐨𝐝𝐢𝐧𝐠! 💻 #𝐉𝐚𝐯𝐚 #𝐏𝐫𝐨𝐠𝐫𝐚𝐦𝐦𝐢𝐧𝐠 #𝐒𝐨𝐟𝐭𝐰𝐚𝐫𝐞𝐃𝐞𝐯𝐞𝐥𝐨𝐩𝐦𝐞𝐧𝐭 #𝐂𝐨𝐝𝐞𝐐𝐮𝐚𝐥𝐢𝐭𝐲 #𝐄𝐱𝐜𝐞𝐩𝐭𝐢𝐨𝐧𝐇𝐚𝐧𝐝𝐥𝐢𝐧𝐠 #𝐇𝐨𝐰𝐓𝐨𝐀𝐥𝐠𝐨
To view or add a comment, sign in
-
-
💡Do You Know about Copy Constructor? 👉 A copy constructor in Java is a special constructor that takes another object of the same class as its parameter and copies its values into the new object. Examples: ▪️ Imagine we have a Student object and we want to make a copy of it. ▪️ A copy constructor allows we to clone the object safely and easily. 👉 Key Points: ▪️ A copy constructor takes one argument: an object of the same class. ▪️ It copies each variable from the existing object to the new object. ▪️ Java does not provide a copy constructor by default; we must write it ourself. ▪️ It creates a deep copy for simple types (like int, String), but for objects, we may need to write a custom deep copy if needed. ▪️ The new object and the original are stored in different memory locations. 💡 Why It’s Useful? ▪️ Allows creating a new object with the same data as an existing object. ▪️ Avoids repeating the same assignments manually for every field. ▪️ Keeps your code clean, short, and easy to understand. ▪️ Ensures the new object is separate, so changes to it don’t affect the original. ▪️ Provides a professional design to your class, especially in real-world applications. 💡 Can we overload a copy constructor? ✅ Yes. Like any constructor, we can overload it — but the common pattern is to have one copy constructor taking a single object. ✌ Finally, ✅ A copy constructor is essential for cloning objects in Java. It simplifies the process, ensures data integrity, and maintains clean code structure. ✅ By mastering copy constructors, We're enhancing our ability to write professional, safe, and maintainable Java code. #Java #JavaPrgramming #LearnJava #JavaSpringBoot #CoreJava #OOPS
To view or add a comment, sign in
-
-
💡 Immutability in Java — why it matters and how to use it effectively Immutability is one of those concepts that makes your Java code safer, cleaner, and easier to reason about. But what does “immutable” really mean? 👇 🧩 What is immutability? An immutable object is one whose state cannot change after it’s created. Once you build it, its data stays the same forever. This prevents unexpected side effects, race conditions, and bugs caused by shared mutable state — especially in multithreaded systems. 🧠 The classic example: String All String objects in Java are immutable. The classic example: String All String objects in Java are immutable String name = "Java"; name.concat(" Rocks!"); System.out.println(name); // "Java" ✅ Even though we called .concat(), it didn’t modify the original string. It returned a new String. ⚙️ final keyword Declaring a variable as final means you can’t reassign the reference — but it doesn’t make the object itself immutable. final List<String> list = new ArrayList<>(); list.add("A"); // ✅ allowed list = new ArrayList<>(); // ❌ not allowed 🧱 record — immutability made easy Since Java 16, record is the easiest way to create immutable data carriers: public record Person(String name, int age) {} Records automatically make fields private and final, and generate constructors, getters, equals(), hashCode(), and toString(). No setters. No mutability. Pure data. 🚀 Why use immutability Makes code thread-safe without synchronization Easier to debug and test Predictable state — no “who changed this object?” moments Simplifies functional programming with Streams and Lambdas 💬 Conclusion: String → always immutable final → prevents reassignment, not mutation record → immutable data structure made simple Immutability is not about restrictions — it’s about predictability and safety. #Java #Backend #CleanCode #Programming #SpringBoot #SoftwareEngineer #DeveloperTip
To view or add a comment, sign in
-
⚙️ Java ClassLoader — How Java Loads Your Classes Before main() Even Runs 🧠 Ever wondered what happens before your public static void main() starts executing? Spoiler: A LOT. The JVM has a behind-the-scenes hero called the ClassLoader — and without it, your entire Java program wouldn’t even start. Let’s break it down 👇 --- 🔹 1️⃣ The Three Core ClassLoaders When you run your app, Java loads classes into memory using this hierarchy: ✔ Bootstrap ClassLoader Loads core Java classes (java.lang, java.util, etc.). Runs in native code — you can’t override it. ✔ Extension (Platform) ClassLoader Loads JARs from the JVM’s lib/ext directory. ✔ Application (System) ClassLoader Loads your classes from the classpath (target/classes, external libs, etc.). Your code runs because this loader finds and loads your .class files 📦 --- 🔹 2️⃣ The Class Loading Process Class loading happens in three phases: 1️⃣ Loading: Find .class → read bytecode → bring it into memory. 2️⃣ Linking: Verify bytecode ✔ Prepare static variables ✔ Resolve references ✔ 3️⃣ Initialization: Run static blocks and assign static variables. Only after this your class is ready. Example 👇 static { System.out.println("Class Loaded!"); } This runs before main(). --- 🔹 3️⃣ Why Developers Should Care Understanding ClassLoaders helps you: Debug “ClassNotFoundException” & “NoClassDefFoundError” better Work with frameworks like Spring (which use custom classloaders) Build plugins or modular architectures Understand how Java isolates and manages classes internally This is deep JVM knowledge — and mastering it makes you a stronger engineer 💪 #Java #JVM #ClassLoader #BackendDevelopment #JavaInternals #SoftwareEngineering #CleanCode #JavaDeveloper
To view or add a comment, sign in
-
🚀 Methods vs. Constructors: Unpacking Key Differences in Java 🚀 New to Java or looking for a quick refresher? Understanding the distinction between Methods and Constructors is fundamental! While both contain blocks of code, they serve very different purposes. Let's break it down with a simple comparison: Constructors: The Blueprint Initializers 🏗️ Purpose: Primarily used to initialize new objects. Think of them as setting up the initial state when an object is first created. Name: Must have the same name as the class itself. Return Type: No return type (not even void). Invocation: Called automatically when you use the new keyword to create an object. Example: new Employee(101, "Alice"); Methods: The Action Performers ⚙️ Purpose: Used to perform actions or operations on an object, or to retrieve information from it. Name: Can have any valid name (following Java naming conventions). Return Type: Must have a return type (e.g., void, int, String, Employee, etc.). Invocation: Called explicitly using the object reference, like object.methodName(). Example: employee.getDetails(); or employee.calculateBonus(); In essence: Constructors build and set up your object. Methods make your object do things. Understanding this distinction is crucial for writing clean, efficient, and object-oriented Java code! Thanks Anand Kumar Buddarapu #Java #Programming #SoftwareDevelopment #OOP #Constructors #Methods #CodingTips
To view or add a comment, sign in
-
-
CompletableFuture in Java: Write Non-Blocking Code That Scales Threads are powerful. But managing them manually quickly gets messy — especially when tasks depend on each other. That’s where CompletableFuture shines. It lets you run async tasks, chain results, and handle errors without blocking. Example: CompletableFuture.supplyAsync(() -> { System.out.println("Fetching data..."); return "Java"; }).thenApply(data -> data + " Developer") .thenAccept(System.out::println); Output: Java Developer Everything runs in the background. The main thread stays free for other work. Key methods to remember supplyAsync() – Starts an async task that returns a value. thenApply() – Transforms the result. thenAccept() – Consumes the result. exceptionally() – Handles errors gracefully. Why it matters CompletableFuture makes async programming clean, readable, and safe. It replaces old patterns with a fluent, functional style that fits modern Java. No callbacks. No blocking. Just smooth, concurrent execution. Real-world use API calls in parallel. Batch data processing. Microservice communication. If you’re still managing threads manually, it’s time to switch. CompletableFuture is how modern Java handles concurrency. Have you tried chaining async calls with CompletableFuture yet? What was your biggest learning? #Java #SpringBoot #Programming #SoftwareDevelopment #Cloud #AI #Coding #Learning #Tech #Technology #WebDevelopment #Microservices #API #Database #SpringFramework #Hibernate #MySQL #BackendDevelopment #CareerGrowth #ProfessionalDevelopment
To view or add a comment, sign in
-
Go vs Java: The Interface Secret That Changes Everything After years of writing Java, switching to Go taught me something that fundamentally changed how I think about code architecture. Go doesn't care if you declare your interfaces. Let me explain what I mean: In Java (Nominal Typing): ```java class MyService implements ServiceInterface { // You MUST explicitly say "implements" // You MUST import the interface // The relationship is declared upfront } ``` In Go (Structural Typing): ```go type MyService struct{} func (s MyService) DoSomething() { // If this matches an interface somewhere, // it just... works. No declaration needed. } ``` Why this matters more than you think: → In Go, you can make third-party libraries implement YOUR interfaces without touching their code → In Java, you need adapters, wrappers, or you're stuck with what the library author gave you → Go's standard library has tiny interfaces (io.Reader is literally one method) → Java interfaces tend to be large because you must declare them upfront The real game-changer: In Go, consumers define interfaces, not producers. You write the interface you need, and anything that matches just works. In Java, producers define interfaces. The library author decides what you can depend on. For testing: - Go: Create a mock by implementing the methods. No frameworks needed. - Java: You're reaching for Mockito because you can't fake an interface without explicitly implementing it. The controversial take: Go's approach is more flexible but less explicit. You can't always tell what implements what just by reading the code. Java's approach is more rigid but crystal clear. Every dependency is declared. I used to think Java's explicit contracts were better. Now I realize Go's flexibility makes code more composable and testable by default. Question Have you worked with both? Which approach do you prefer and why? Drop your experience in the comments - I'm curious to hear different perspectives. #Fonsium #GoLang #Java #SoftwareEngineering #Programming #TechStack #SoftwareDevelopment #Pacti #CodeArchitecture
To view or add a comment, sign in
-
-
Java Developers — Let’s Talk About equals() and hashCode() 🔥 If you’ve ever felt confused about Java’s equals() and hashCode() methods, trust me—you’re not alone. Many developers overlook this fundamental concept, and the result can be disastrous in real-world applications. I’ve personally worked on a project that failed in production because of an incorrect equals-hashCode contract. That experience made me realize how critical this topic really is—especially when using collections like HashSet, HashMap, or working with Hibernate/JPA. So, I decided to break down the entire concept in a clear, practical, and beginner-friendly way — from what these methods actually mean to how to implement them correctly. If you’ve ever: Felt unsure when overriding equals() or hashCode(), used Lombok and hoped it “just works”, or simply avoided the topic 😅 Then this article is definitely for you👇 📌 Read the full breakdown here: https://lnkd.in/grG2aDbR Let’s level up together. Happy coding! 💻✨ #Java #ObjectEquality #HashCodeImplementation #JavaInternals #SoftwareDesign #JavaPatterns
To view or add a comment, sign in
-
🚀 Java Stream API — Simplify Your Data Processing Stream API (introduced in Java 8) helps us process collections in a declarative, functional-style way — reducing boilerplate and improving readability. Let’s explore the two types of Stream operations 👇 ✅ Intermediate Operations ✅ Terminal Operations 🔹 Intermediate Operations (Lazy — return another Stream) filter() → filters elements based on condition map() → transforms each element flatMap() → flattens nested structures sorted() → sorts elements distinct() → removes duplicates limit(n) → takes first n elements skip(n) → skips first n elements peek() → used for debugging (prints intermediate values) takeWhile() → takes elements while condition is true (Java 9+) dropWhile() → skips elements while condition is true (Java 9+) 💡 Intermediate operations are lazy — they don’t execute until a terminal operation is called. 🔹 Terminal Operations (Eager — produce a final result) forEach() → performs an action on each element collect() → collects result into List, Set, or Map count() → returns number of elements reduce() → combines elements into one result findFirst() → returns the first element findAny() → returns any element (useful in parallel streams) anyMatch() → returns true if any element matches condition allMatch() → returns true if all match condition noneMatch() → returns true if none match condition toArray() → returns an array of elements min() / max() → returns smallest/largest element based on comparator 💡 Once a terminal operation is executed, the stream is consumed and can’t be reused. 📘 Quick Summary Intermediate → Transform or filter Terminal → Produce result & close stream Stream can’t be reused after a terminal operation 💬 How often do you use Stream API in your daily coding? Comment your favorite Stream method below 👇 #Java #StreamAPI #Java8 #FunctionalProgramming
To view or add a comment, sign in
-
🚀 Java 8 — The Update That Changed Everything! Java 8 wasn’t just another update — it was a paradigm shift that redefined how we write Java code. It brought modern functional programming to the mainstream and gave us tools that still shape clean, efficient code today. 💡 Let’s look back at some of its most revolutionary features: 1️⃣ Lambda Expressions — The star of the show! Treat functions as method arguments and eliminate boilerplate. Cleaner, functional, and elegant. 2️⃣ Functional Interfaces — The backbone of Lambdas. Think Runnable, Comparator, or even your own single-method interfaces! 3️⃣ Stream API — A declarative and powerful way to process collections. Filter, map, reduce, and sort data seamlessly — in parallel too! ⚡ 4️⃣ Date & Time API (java.time) — Goodbye java.util.Date chaos 👋 Immutable, thread-safe, and beautifully designed for modern needs. 5️⃣ Default Methods — Backward compatibility done right. Add new methods to interfaces without breaking old code. 6️⃣ Method References — The concise cousin of lambdas. Cleaner syntax when all you need is to call an existing method. 7️⃣ Optional Class — The end of NullPointerException nightmares! ☠️ Forces explicit handling of missing values = more robust code. 8️⃣ CompletableFuture — A game changer for async programming. Compose, chain, and combine asynchronous tasks easily. 9️⃣ Nashorn JavaScript Engine — Better integration between Java & JavaScript for embedded scripting. 💬 Java 8 empowered developers with tools that made Java expressive, efficient, and future-ready. 👉 Which of these features do you still find indispensable in your daily coding life? Let’s discuss in the comments! 👇 #Java #Java8 #Programming #SoftwareDevelopment #Tech #Coding #Developer #FunctionalProgramming #CodeQuality #JavaDeveloper
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