Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Node.js vs. Python for Backend: 7 Reasons C-Level Leaders Choose Node.js Talent

      July 21, 2025

      Handling JavaScript Event Listeners With Parameters

      July 21, 2025

      ChatGPT now has an agent mode

      July 21, 2025

      Scrum Alliance and Kanban University partner to offer new course that teaches both methodologies

      July 21, 2025

      Is ChatGPT down? You’re not alone. Here’s what OpenAI is saying

      July 21, 2025

      I found a tablet that could replace my iPad and Kindle – and it’s worth every penny

      July 21, 2025

      The best CRM software with email marketing in 2025: Expert tested and reviewed

      July 21, 2025

      This multi-port car charger can power 4 gadgets at once – and it’s surprisingly cheap

      July 21, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Execute Ping Commands and Get Back Structured Data in PHP

      July 21, 2025
      Recent

      Execute Ping Commands and Get Back Structured Data in PHP

      July 21, 2025

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 21, 2025

      Zero Trust & Cybersecurity Mesh: Your Org’s Survival Guide

      July 21, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      I Made Kitty Terminal Even More Awesome by Using These 15 Customization Tips and Tweaks

      July 21, 2025
      Recent

      I Made Kitty Terminal Even More Awesome by Using These 15 Customization Tips and Tweaks

      July 21, 2025

      Microsoft confirms active cyberattacks on SharePoint servers

      July 21, 2025

      How to Manually Check & Install Windows 11 Updates (Best Guide)

      July 21, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Integral to a Database Read

    CodeSOD: Integral to a Database Read

    June 5, 2025

    One of the key points of confusion for people unfamiliar with Java is the distinction between true object types, like Integer, and “primitive” types, like int. This is made worse by the collection types, like ArrayList, which needs to hold a true object type, but can’t hold a primitive. A generic ArrayList<Integer> is valid, but ArrayList<int> won’t compile. Fortunately for everyone, Java automatically “boxes” types- at least since Java 5, way back in 2004- so integerList.add(5) and int n = integerList.get(0) will both work just fine.

    Somebody should have told that to Alice‘s co-worker, who spends a lot of code to do some type gymnastics that they shouldn’t have:

    try {
    		ps = conn.prepareStatement(SQL_GET_LOT_WORKUP_STATUSES);
    		ps.setLong(1, _lotId);
    
    		rs = ps.executeQuery();
    
    		while (rs.next()) {
    				result.add(new Integer(rs.getInt(1)));
    		}
    }
    finally {
    		CloseUtil.close(ps,rs);
    }
    
    // instatiate a the array
    _workupStatuses = new int[result.size()];
    
    // convert the integers to ints
    for (int h=0; h<result.size(); h++) {
    		_workupStatuses[h] = ((Integer)result.get(h)).intValue();
    }
    

    This runs a query against the database, and then iterates across the result to populate a List type with integers, and right away we’re getting into confused territory. rs.getInt returns an int primitive, which they manually box with new Integer, and stuff into the List. And look, I wouldn’t really call that a WTF, but it’s what they do next that leaves me scratching my head.

    They initialize a private member, _workupStatuses to a new array of ints. Then they copy every integer from the result collection into the array, first by casting the get return value to Integer, then by pulling off the intValue.

    In the end, this whole dance happens because Java ResultSet types open cursors on the database side and thus don’t have the capacity to tell you how many rows they returned. You need to iterate across each record until it runs out of results. That’s why they populate an intermediate list. Then they can check the size and create an array, but that itself is a big why. I’m not going to say that using arrays in Java is an instant anti-pattern, but it’s always something to be suspicious of, especially when you’re holding result sets. It’s probably a premature optimization: the key performance distance is on insertions where an ArrayList may need to resize and copy its internal backing store.

    My suspicion, however, is that this code falls into the category of “C programmer forced to do Java”. They’re comfortable with an array of integers, which is covers 90% of the data types you use in C but a dynamic, complicated data structure is horrifying to them. So they use it when they absolutely have to, and then throw it away as quickly as they can to get back to what they’re familiar with.

    [Advertisement] Plan Your .NET 9 Migration with Confidence
    Your journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleFOSS Weekly #25.23: Helwan Linux, Quarkdown, Konsole Tweaks, Keyboard Shortcuts and More Linux Stuff
    Next Article FuguIta is a live system based on the OpenBSD operating system

    Related Posts

    News & Updates

    Is ChatGPT down? You’re not alone. Here’s what OpenAI is saying

    July 21, 2025
    News & Updates

    I found a tablet that could replace my iPad and Kindle – and it’s worth every penny

    July 21, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Failing well and 3 other ways AI can help you solve your big business problems

    News & Updates

    CVE-2025-53889 – Directus Unauthenticated Flow Trigger Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    How Kepler democratized AI access and enhanced client services with Amazon Q Business

    Machine Learning

    CVE-2025-36527 – Zohocorp ManageEngine ADAudit Plus SQL Injection Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    Paid proxy servers vs free proxies: Is paying for a proxy service worth it?

    June 13, 2025

    Debating between a paid or free proxy service? These are the benefits and potential issues…

    1000+ Unique IPs Attacking Ivanti Connect Secure Systems to Exploit Vulnerabilities

    April 24, 2025

    CVE-2025-53277 – Infigo Software IS-theme-companion CSRF Object Injection

    June 27, 2025

    The NestJS Handbook – Learn to Use Nest with Code Examples

    June 13, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.