When an object is assigned to a variable, will modifying the variable modify the original object?

This is similar to the previous blog post except this is more direct. The answer is “Yes” for all tested languages except C and C++. This may seem trivial until you meet a situation where the same original object is shared across requests/sessions, like a public static variable in Java or an incorrectly scoped Javascript …

Does modifying objects passed in to functions modify original object?

As per title, ran this across various languages. Results are mixed, but IMHO, it seems unsafe to design your functions/methods this way. It would be better to pass in the object, compute the changes without modifying the object, return the computed changes and assign it back to the original variable. Below are sample code snippets …

Simple Java logging class with inferred TAG

Been using a lot of Log.d(TAG, “message”); when working on Android projects. Problem with TAG is that it needs to be explicitly declared, e.g. protected String TAG = MyClass.class.getSimpleName(); instead of being inferred. Unlike PHP, Java has no magic constants such as __CLASS__ or __FUNCTION__ that can resolve automagically to the class/method being used at …

Resize view to fit aspect ratio of video in Android ExoPlayer

Been playing with ExoPlayer in Android and trying to resize a view to fit the aspect ratio of the video being played, i.e. fill the view with the video. References: Change resize mode for ExoPlayer Change aspect ratio of SurfaceView for ExoPlayer video 5-part series on building video player using ExoPlayer import android.view.ViewGroup.LayoutParams; import com.google.android.exoplayer2.Player.EventListener; …

Print QR code to network-enabled thermal receipt printer using Java

For more information on the ESC/POS command set which receipt printers use for printing, see What is ESC/POS and How Do I Use It by Michael Billington, also the author of the excellent escpos-php PHP library for receipt printers. Thanks to this StackOverflow post as well: printing QR codes through an ESC/POS thermal printer? ๐Ÿ™‚ …

Print Chinese text to network-enabled thermal receipt printer using Java

For more information on the ESC/POS command set which receipt printers use for printing, see What is ESC/POS and How Do I Use It by Michael Billington, also the author of the excellent escpos-php PHP library for receipt printers. Steps to run: Save the code below as NetworkReceiptPrinter.java – change printer IP accordingly. Run javac …

Using COALESCE and logging SQL string in Play Framework 2.x

For future reference…after spending quite some time figuring it out ๐Ÿ˜› package models; import com.avaje.ebean.Model; import com.avaje.ebean.Query; import play.Logger; import play.data.validation.Constraints; import java.util.Date; import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name = “my_table”) public class MyModel extends Model { @Id public Long id; @Column(name = “name”) public String name; @Constraints.Required @Column(name …