Tag Archives: Java

IntelliJ Hints and Tips

Most useful keyboard shortcuts (these are for Mac): CMD + O Open class CMD + SHIFT + OOpen file CMD + F Find in file CMD + R Replace in file CMD + SHIFT + F Find in path CMD … Continue reading

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

log4j in maven tests

If you want to specify log4j configuration when running tests via Maven, you can do so by updating the Maven surefire plugin configuration to point to a specific log4j configuration file. For log4j v2 the appropriate parameter is called log4j.configuration. … Continue reading

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

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