Carlos Chacin

Software Engineering Experiences


๐Ÿ”Œ Restore IntelliJ Idea settings โ›ฝ

Posted at April 30, 2020 /

intellij-restore-settings

After a long day trying to figure out how to reset all my IntelliJ settings, I decided to write this to document the obvious solution that was not that obvious to me.

I was using the ๐Ÿ”ฅ JetBrains Toolbox App ๐Ÿ”ฅ for a while to manage my IntelliJ Idea Ultimate installation along with other tools like Rider, WebStorm, and the Early Access Preview for IntelliJ Community Edition.

toolboxapp

After several installations and reinstallations of IDEs and different Java/JDK versions (8, 9, 11, 14), the IDE was not able to import my maven projects. The IntelliJ IDEA was acting as a simple text editor at this time ๐Ÿ˜Ÿ.

Read more ...

๐Ÿ’พ Java 14 Records ๐Ÿž with JakartaEE JSON-B

Posted at April 20, 2020 /

java-records-jsonb

In the previous article about Java 14 Records, we saw how to start creating Records to avoid writing much boilerplate code that the compiler would generate for us.

Now the next steps are to see how we can serialize records to JSON and deserialize JSON to records to be able to use them as a request/response representation for microservices.

In this case, we would use the JSON-B specification used by JakartaEE and MicroProfile implementations like GlashFish, TomEE, Wildfly, OpenLiberty, and Quarkus.

Read more ...

๐Ÿš€ Java 14 Records ๐Ÿ’พ (Preview)

Posted at April 17, 2020 /

java-records

Record is a new kind of type declaration in the Java language. Like an enum, a record is a restricted form of class. It declares its representation and commits to an API that matches that representation. Records give up a freedom that classes usually enjoy: the ability to decouple API from representation. In return, records gain a significant degree of concision.

A record has a name and a state description. The state description declares the components of the record. Optionally, a record has a body. For example:

record Point(int x, int y) { }
Read more ...

โ˜•๏ธ Immutables/AutoValue/Lombok ๐Ÿ”ฅ Which One?

Posted at April 12, 2020 /

OfficeDesk

In this article, we are going to compare some of the features of the Immutables.org library, Google AutoValue and Project Lombok:

  • Generated the Builder pattern by default?
  • Generated helper methods for, i.e., Optional and List?
  • The number of lines of code to write?
  • Required IDEโ€™s plugins?
  • Are the objects immutable?

The three libraries are based on an annotation processor to generate/modify code for us:

  • Immutable classes
  • equals, hashCode and toString methods
  • other utilities

NOTE: Immutables and AutoValue generate new classes with the processor, and Lombok modifies the bytecode of the original class.

Read more ...

๐ŸŽฉ Immutability in Java ๐Ÿ”ฅ Made Easy

Posted at April 11, 2020 /

HomeOffice

In Effective Java, Joshua Bloch makes the following recommendation:

Classes should be immutable unless thereโ€™s a very good reason to make them mutableโ€ฆ If a class cannot be made immutable, limit its mutability as much as possible.

๐Ÿ”ฉ Immutable Objects

An object is considered immutable if its state cannot change after it is constructed. Maximum reliance on immutable objects is widely accepted as a sound strategy for creating a simple, reliable code. reference

  • Immutable objects are constructed once, in a consistent state, and can be safely shared
    • Will fail if mandatory attributes are missing
    • Cannot be sneakily modified when passed to other code
  • Immutable objects are naturally thread-safe and can therefore be safely shared among threads
    • No excessive copying
    • No excessive synchronization
  • Object definitions are pleasant to write and read
    • No boilerplate setter and getters
    • No ugly IDE-generated hashCode, equals and toString methods that end up being stored in source control. reference
Read more ...