Learn to compare two LocalDate instances to find out which date represents an older date in comparison to second date. LocalDate class is part of java.time package added in Java 8.
The AtomicInteger class protects an underlying int value by providing methods that perform atomic operations on the value. It shall not be used as a replacement for an Integer class.
Learn to format date and time in either 12 hours pattern. The formatted date string will have the AM/PM information as applicable to the timestamp.
Java 8 examples to format LocalDate to String in default patterns as well as custom date patterns. 1. Default pattern [yyyy-MM-dd] If we use the LocalDate.toString() method then it format the date in default format which is yyyy-MM-dd. The default pattern referenced in DateTimeFormatter.ISO_LOCAL_DATE. DateTimeFormatter.ISO_DATE also produces the same result. Program output. 2. Custom patterns […]
Learn to determine, if the given year is leap year, using different Java date time classes including Calendar, ZonedDateTime and LocalDateTime in Java 8.
Learn to compare two instances of ZonedDateTime either in same timezone or in different timezones in Java 8. 1. ZonedDateTime comparison in different timezones If both instances of ZonedDateTime are in same timezone then we can use the ZonedDateTime.compareTo() method to compare both instances, including the chronology. It returns a value negative if less, positive […]
Learn to format a ZonedDateTime to string using ZonedDateTime.format (DateTimeFormatter) method in Java 8. Convert ZonedDateTime to String example.
Learn to convert from LocalDate to ZonedDateTime and from ZonedDateTime to LocalDate in Java 8. To restate, LocalDate represent a calendar date without time and timezone. ZonedDateTime instance contains both information. ZonedDateTime = LocalDate + time + timezone 1. LocalDate to ZonedDateTime conversion To convert a LocalDate instance to ZonedDateTime instance, we have two approaches. […]
Learn to convert from LocalDate to LocalDateTime and from LocalDateTime to LocalDate in Java 8.
Java 8 ZonedDateTime class represents a date without associated timezone information. Learn to convert a date in string to ZonedDateTime object in Java 8 using ZonedDateTime parse() method. 1. String to ZonedDateTime example – default and custom patterns Java example to convert a string into ZonedDateTime. Program output. 2. Patterns 2.1. Default pattern The default […]
Java 8 LocalDateTime class represents a date without associated timezone information. Learn to convert a date in string to LocalDateTime object in Java 8.
Java 8 LocalDate class represents a calendar date without time (hour/minute/seconds) and timezone information. Learn to convert a date in string to LocalDate object in Java 8. The default date pattern is DateTimeFormatter.ISO_LOCAL_DATE which is yyyy-MM-dd. 1. String to LocalDate example – default and custom patterns Java example to convert a string into LocalDate. Program […]
java.time.ZonedDateTime class, introduced in Java 8, represents a date and time with timezone information in ISO-8601 calendar system. This class stores all date and time fields, to a precision of nanoseconds. We can use the ZonedDateTime instances where we need to represent the time for globally distributed users. For example, we can use ZonedDateTime to […]
java.time.LocalDateTime class, introduced in Java 8, represents a local date time object without timezone information. It represents time to nanosecond precision e.g. 2007-12-03T10:15:30:55.123456789 We can use the LocalDateTime instances where we need to represent the time without any need of the timezone reference. For example, we can use LocalDateTime to trigger the batch jobs in […]
java.time.LocalTime class, introduced in Java 8, represents a local time object without the date or timezone information as hour-minute-second parts. It represents time to nanosecond precision e.g. 09:25:59.123456789 We can use the LocalTime instances where we need to represent a time without any need of the date or timezone reference as seen in a wall […]
java.time.LocalDate class, introduced in Java 8, represents a local date without timezone and time of that day e.g. 2019-03-27. It has the time portion as the moment of the day starts i.e. minutes and seconds are considered zero. We can use the LocalDate instances where we need to represent a day without specific time of […]
The program arguments passed at launching the Java program are called command line arguments. While launching the program we can pass additional arguments (no limit of numbers of arguments).
Recursion is referred to a programming style where a method invokes itself repeatedly until a certain predefined condition is met. Such method calls are also called recursive methods.
Java naming conventions are sort of guidelines which application programmers are expected to follow to produce a consistent and readable code throughout the application. If teams do not not follow these conventions, they may collectively write an application code which is hard to read and difficult to understand. Java heavily uses CamelCase notations for naming […]
this and super are reserved keywords in Java. this refer to current instance of a class while super refer to the parent class of that class where super keyword is used.