Last week a junior dev asked me this in a code review: "Why do you always use Long instead of long for IDs?" 10 minutes earlier — I'd probably have said: "Habit. It's just better." But that's a garbage answer. So I actually stopped and thought about it. Here's what I came up with 👇 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ❌ long id; (primitive) → Default value: 0 → Cannot be null → Database NULL? Boom. NullPointerException at unboxing time. → "Is this ID missing or is it genuinely zero?" You can't tell. ✅ Long id; (wrapper) → Default value: null → Can distinguish "not set" from "zero" → Works seamlessly with Spring Data JPA, Jackson, Optional, database NULLs → The 10-byte object overhead is irrelevant in 99.9% of real apps ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ The same logic applies to: → Integer over int (for nullable fields) → Boolean over boolean (for "not answered" states) → BigDecimal over double (for money — ALWAYS) The "use primitives for performance" advice made sense in 2005. In 2026, with Spring Boot apps running on containers with 2GB RAM? Clarity > micro-optimization. Every. Single. Time. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Which Java "obvious habit" did YOU realize was actually wrong after 1-2 years of real work? Drop it below 👇 #Java #SpringBoot #CleanCode #BackendDeveloper #SoftwareEngineering
Why Long Over Primitive Long in Java IDs
More Relevant Posts
-
🚨 Most Developers Don't Realize This in Spring Boot... Everything works fine in the beginning. But as your project grows: ⚠ APIs slow down ⚠ Code becomes messy ⚠ Debugging becomes painful Here are some mistakes I’ve seen (and personally faced): ❌ Writing business logic inside controllers ❌ Ignoring database performance (no indexing, no pagination) ❌ Poor layering structure ❌ No proper logging or exception handling What actually helped me improve: ✅ Clean architecture (Controller → Service → Repository) ✅ Constructor-based dependency injection ✅ Query optimization + pagination ✅ Using Elasticsearch for fast search ✅ Writing scalable and maintainable APIs 💡 Biggest lesson: Backend development is not just about writing APIs — it's about designing systems that scale. Have you faced any of these issues in real projects?.. #SpringBoot #JavaDeveloper #BackendDevelopment #Microservices #SoftwareEngineering #CleanCode #Java #TechCareers #DevelopersLife #CodingJourney #Elasticsearch #PostgreSQL #API #SystemDesign #LearningInPublic #LinkedInTech
To view or add a comment, sign in
-
-
Everything failed… but the database still got updated 🙃. Recently, while working on a feature in Spring Boot project, I used @Transactional annotation assuming it would rollback the entire operation if something failed. But during testing, I noticed something strange, even after an exception, some data was still getting saved. That’s when I started digging deeper. I realized that @Transactional doesn’t always behave the way we expect: - It rolls back only for unchecked exceptions (RuntimeException) by default. - If the method call happens within the same class, it might not work due to proxy behavior. - Catching exceptions without rethrowing can prevent rollback. In my case, I was catching the exception and not rethrowing it. So Spring thought everything was fine and committed the transaction. Once I fixed that, the rollback worked as expected. Annotations make things easier… but understanding how they actually work makes you a better developer. #Java #SpringBoot #BackendDevelopment #Transactional #LearningInPublic #SoftwareEngineering #Database #SpringJPA #DataManagement
To view or add a comment, sign in
-
-
Over the past few weeks, the focus has been on backend development using Spring as part of the ongoing training. Worked through core concepts including designing the service layer, implementing the persistence layer with Spring Data, and building RESTful APIs, along with an assessment to validate these fundamentals. This phase has provided a clearer understanding of layered architecture, data handling, and how backend services are structured to support scalable applications. Looking forward to applying these concepts in building end-to-end applications and strengthening backend development skills further. #SoftwareEngineering #Java #Spring
To view or add a comment, sign in
-
🔧 3 Things I Always Follow While Building APIs in Spring Boot ✅ 1. Keep Controllers Thin → Only handle request & response — no business logic ✅ 2. Write Clear Service Layer Logic → Keep core logic in services for better maintainability and testing ✅ 3. Optimize Database Queries → Efficient SQL = better performance, especially with large data 💡 Small backend decisions today can save hours of debugging tomorrow. Still learning and improving every day 🚀 What practices do you follow while building APIs? #BackendDeveloper #Java #SpringBoot #RESTAPI #SoftwareEngineering #Tech
To view or add a comment, sign in
-
Most "Library Management" projects stop at basic CRUD operations. I decided to take it a step further and build an Enterprise-Grade Digital Library SaaS (SmartLib)! 📚🚀 Over the past few days, I upgraded a raw SQL database into a fully functional, automated Full-Stack application using Java, Spring Boot, and MySQL. 💡 Key Engineering Highlights: 🔹 Automated Background Engine: Engineered a Spring Boot Cron Job (@Scheduled) that runs exactly at midnight to scan overdue books and automatically calculate & update late fines in the database. 🔹 Database-First Architecture: Migrated the core book-issuing logic into MySQL Stored Procedures. This ensures 100% ACID compliance and prevents race conditions if two students try to borrow the last copy at the exact same millisecond. 🔹 Smart Inventory System: Each physical book has a unique ID (Barcode), but the Vanilla JS frontend dynamically groups them by Title/Author for a seamless e-commerce-like user experience. 🔹 Secure 2FA Auth: Built a real-time Email OTP verification system using JavaMailSender that auto-generates unique Hash IDs (e.g., STU-X9A2B) for role-based routing (Admin vs. Student). Building systems where the Database and Backend interact so seamlessly has been an incredible learning curve! 💻🔥 #Java #SpringBoot #SoftwareEngineering #MySQL #DatabaseDesign #CronJobs #WebDevelopment #BackendDeveloper #TechJourney
To view or add a comment, sign in
-
Top 5 mistakes developers make in Spring Boot 🚨 I’ve made some of these myself 👇 ❌ 1. Not using proper exception handling 👉 Leads to messy APIs ❌ 2. Writing fat controllers 👉 Business logic should be in service layer ❌ 3. Ignoring database optimization 👉 Slow queries = slow application ❌ 4. No caching strategy 👉 Repeated DB calls kill performance ❌ 5. Not understanding @Transactional 👉 Can cause data inconsistency 💡 What I learned: Clean architecture + proper layering = scalable system ⚡ Pro Tip: Think like a backend engineer, not just a coder. Which mistake have you made before? 😅 #SpringBoot #Java #CleanCode #BackendDeveloper
To view or add a comment, sign in
-
💡 How many of us REALLY know how "@Transactional" works in Spring Boot? Most developers use "@Transactional" daily… But under the hood, there’s a lot more happening than just "auto rollback on exception". Let’s break it down 👇 🔹 What is "@Transactional"? It’s a declarative way to manage database transactions in Spring. Instead of manually writing commit/rollback logic, Spring handles it for you. --- 🔍 What actually happens behind the scenes? 1️⃣ Spring creates a proxy object around your service class 2️⃣ When a method annotated with "@Transactional" is called → it goes through the proxy 3️⃣ The proxy: - Opens a transaction before method execution - Commits if everything succeeds ✅ - Rolls back if a runtime exception occurs ❌ --- ⚙️ Execution Flow Client → Proxy → Transaction Manager → Target Method → DB --- 🚨 Important Gotchas ❗ Works only on public methods ❗ Self-invocation (method calling another method inside same class) will NOT trigger transaction ❗ By default, only unchecked exceptions trigger rollback ❗ Uses AOP (Aspect-Oriented Programming) --- 🧠 Advanced Concepts ✔ Propagation (REQUIRED, REQUIRES_NEW, etc.) ✔ Isolation Levels (READ_COMMITTED, SERIALIZABLE) ✔ Transaction Manager (PlatformTransactionManager) ✔ Lazy initialization & session handling --- 🔥 Example @Service public class PaymentService { @Transactional public void processPayment() { debitAccount(); creditAccount(); // If credit fails → debit will rollback automatically } } --- ✨ Pro Tip Understanding "@Transactional" deeply can save you from: - Data inconsistencies - Hidden bugs - Production failures --- 👉 Next time you use "@Transactional", remember — you're not calling a method… you're triggering a proxy-driven transaction lifecycle! #SpringBoot #Java #BackendDevelopment #Microservices #TechDeepDive #Learning
To view or add a comment, sign in
-
-
I fixed a memory leak in production last week. Here are 5 things it reminded me about being a better Python developer 👇 1. Profiling before guessing saves hours The moment I stopped assuming and started measuring, the problem became obvious. Tools like tracemalloc and memory_profiler exist for a reason. Use them. 2. The bug is rarely where you think it is I was convinced it was the API layer. It was a background task quietly holding references it had no right to keep. Always follow the data, not your instincts. 3. Quick fixes are expensive in the long run I could've patched it in 20 minutes. Instead, I spent 3 hours doing it right, restructuring the task lifecycle properly. Future me will be grateful. 4. Monitoring is part of the fix A solution without observability is just a delayed problem. We added memory tracking to our dashboards so this never sneaks up on us again. 5. Hard problems make you a better engineer Not the tutorials. Not the easy tickets. The production fires at 4 pm on a Friday; those are the ones that level you up. The server ran clean all weekend. Worth every minute. ✅ What's the toughest bug you've had to hunt down? Drop it below 👇 #Python #SeniorDeveloper #C2C #C2H #C2CJobs #SoftwareEngineering #Debugging #LessonsLearned #PythonDeveloper
To view or add a comment, sign in
-
𝗠𝗼𝘀𝘁 𝗦𝗽𝗿𝗶𝗻𝗴 𝗕𝗼𝗼𝘁 𝗽𝗿𝗼𝗷𝗲𝗰𝘁𝘀 𝗮𝗿𝗲𝗻'𝘁 𝗽𝗿𝗼𝗱𝘂𝗰𝘁𝗶𝗼𝗻-𝗿𝗲𝗮𝗱𝘆. They have controllers. They have CRUD. But they are missing what actually matters. I built a Student Portal API not to tick boxes, but to deeply understand what separates a demo from a deployable system. Here is what that looked like in practice 𝗦𝘁𝗮𝘁𝗲𝗹𝗲𝘀𝘀 𝗔𝘂𝘁𝗵 𝘄𝗶𝘁𝗵 𝗝𝗪𝗧, 𝗻𝗼𝘁 𝘀𝗲𝘀𝘀𝗶𝗼𝗻𝘀 Built a custom JWT filter that intercepts every request before it hits business logic. No session state means horizontally scalable by design. 𝗥𝗲𝗮𝗹 𝗦𝗲𝗰𝘂𝗿𝗶𝘁𝘆, 𝗻𝗼𝘁 𝗰𝗵𝗲𝗰𝗸𝗯𝗼𝘅 𝘀𝗲𝗰𝘂𝗿𝗶𝘁𝘆 BCrypt for password hashing, never plain storage. Spring Security config that locks down endpoints with precision, not a blanket permit-all. 𝗗𝗧𝗢𝘀 𝗼𝘃𝗲𝗿 𝗘𝗻𝘁𝗶𝘁𝘆 𝗘𝘅𝗽𝗼𝘀𝘂𝗿𝗲 Your database schema is not your API contract. Separated entity models from response objects to prevent over-fetching, accidental field leaks, and tight coupling. 𝗣𝗮𝗴𝗶𝗻𝗮𝘁𝗶𝗼𝗻 𝗮𝗻𝗱 𝗦𝗼𝗿𝘁𝗶𝗻𝗴 𝗼𝗻 𝗹𝗮𝗿𝗴𝗲 𝗱𝗮𝘁𝗮𝘀𝗲𝘁𝘀 Most tutorials return everything. Production does not. Built proper paginated responses so the API holds up under real query loads. 𝗖𝗲𝗻𝘁𝗿𝗮𝗹𝗶𝘇𝗲𝗱 𝗘𝘅𝗰𝗲𝗽𝘁𝗶𝗼𝗻 𝗛𝗮𝗻𝗱𝗹𝗶𝗻𝗴 Predictable API behavior means consistent error contracts. One place to catch, format, and return meaningful error responses. 𝗕𝗶𝗴𝗴𝗲𝘀𝘁 𝗶𝗻𝘀𝗶𝗴𝗵𝘁 Authentication is not a login API. It is a request lifecycle problem. Every request must be verified, parsed, and authorized before business logic ever runs. That is what a JWT filter actually solves. 𝗧𝗲𝗰𝗵 𝗦𝘁𝗮𝗰𝗸 Java 17, Spring Boot, Spring Security, JWT, Hibernate, PostgreSQL 𝗖𝘂𝗿𝗿𝗲𝗻𝘁𝗹𝘆 𝗲𝘅𝘁𝗲𝗻𝗱𝗶𝗻𝗴 𝘄𝗶𝘁𝗵 Role-based access control Refresh token rotation Response caching layer If you are building backend projects, stop optimizing for happy paths. 𝗕𝘂𝗶𝗹𝗱 𝗳𝗼𝗿 𝗵𝗼𝘄 𝘀𝘆𝘀𝘁𝗲𝗺𝘀 𝗯𝗲𝗵𝗮𝘃𝗲 𝘂𝗻𝗱𝗲𝗿 𝗿𝗲𝗮𝗹 𝗰𝗼𝗻𝗱𝗶𝘁𝗶𝗼𝗻𝘀. That is what interviewers, code reviewers, and production will test you on. #SpringBoot #Java #BackendDevelopment #SpringSecurity #JWT #SoftwareEngineering #APIDevelopment
To view or add a comment, sign in
-
Day 3 – Tech Stack Tech Stack used in my project: Java Spring Boot Spring Data JPA MySQL REST APIs Focused on building a scalable backend system. #TechStack #Backend
To view or add a comment, sign in
Explore related topics
- Building Clean Code Habits for Developers
- Improving Code Clarity for Senior Developers
- SOLID Principles for Junior Developers
- Ways to Improve Coding Logic for Free
- Why Long Context Improves Codebase Quality
- Coding Best Practices to Reduce Developer Mistakes
- Simple Ways To Improve Code Quality
- Intuitive Coding Strategies for Developers
- Code Planning Tips for Entry-Level Developers
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