Tag Archives: Java

Generating code with JavaPoet

Why write code when you can generate it? There are lots of situations when it makes more sense to generate. In this article I’m going to work through an example of how to use JavaPoet and Apache BeanUtils to write … Continue reading

Posted in Java, Uncategorized | Tagged | Leave a comment

Java 8 Streams Tutorial

In this tutorial, I’m going to start by explaining some of the basics of streams. Viz: What streams are Terminal and non-terminal operations Their “lazy” nature Their read-once nature Why they were introduced i.e. how they enable easy parallel operations … Continue reading

Posted in Java | Tagged , | Leave a comment

Yet another Java 8 custom collector example

Java 8 introduces a number of functional programming techniques to the language. Collections can be turned into streams which allows you to perform standard functional operations on them, such as filtering, mapping, reducing and collecting. In this post I’m going … Continue reading

Posted in Java | Tagged | Leave a comment

Hibernate example 4 – many to many associations

I’ve put some code on Github that shows three ways of modelling many to many associations with JPA / Hibernate: Using a join table that is not mapped as either an entity or an embedded component type. Mapping the join … Continue reading

Posted in Hibernate, Java | Tagged , | Leave a comment

Hibernate example 3 – one to one associations

Just put a Hibernate example of the three different ways to create one-to-one associations on github: https://github.com/hedleyproctor/hibernate-one-to-one It contains a Customer entity, which has one-to-one associations to a UserProfile, MarketingPreferences and a Wistlist. Foreign key relationship. Customer has a foreign … Continue reading

Posted in Hibernate, Java | Tagged , | Leave a comment

Hibernate example 2 – one-to-many associations

Just put an example of how to use one-to-many associations with Hibernate on Github: https://github.com/hedleyproctor/hibernate-one-to-many Shows two examples of a one-to-many relationship between entities: Unordered one-to-many between Customer and Address. Ordered one-to-many between Customer and PaymentCard. The unordered association uses … Continue reading

Posted in Hibernate, Java | Tagged , | Leave a comment

Hibernate example 1 – inheritance and polymorphism

Have just put an example on Github of how to handle inheritance and polymorphism with Hibernate: https://github.com/hedleyproctor/hibernate-polymorphism It demonstrates the four ways of dealing with inheritance and polymorphism: Implicit polymorphism – no explicit mapping of the inheritance, but Hibernate can … Continue reading

Posted in Hibernate, Java | Tagged , | Leave a comment

Using Java to download a file that needs authentication

You can easily download files using Java by making a URLConnection. However, if you need to login before accessing the file, how can do this automatically? If you automate the login, how will the code that makes the URLConnection be … Continue reading

Posted in Java, Scala, Selenium | Tagged , , | Leave a comment

Organising Eclipse static imports

By default Eclipse “Organise imports” doesn’t deal with static imports, so if you are using JUnit and want to write something like assertEquals(), it won’t be imported. However, you can add static imports to your Java preferences to get them … Continue reading

Posted in Eclipse, Java | Tagged , | Leave a comment

Closures in Java?

There has been discussion about including closures in Java for a few years now. They are already in languages like Groovy, Ruby and Scala, so the lack of Java closures makes Java look a bit tired. However, I didn’t realize … Continue reading

Posted in Java | Tagged | Leave a comment