How to detect and prevent layout reflow Chrome DevTools Tutorial How To Detect And Prevent Layout Reflow Recently I had the opportunity (or perhaps obligation) to dive into the topic of tracking down and fix a variety of unhandled DOM elements causing layout reflow on every update. Given that these reflow can be caused for …
Avoid Java serialization if possible
Serialization was intended as a utility within the Java language, which allows objects to be converted into bytes (serialized), send to another endpoint, and reconstructed as an object again (deserialized). This is necessary since java objects only exists within the JVM and can therefore not be send directly.
78. Use Synchronize When Handling Mutable Methods
When working with threads, synchronize on mutable methods becomes a valuable resource. This is because of two reasons:
Synchronize ensure the method can only be accessed by one thread at a time. Any thread attempting to execute the method while it is already in use, will be put on hold until the method is available again.
Because the threads are set to wait for each other, synchronize also guarantee that each thread will be able to see changes to the mutable method made by previous threads.
A mutable method could for example be a method providing an incremental serial number based on a field instance.
Minimize scope of local variables.
Local variables should be contained within the smallest scope possible.
The most optimal solution is therefore to create the local variable the same place as it is used. Thereby increasing the readability of the code and minimizing the chance of misusing the variable.
Assert method arguments validity
Whenever an object is given in as a method argument, it should be asserted in terms of validity as the first thing.
This can be done with something as Objects.requireNonNull(arg), which will throw an exception if the argument is null.
Additionally, if you want to determine which arguments, should be allowed to be nullable, the @Nullable annotation can be used.