Comparing dates and times is a common task in software development, especially when dealing with scheduling, event management, or data analysis. This comprehensive guide on How To Compare Date And Time In Java will provide you with the knowledge and code examples necessary to perform these comparisons efficiently and accurately. Whether you’re a student, a consumer comparing deadlines, or a seasoned professional, compare.edu.vn will showcase a modern approach to date-time comparisons, ensuring you make informed decisions using robust and reliable techniques with date comparison and time comparison methods.
1. Understanding Java’s Date and Time APIs
Java offers two primary APIs for working with dates and times: the legacy java.util
package (containing Date
and Calendar
) and the modern java.time
package (introduced in Java 8).
1.1. The Legacy java.util
API
The java.util.Date
and java.util.Calendar
classes have been the standard for date and time manipulation in Java for a long time. However, they have some known issues:
- Mutability:
Date
andCalendar
objects are mutable, which means their values can be changed after creation. This can lead to unexpected behavior and threading issues. - Design Flaws: The API design is not intuitive and lacks clear separation of concerns.
- Time Zone Handling: Time zone handling is complex and error-prone.
Due to these drawbacks, it’s recommended to avoid using the java.util
API for new projects. However, understanding it is still important for maintaining legacy code.
1.2. The Modern java.time
API
Introduced in Java 8, the java.time
API provides a comprehensive and well-designed set of classes for handling dates and times. It addresses the issues of the legacy API with the following features:
- Immutability: The classes in
java.time
are immutable, ensuring thread safety and predictable behavior. - Clear Design: The API is designed with clear separation of concerns, with classes like
LocalDate
,LocalTime
, andLocalDateTime
representing different aspects of date and time. - Comprehensive Functionality: The API provides a wide range of methods for manipulating, formatting, and comparing dates and times.
- Time Zone Support: The API offers robust time zone support with classes like
ZonedDateTime
andZoneId
.
The java.time
API is the recommended approach for handling dates and times in Java, and it’s the focus of this guide.
2. Core Classes in java.time
for Date and Time Comparison
The java.time
package provides several classes for representing different aspects of date and time. Here are some of the most important ones for date and time comparison:
LocalDate
: Represents a date (year, month, day) without time or time zone.LocalTime
: Represents a time (hour, minute, second, nanosecond) without date or time zone.LocalDateTime
: Represents a date and time without time zone.ZonedDateTime
: Represents a date and time with a time zone.Instant
: Represents a point in time on the UTC timeline.Duration
: Represents a time-based amount of time, such as “2 hours, 30 minutes”.Period
: Represents a date-based amount of time, such as “2 years, 3 months, and 4 days”.
3. Comparing LocalDate
Objects
The LocalDate
class is used to represent a date without time or time zone information. Here’s how to compare LocalDate
objects in Java:
3.1. Creating LocalDate
Instances
There are several ways to create LocalDate
instances:
LocalDate.of(year, month, dayOfMonth)
: Creates aLocalDate
from the given year, month, and day.LocalDate.now()
: Creates aLocalDate
representing the current date using the system clock and default time zone.LocalDate.parse(dateString)
: Creates aLocalDate
from a string representation of a date.
import java.time.LocalDate;
public class LocalDateComparison {
public static void main(String[] args) {
LocalDate date1 = LocalDate.of(2024, 1, 15);
LocalDate date2 = LocalDate.now();
LocalDate date3 = LocalDate.parse("2024-03-10");
System.out.println("Date 1: " + date1);
System.out.println("Date 2: " + date2);
System.out.println("Date 3: " + date3);
}
}
3.2. Comparing LocalDate
Using isEqual()
, isBefore()
, and isAfter()
The LocalDate
class provides three methods for comparing dates:
isEqual(otherDate)
: Returnstrue
if the two dates are equal.isBefore(otherDate)
: Returnstrue
if the current date is before the other date.isAfter(otherDate)
: Returnstrue
if the current date is after the other date.
import java.time.LocalDate;
public class LocalDateComparison {
public static void main(String[] args) {
LocalDate date1 = LocalDate.of(2024, 5, 15);
LocalDate date2 = LocalDate.of(2024, 3, 10);
if (date1.isEqual(date2)) {
System.out.println("Date 1 is equal to Date 2");
} else {
System.out.println("Date 1 is not equal to Date 2");
}
if (date1.isBefore(date2)) {
System.out.println("Date 1 is before Date 2");
} else {
System.out.println("Date 1 is not before Date 2");
}
if (date1.isAfter(date2)) {
System.out.println("Date 1 is after Date 2");
} else {
System.out.println("Date 1 is not after Date 2");
}
}
}
Output:
Date 1 is not equal to Date 2
Date 1 is not before Date 2
Date 1 is after Date 2
3.3. Comparing LocalDate
Using compareTo()
The compareTo(otherDate)
method compares two LocalDate
objects and returns:
- 0: If the two dates are equal.
- A negative value: If the current date is before the other date.
- A positive value: If the current date is after the other date.
import java.time.LocalDate;
public class LocalDateComparison {
public static void main(String[] args) {
LocalDate date1 = LocalDate.of(2024, 5, 15);
LocalDate date2 = LocalDate.of(2024, 3, 10);
int comparisonResult = date1.compareTo(date2);
if (comparisonResult == 0) {
System.out.println("Date 1 is equal to Date 2");
} else if (comparisonResult < 0) {
System.out.println("Date 1 is before Date 2");
} else {
System.out.println("Date 1 is after Date 2");
}
}
}
Output:
Date 1 is after Date 2
4. Comparing LocalTime
Objects
The LocalTime
class represents a time without date or time zone information. Here’s how to compare LocalTime
objects in Java:
4.1. Creating LocalTime
Instances
You can create LocalTime
instances using:
LocalTime.of(hour, minute, second)
: Creates aLocalTime
from the given hour, minute, and second.LocalTime.now()
: Creates aLocalTime
representing the current time using the system clock and default time zone.LocalTime.parse(timeString)
: Creates aLocalTime
from a string representation of a time.
import java.time.LocalTime;
public class LocalTimeComparison {
public static void main(String[] args) {
LocalTime time1 = LocalTime.of(10, 30, 0);
LocalTime time2 = LocalTime.now();
LocalTime time3 = LocalTime.parse("14:45:30");
System.out.println("Time 1: " + time1);
System.out.println("Time 2: " + time2);
System.out.println("Time 3: " + time3);
}
}
4.2. Comparing LocalTime
Using isEqual()
, isBefore()
, and isAfter()
The LocalTime
class provides the same comparison methods as LocalDate
:
isEqual(otherTime)
: Returnstrue
if the two times are equal.isBefore(otherTime)
: Returnstrue
if the current time is before the other time.isAfter(otherTime)
: Returnstrue
if the current time is after the other time.
import java.time.LocalTime;
public class LocalTimeComparison {
public static void main(String[] args) {
LocalTime time1 = LocalTime.of(10, 30, 0);
LocalTime time2 = LocalTime.of(14, 45, 30);
if (time1.isEqual(time2)) {
System.out.println("Time 1 is equal to Time 2");
} else {
System.out.println("Time 1 is not equal to Time 2");
}
if (time1.isBefore(time2)) {
System.out.println("Time 1 is before Time 2");
} else {
System.out.println("Time 1 is not before Time 2");
}
if (time1.isAfter(time2)) {
System.out.println("Time 1 is after Time 2");
} else {
System.out.println("Time 1 is not after Time 2");
}
}
}
Output:
Time 1 is not equal to Time 2
Time 1 is before Time 2
Time 1 is not after Time 2
4.3. Comparing LocalTime
Using compareTo()
The compareTo(otherTime)
method for LocalTime
works the same way as for LocalDate
:
- 0: If the two times are equal.
- A negative value: If the current time is before the other time.
- A positive value: If the current time is after the other time.
import java.time.LocalTime;
public class LocalTimeComparison {
public static void main(String[] args) {
LocalTime time1 = LocalTime.of(10, 30, 0);
LocalTime time2 = LocalTime.of(14, 45, 30);
int comparisonResult = time1.compareTo(time2);
if (comparisonResult == 0) {
System.out.println("Time 1 is equal to Time 2");
} else if (comparisonResult < 0) {
System.out.println("Time 1 is before Time 2");
} else {
System.out.println("Time 1 is after Time 2");
}
}
}
Output:
Time 1 is before Time 2
5. Comparing LocalDateTime
Objects
The LocalDateTime
class combines both date and time without time zone information. Here’s how to compare LocalDateTime
objects:
5.1. Creating LocalDateTime
Instances
You can create LocalDateTime
instances using:
LocalDateTime.of(year, month, dayOfMonth, hour, minute, second)
: Creates aLocalDateTime
from the given year, month, day, hour, minute, and second.LocalDateTime.now()
: Creates aLocalDateTime
representing the current date and time using the system clock and default time zone.LocalDateTime.parse(dateTimeString)
: Creates aLocalDateTime
from a string representation of a date and time.LocalDateTime.of(LocalDate, LocalTime)
: Creates aLocalDateTime
by combining aLocalDate
and aLocalTime
object.
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
public class LocalDateTimeComparison {
public static void main(String[] args) {
LocalDateTime dateTime1 = LocalDateTime.of(2024, 5, 15, 10, 30, 0);
LocalDateTime dateTime2 = LocalDateTime.now();
LocalDateTime dateTime3 = LocalDateTime.parse("2024-03-10T14:45:30");
LocalDate date = LocalDate.of(2024, 6, 1);
LocalTime time = LocalTime.of(8,0,0);
LocalDateTime dateTime4 = LocalDateTime.of(date, time);
System.out.println("DateTime 1: " + dateTime1);
System.out.println("DateTime 2: " + dateTime2);
System.out.println("DateTime 3: " + dateTime3);
System.out.println("DateTime 4: " + dateTime4);
}
}
5.2. Comparing LocalDateTime
Using isEqual()
, isBefore()
, and isAfter()
The LocalDateTime
class provides the same comparison methods as LocalDate
and LocalTime
:
isEqual(otherDateTime)
: Returnstrue
if the two date-times are equal.isBefore(otherDateTime)
: Returnstrue
if the current date-time is before the other date-time.isAfter(otherDateTime)
: Returnstrue
if the current date-time is after the other date-time.
import java.time.LocalDateTime;
public class LocalDateTimeComparison {
public static void main(String[] args) {
LocalDateTime dateTime1 = LocalDateTime.of(2024, 5, 15, 10, 30, 0);
LocalDateTime dateTime2 = LocalDateTime.of(2024, 3, 10, 14, 45, 30);
if (dateTime1.isEqual(dateTime2)) {
System.out.println("DateTime 1 is equal to DateTime 2");
} else {
System.out.println("DateTime 1 is not equal to DateTime 2");
}
if (dateTime1.isBefore(dateTime2)) {
System.out.println("DateTime 1 is before DateTime 2");
} else {
System.out.println("DateTime 1 is not before DateTime 2");
}
if (dateTime1.isAfter(dateTime2)) {
System.out.println("DateTime 1 is after DateTime 2");
} else {
System.out.println("DateTime 1 is not after DateTime 2");
}
}
}
Output:
DateTime 1 is not equal to DateTime 2
DateTime 1 is after DateTime 2
DateTime 1 is not before DateTime 2
5.3. Comparing LocalDateTime
Using compareTo()
The compareTo(otherDateTime)
method for LocalDateTime
works the same way as for LocalDate
and LocalTime
:
- 0: If the two date-times are equal.
- A negative value: If the current date-time is before the other date-time.
- A positive value: If the current date-time is after the other date-time.
import java.time.LocalDateTime;
public class LocalDateTimeComparison {
public static void main(String[] args) {
LocalDateTime dateTime1 = LocalDateTime.of(2024, 5, 15, 10, 30, 0);
LocalDateTime dateTime2 = LocalDateTime.of(2024, 3, 10, 14, 45, 30);
int comparisonResult = dateTime1.compareTo(dateTime2);
if (comparisonResult == 0) {
System.out.println("DateTime 1 is equal to DateTime 2");
} else if (comparisonResult < 0) {
System.out.println("DateTime 1 is before DateTime 2");
} else {
System.out.println("DateTime 1 is after DateTime 2");
}
}
}
Output:
DateTime 1 is after DateTime 2
6. Comparing ZonedDateTime
Objects
The ZonedDateTime
class represents a date and time with a specific time zone. Comparing ZonedDateTime
objects requires considering the time zone.
6.1. Creating ZonedDateTime
Instances
You can create ZonedDateTime
instances using:
ZonedDateTime.of(year, month, dayOfMonth, hour, minute, second, nano, zoneId)
: Creates aZonedDateTime
from the given year, month, day, hour, minute, second, nanosecond, andZoneId
.ZonedDateTime.now(zoneId)
: Creates aZonedDateTime
representing the current date and time in the specified time zone.ZonedDateTime.parse(dateTimeString)
: Creates aZonedDateTime
from a string representation of a date and time, including the time zone information.
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
public class ZonedDateTimeComparison {
public static void main(String[] args) {
ZoneId losAngelesZone = ZoneId.of("America/Los_Angeles");
ZoneId newYorkZone = ZoneId.of("America/New_York");
ZonedDateTime dateTime1 = ZonedDateTime.of(2024, 5, 15, 10, 30, 0, 0, losAngelesZone);
ZonedDateTime dateTime2 = ZonedDateTime.now(newYorkZone);
ZonedDateTime dateTime3 = ZonedDateTime.parse("2024-03-10T14:45:30-05:00[America/New_York]");
System.out.println("DateTime 1: " + dateTime1);
System.out.println("DateTime 2: " + dateTime2);
System.out.println("DateTime 3: " + dateTime3);
}
}
6.2. Comparing ZonedDateTime
Using isEqual()
, isBefore()
, and isAfter()
The ZonedDateTime
class provides the same comparison methods as LocalDate
, LocalTime
, and LocalDateTime
:
isEqual(otherDateTime)
: Returnstrue
if the two date-times are equal.isBefore(otherDateTime)
: Returnstrue
if the current date-time is before the other date-time.isAfter(otherDateTime)
: Returnstrue
if the current date-time is after the other date-time.
Important: When comparing ZonedDateTime
objects, the comparison is based on the actual point in time (instant) they represent, taking into account the time zone offset.
import java.time.ZoneId;
import java.time.ZonedDateTime;
public class ZonedDateTimeComparison {
public static void main(String[] args) {
ZoneId losAngelesZone = ZoneId.of("America/Los_Angeles");
ZoneId newYorkZone = ZoneId.of("America/New_York");
ZonedDateTime dateTime1 = ZonedDateTime.of(2024, 5, 15, 10, 30, 0, 0, losAngelesZone);
ZonedDateTime dateTime2 = ZonedDateTime.of(2024, 3, 10, 14, 45, 30, 0, newYorkZone);
if (dateTime1.isEqual(dateTime2)) {
System.out.println("DateTime 1 is equal to DateTime 2");
} else {
System.out.println("DateTime 1 is not equal to DateTime 2");
}
if (dateTime1.isBefore(dateTime2)) {
System.out.println("DateTime 1 is before DateTime 2");
} else {
System.out.println("DateTime 1 is not before DateTime 2");
}
if (dateTime1.isAfter(dateTime2)) {
System.out.println("DateTime 1 is after DateTime 2");
} else {
System.out.println("DateTime 1 is not after DateTime 2");
}
}
}
Output:
DateTime 1 is not equal to DateTime 2
DateTime 1 is after DateTime 2
DateTime 1 is not before DateTime 2
6.3. Comparing ZonedDateTime
Using compareTo()
The compareTo(otherDateTime)
method for ZonedDateTime
works the same way as for the other date and time classes, taking into account the time zone offset.
import java.time.ZoneId;
import java.time.ZonedDateTime;
public class ZonedDateTimeComparison {
public static void main(String[] args) {
ZoneId losAngelesZone = ZoneId.of("America/Los_Angeles");
ZoneId newYorkZone = ZoneId.of("America/New_York");
ZonedDateTime dateTime1 = ZonedDateTime.of(2024, 5, 15, 10, 30, 0, 0, losAngelesZone);
ZonedDateTime dateTime2 = ZonedDateTime.of(2024, 3, 10, 14, 45, 30, 0, newYorkZone);
int comparisonResult = dateTime1.compareTo(dateTime2);
if (comparisonResult == 0) {
System.out.println("DateTime 1 is equal to DateTime 2");
} else if (comparisonResult < 0) {
System.out.println("DateTime 1 is before DateTime 2");
} else {
System.out.println("DateTime 1 is after DateTime 2");
}
}
}
Output:
DateTime 1 is after DateTime 2
7. Comparing Instant
Objects
The Instant
class represents a point in time on the UTC timeline. It’s useful for representing timestamps and comparing events that occurred at different times.
7.1. Creating Instant
Instances
You can create Instant
instances using:
Instant.now()
: Creates anInstant
representing the current time.Instant.ofEpochSecond(epochSecond)
: Creates anInstant
from the number of seconds from the epoch of 1970-01-01T00:00:00Z.Instant.parse(instantString)
: Creates anInstant
from a string representation of an instant.ZonedDateTime.toInstant()
: Converts aZonedDateTime
to anInstant
.
import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.ZoneId;
public class InstantComparison {
public static void main(String[] args) {
Instant instant1 = Instant.now();
Instant instant2 = Instant.ofEpochSecond(1683700000);
Instant instant3 = Instant.parse("2024-03-10T14:45:30Z");
ZoneId losAngelesZone = ZoneId.of("America/Los_Angeles");
ZonedDateTime dateTime = ZonedDateTime.of(2024, 5, 15, 10, 30, 0, 0, losAngelesZone);
Instant instant4 = dateTime.toInstant();
System.out.println("Instant 1: " + instant1);
System.out.println("Instant 2: " + instant2);
System.out.println("Instant 3: " + instant3);
System.out.println("Instant 4: " + instant4);
}
}
7.2. Comparing Instant
Using isEqual()
, isBefore()
, and isAfter()
The Instant
class provides the same comparison methods:
isEqual(otherInstant)
: Returnstrue
if the two instants are equal.isBefore(otherInstant)
: Returnstrue
if the current instant is before the other instant.isAfter(otherInstant)
: Returnstrue
if the current instant is after the other instant.
import java.time.Instant;
public class InstantComparison {
public static void main(String[] args) {
Instant instant1 = Instant.now();
Instant instant2 = Instant.ofEpochSecond(1683700000);
if (instant1.isEqual(instant2)) {
System.out.println("Instant 1 is equal to Instant 2");
} else {
System.out.println("Instant 1 is not equal to Instant 2");
}
if (instant1.isBefore(instant2)) {
System.out.println("Instant 1 is before Instant 2");
} else {
System.out.println("Instant 1 is not before Instant 2");
}
if (instant1.isAfter(instant2)) {
System.out.println("Instant 1 is after Instant 2");
} else {
System.out.println("Instant 1 is not after Instant 2");
}
}
}
Output: (The output will depend on the current time)
Instant 1 is not equal to Instant 2
Instant 1 is after Instant 2
Instant 1 is not before Instant 2
7.3. Comparing Instant
Using compareTo()
The compareTo(otherInstant)
method for Instant
works the same way as for the other date and time classes:
- 0: If the two instants are equal.
- A negative value: If the current instant is before the other instant.
- A positive value: If the current instant is after the other instant.
import java.time.Instant;
public class InstantComparison {
public static void main(String[] args) {
Instant instant1 = Instant.now();
Instant instant2 = Instant.ofEpochSecond(1683700000);
int comparisonResult = instant1.compareTo(instant2);
if (comparisonResult == 0) {
System.out.println("Instant 1 is equal to Instant 2");
} else if (comparisonResult < 0) {
System.out.println("Instant 1 is before Instant 2");
} else {
System.out.println("Instant 1 is after Instant 2");
}
}
}
Output: (The output will depend on the current time)
Instant 1 is after Instant 2
8. Comparing Duration
Objects
The Duration
class represents a time-based amount of time, such as “2 hours, 30 minutes”. It’s useful for calculating the difference between two points in time.
8.1. Creating Duration
Instances
You can create Duration
instances using:
Duration.of(long amount, TemporalUnit unit)
: Creates aDuration
from the given amount and unit (e.g.,Duration.of(2, ChronoUnit.HOURS)
).Duration.between(Temporal start, Temporal end)
: Creates aDuration
representing the difference between twoTemporal
objects (e.g.,Duration.between(startTime, endTime)
).
import java.time.Duration;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
public class DurationComparison {
public static void main(String[] args) {
Duration duration1 = Duration.of(2, ChronoUnit.HOURS);
Duration duration2 = Duration.ofMinutes(120);
LocalTime startTime = LocalTime.of(10, 0, 0);
LocalTime endTime = LocalTime.of(12, 30, 0);
Duration duration3 = Duration.between(startTime, endTime);
System.out.println("Duration 1: " + duration1);
System.out.println("Duration 2: " + duration2);
System.out.println("Duration 3: " + duration3);
}
}
8.2. Comparing Duration
Using equals()
The Duration
class uses the equals()
method to check if two durations are equal.
import java.time.Duration;
import java.time.temporal.ChronoUnit;
public class DurationComparison {
public static void main(String[] args) {
Duration duration1 = Duration.of(2, ChronoUnit.HOURS);
Duration duration2 = Duration.ofMinutes(120);
if (duration1.equals(duration2)) {
System.out.println("Duration 1 is equal to Duration 2");
} else {
System.out.println("Duration 1 is not equal to Duration 2");
}
}
}
Output:
Duration 1 is equal to Duration 2
8.3. Comparing Duration
Using compareTo()
The compareTo(otherDuration)
method for Duration
works the same way as for the other date and time classes:
- 0: If the two durations are equal.
- A negative value: If the current duration is shorter than the other duration.
- A positive value: If the current duration is longer than the other duration.
import java.time.Duration;
import java.time.temporal.ChronoUnit;
public class DurationComparison {
public static void main(String[] args) {
Duration duration1 = Duration.of(2, ChronoUnit.HOURS);
Duration duration2 = Duration.ofMinutes(150);
int comparisonResult = duration1.compareTo(duration2);
if (comparisonResult == 0) {
System.out.println("Duration 1 is equal to Duration 2");
} else if (comparisonResult < 0) {
System.out.println("Duration 1 is shorter than Duration 2");
} else {
System.out.println("Duration 1 is longer than Duration 2");
}
}
}
Output:
Duration 1 is shorter than Duration 2
9. Comparing Period
Objects
The Period
class represents a date-based amount of time, such as “2 years, 3 months, and 4 days”.
9.1. Creating Period
Instances
You can create Period
instances using:
Period.of(int years, int months, int days)
: Creates aPeriod
from the given years, months, and days.Period.between(LocalDate startDate, LocalDate endDate)
: Creates aPeriod
representing the difference between twoLocalDate
objects.
import java.time.LocalDate;
import java.time.Period;
public class PeriodComparison {
public static void main(String[] args) {
Period period1 = Period.of(2, 3, 4);
LocalDate startDate = LocalDate.of(2022, 1, 1);
LocalDate endDate = LocalDate.of(2024, 5, 15);
Period period2 = Period.between(startDate, endDate);
System.out.println("Period 1: " + period1);
System.out.println("Period 2: " + period2);
}
}
9.2. Comparing Period
Using equals()
The Period
class uses the equals()
method to check if two periods are equal.
import java.time.Period;
public class PeriodComparison {
public static void main(String[] args) {
Period period1 = Period.of(2, 3, 4);
Period period2 = Period.of(2, 3, 4);
if (period1.equals(period2)) {
System.out.println("Period 1 is equal to Period 2");
} else {
System.out.println("Period 1 is not equal to Period 2");
}
}
}
Output:
Period 1 is equal to Period 2
9.3. Comparing Period
Using compareTo()
The compareTo(otherPeriod)
method for Period
works the same way as for the other date and time classes:
- 0: If the two periods are equal.
- A negative value: If the current period is shorter than the other period.
- A positive value: If the current period is longer than the other period.
Important: The compareTo()
method for Period
compares the total length of the periods in days. This means that a period of “1 month” may be considered shorter than a period of “30 days”, depending on the specific months involved.
import java.time.Period;
public class PeriodComparison {
public static void main(String[] args) {
Period period1 = Period.of(2, 3, 4);
Period period2 = Period.of(1, 6, 10);
int comparisonResult = period1.compareTo(period2);
if (comparisonResult == 0) {
System.out.println("Period 1 is equal to Period 2");
} else if (comparisonResult < 0) {
System.out.println("Period 1 is shorter than Period 2");
} else {
System.out.println("Period 1 is longer than Period 2");
}
}
}
Output:
Period 1 is longer than Period 2
10. Comparing Dates and Times in Legacy Code
If you’re working with legacy code