In domain drivern design, be as specific as possible when defining domain models and database entitites. DO NOT try to generalize them to reduce lines of code. #java
Ismail Khan’s Post
More Relevant Posts
-
The Two Pillars: Primitives vs. References Java clearly separates its data types into two main categories: Primitive Types: These hold the actual value directly. They are simple, memory-efficient, and stored in the Stack Memory. They are the 'nuts and bolts' of computation. Numeric: byte, short, int, long (for whole numbers), float, double (for decimals). Character: char (for a single character). Logical: boolean (for true or false). Reference Types (Objects): These do not store the actual data directly. Instead, they store a reference (a memory address) pointing to the object's location in the Heap Memory. Examples include String, Arrays, and any custom class you create (like Scanner or a custom User class). #Java #development #datatypes #aoftwareengineering #OOPs
To view or add a comment, sign in
-
-
🚀 A Small but Powerful Java Tip — Logging Done Right! Recently, I came across a subtle performance pitfall that often sneaks into production code — string concatenation in log statements. Let’s look at this simple example: log.debug("User data: " + user.getName() + " age: " + user.getAge()); At first glance, it seems fine. But here’s the catch 👉 even if debug logging is disabled in production, the string concatenation will still happen before log.debug() is called! That means: Unnecessary object creation Extra memory usage in the String pool Avoidable CPU overhead ✅ The better approach: use parameterized logging — log.debug("User data: {} age: {}", user.getName(), user.getAge()); With this, the concatenation is skipped entirely if debug logging is off. The logging framework (like Log4j or SLF4J) only processes the message if that log level is actually enabled. 🧠 Takeaway: Even small code choices like this can make your production code a bit leaner and more efficient. Use parameterized logging — save memory, save CPU, and write cleaner logs. #Java #Logging #CleanCode #Performance #BestPractices
To view or add a comment, sign in
-
#SoftwareEngineering #Java #Concurrency #Performance 𝗜𝗺𝗽𝗮𝗰𝘁 𝗼𝗳 𝗣𝗮𝗿𝗮𝗹𝗹𝗲𝗹𝗦𝘁𝗿𝗲𝗮𝗺 𝘄𝗶𝘁𝗵 𝗙𝗼𝗿𝗸𝗝𝗼𝗶𝗻 𝗼𝗻 𝗖𝗣𝗨 𝗮𝗻𝗱 𝗠𝗲𝗺𝗼𝗿𝘆 𝗖𝗼𝗻𝗰𝗲𝗽𝘁 - parallelStream() allows Java Streams to run in multiple threads automatically. - It divides the data into chunks and processes them concurrently using the ForkJoinPool. - The goal is to speed up CPU-bound (not IO-bound) operations on large collections. 𝗛𝗼𝘄 𝗜𝘁 𝗪𝗼𝗿𝗸𝘀 parallelStream() automatically uses the ForkJoinPool.commonPool() to split workloads into subtasks. The main thread divides data, worker threads process chunks concurrently, and results merge back into final output. 𝗖𝗣𝗨 𝗜𝗺𝗽𝗮𝗰𝘁 Worker threads leverage multiple CPU cores for true parallel processing. However, excessive parallelism causes thread contention and context switching overhead, potentially reducing performance despite more cores being utilized. 𝗠𝗲𝗺𝗼𝗿𝘆 𝗜𝗺𝗽𝗮𝗰𝘁 Each parallel task creates intermediate objects during processing, significantly increasing heap memory usage. This leads to more frequent garbage collection cycles, which can offset parallel performance gains if not managed properly. 𝗢𝗽𝘁𝗶𝗺𝗮𝗹 𝗨𝘀𝗮𝗴𝗲 Effective parallel streaming requires balancing task size with available cores, using efficient data structures, and monitoring both CPU utilization and memory allocation to prevent bottlenecks.
To view or add a comment, sign in
-
-
💡 Day 5 of my 𝗝𝗮𝘃𝗮 𝗕𝗮𝗰𝗸𝗲𝗻𝗱 𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻 𝗼𝗳 𝘁𝗵𝗲 𝗗𝗮𝘆 𝘀𝗲𝗿𝗶𝗲𝘀: 🧠 Question: You have a high-performance Java application where multiple threads update shared data. You notice inconsistent results due to race conditions 👉 How would you ensure thread safety and improve concurrency performance? ✅ Answer: Thread safety ensures that shared data remains consistent when accessed by multiple threads. Here’s how to achieve it effectively: 𝐔𝐬𝐞 𝐬𝐲𝐧𝐜𝐡𝐫𝐨𝐧𝐢𝐳𝐞𝐝 𝐛𝐥𝐨𝐜𝐤𝐬 𝐨𝐫 𝐥𝐨𝐜𝐤𝐬 Wrap critical sections with 𝘴𝘺𝘯𝘤𝘩𝘳𝘰𝘯𝘪𝘻𝘦𝘥 or use 𝘙𝘦𝘦𝘯𝘵𝘳𝘢𝘯𝘵𝘓𝘰𝘤𝘬 for finer control. 𝐏𝐫𝐞𝐟𝐞𝐫 𝐜𝐨𝐧𝐜𝐮𝐫𝐫𝐞𝐧𝐭 𝐜𝐨𝐥𝐥𝐞𝐜𝐭𝐢𝐨𝐧𝐬 Replace traditional structures with: - 𝘊𝘰𝘯𝘤𝘶𝘳𝘳𝘦𝘯𝘵𝘏𝘢𝘴𝘩𝘔𝘢𝘱 - 𝘊𝘰𝘱𝘺𝘖𝘯𝘞𝘳𝘪𝘵𝘦𝘈𝘳𝘳𝘢𝘺𝘓𝘪𝘴𝘵 - 𝘉𝘭𝘰𝘤𝘬𝘪𝘯𝘨𝘘𝘶𝘦𝘶𝘦 𝐔𝐬𝐞 𝐀𝐭𝐨𝐦𝐢𝐜 𝐜𝐥𝐚𝐬𝐬𝐞𝐬 For counters or flags, use 𝘈𝘵𝘰𝘮𝘪𝘤𝘐𝘯𝘵𝘦𝘨𝘦𝘳, 𝘈𝘵𝘰𝘮𝘪𝘤𝘉𝘰𝘰𝘭𝘦𝘢𝘯, etc. - faster than locking. 𝐈𝐦𝐦𝐮𝐭𝐚𝐛𝐥𝐞 𝐨𝐛𝐣𝐞𝐜𝐭𝐬 Design data as immutable so threads don’t modify shared state. 𝐄𝐱𝐞𝐜𝐮𝐭𝐨𝐫 𝐅𝐫𝐚𝐦𝐞𝐰𝐨𝐫𝐤 Use 𝘌𝘹𝘦𝘤𝘶𝘵𝘰𝘳𝘚𝘦𝘳𝘷𝘪𝘤𝘦 or 𝘍𝘰𝘳𝘬𝘑𝘰𝘪𝘯𝘗𝘰𝘰𝘭 to manage threads efficiently. ✅ Smart use of concurrency utilities = safer, faster multithreaded code. ⚙️ See you tomorrow for Day 6 👋 #Java #Concurrency #Multithreading #ExecutorService #BackendDeveloper #Performance #ContinuousLearning #QuestionOfTheDay
To view or add a comment, sign in
-
☕ Day 14 of my “Java from Scratch” Series – “Logical Operators in Java” Logical Operators are used to combine multiple conditions and return a boolean result (true or false). 🔹 1. AND (&&) If both values are true, the result will be true. Otherwise, the result is false. T && T => T T && F => F F && T => F F && F => F 🔹 2. OR (||) If any one of the values is true, then the result will be true. If both values are false, the result will also be false. T || T => T T || F => T F || T => T F || F => F 🔹 3. NOT (!) This gives the opposite value of the condition. If it’s true, it becomes false — and vice versa. !T => F !F => T 💡 In simple words: Logical operators are most commonly used in if conditions, loops, and complex decision-making. 👉 Question for you: What will be the result of this code? 👇 int a = 5, b = 10, c = 15; System.out.println(a < b && b < c); (Comment your answer below ⬇️) #Java #Programming #Learning #SoftwareDevelopment #SoftwareEngineering #JavaDeveloper #Logic #Coding #JavaFromScratch #Tech #LogicalOperatorsInJava #NeverGiveUp
To view or add a comment, sign in
-
@Lazy Loading & JdbcTemplate @Lazy delays bean creation until the bean is actually required. This improves startup time and reduces unnecessary initialization. JdbcTemplate simplifies database operations by handling boilerplate code. It manages connections, statements, and exceptions automatically. Together they optimize performance and reduce repetitive code. #SpringFramework #Java #SoftwareEngineering #BackendDevelopment
To view or add a comment, sign in
-
Java 21: Record Patterns Make Code Cleaner Than Ever I’ve been using records for DTOs and value objects for a while now. They cut out a ton of boilerplate — but in Java 21, records got even better. You can now deconstruct a record directly in an if statement or switch expression. Before (manual unpacking): if (obj instanceof Point) { Point p = (Point) obj; int x = p.x(); int y = p.y(); System.out.println("x=" + x + ", y=" + y); } After (record pattern): if (obj instanceof Point(int x, int y)) { System.out.println("x=" + x + ", y=" + y); } No casts, no extra variables — just clean, direct access to the data. Why I like it: ✅ Fewer lines and fewer mistakes ✅ Great for pattern-based logic and DTOs ✅ Works beautifully with switch expressions Small change, big clarity. 👉 Have you tried record patterns yet? #Java #Java21 #Records #CleanCode #SoftwareEngineering #Refactoring
To view or add a comment, sign in
-
🚀 Java tip: 10× concurrency with (almost) one line—Virtual Threads If your REST service spends time waiting on I/O (DB, HTTP calls), you can often scale without rewriting everything—just switch your executors to virtual threads. // Before var exec = Executors.newFixedThreadPool(200); // After (Virtual Threads) var exec = Executors.newVirtualThreadPerTaskExecutor(); // Example try (exec) { var futures = urls.stream() .map(u -> exec.submit(() -> httpClient.send(request(u)))) .toList(); for (var f : futures) f.get(); // simple fan-out/fan-in } Why it helps 🧵 Virtual threads are lightweight → you can run thousands without choking the OS. ⏱️ Great for blocking I/O code you don’t want to fully rewrite to reactive. 🔄 Works with familiar APIs (JDBC, HTTP clients) so the learning curve is tiny. Gotchas Use timeouts + bulkheads; virtual threads are cheap, not free. Keep CPU-bound work on a bounded pool (don’t flood the cores). Measure real latency/throughput with production-like loads before flipping the switch. I’ve started adopting this pattern in services that rely on DB + external APIs and saw smoother tail latencies with minimal code changes. #Java #VirtualThreads #ProjectLoom #SpringBoot #Performance #Backend #SoftwareEngineering #JVM
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
Never ever generalise translation tokens based on English.