Posts

Showing posts from March, 2019

Java 12 is here!

Java has switched to a 6-month release cycle, which means you don't have to wait 3 years for a major Java upgrade. It also means less and manageable changes in each major release. Java 12 has been released recently. Here is a brief overview of new features. Switch Expressions We all use switch statements, and we know how much it simplifies coding. But still, it required having a break statement after every case expression. As a guy who makes a lot of careless mitsakes, missing break statement after a case is one of the mistakes I make a lot. switch (month) { case 1 : monthStr = "January" ; break ; case 2 : monthStr = "February" ; break ; case 3 : monthStr = "March" ; break ; case 4 : monthStr = "April" ; break ; } Now with switch expressions , the switch block is going to look much cleaner and robust. String monthStr = switch (month) { case 1 -> "Ja

Programmer's Guide to Dealing With Different Time Zones

Image
All programmers have to deal with times and time zones at some point.  When your product gets wider, it gets more and more difficult to handle and synchronize time between multiple time zones. Being well-informed beforehand might save some pain in the "head" later. I've compiled a few most important tips to take care of when dealing with time zones. The actual list is definitely much bigger. But consider this a start. Store Time in UTC Storing local time in the database is okay when your product is small and deals with just one time zone. But when you start dealing multiple time zones and DST(Daylight Saving Time) , it gets weirder. Now you have to convert your time to different time zones for different users and you have to maintain all upcoming DST changes.  Storing time in UTC can save many headaches in the future. The important reason being that the UTC timezone is never affected by DST. So always remember to store time in UTC, and apply the user's