On Java Development

All things related to Java development, from the perspective of a caveman.

Archive for the ‘Java Lists and Maps’ Category

Reconciling ArrayList contents with the Comparator class

without comments

Introduction

This post explains how to use the Comparator class to reconcile the contents of two arraylists. As an example of use, this technique can be helpful when there is a need to know what was changed in a pick list. This information can then be used to log the “who-what-when” questions about the edit session.
Read the rest of this entry »

Written by admin

March 11th, 2016 at 1:20 pm

Creating Summary Data using SQL Count(*) and Hibernate

without comments

Introduction

This post shows how to implement a SQL statement with a Count(*) function using Hibernate. This creates a record set that doesn’t map to an existing entity, so the coding needed to pull the data out of the resulting list and to then put them into a container class is a bit different than usual when using Hibernate and mapped entities.

This post also goes beyond being a simple presentation about an SQL statement inside a DAO. Along the way, it explains many Java development concepts that every developer should know. It also exposes forces that should cause the developer to recognize the need for a certain Java Design Pattern.

Maybe this post should have been called “How to Design an Application to use a Mini-Architecture including Services, Business Objects, Data Access and Transfer Objects while using Hibernate to summarize records.“, but the focus is still about how to use the Count(*) function with Hibernate.
Read the rest of this entry »

Iterating through a Hashmap

without comments

Introduction

Unlike Lists, and ArrayLists should come to mind, Maps don’t have an iterator() method like that provided by the Set or List classes. However, you can iterate through the keys or the key-value elements.

There are a few different types of maps such as HashMap, TreeMap and LinkedHashMap. The ordering of the elements in each differ a bit depending on the type of map.
Read the rest of this entry »

Written by admin

March 28th, 2014 at 6:24 am