example for multi-release jar
This commit is contained in:
parent
6dde5fc7bf
commit
009a99e340
|
@ -0,0 +1,11 @@
|
|||
package com.baeldung.multireleaseapp;
|
||||
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String dateToCheck = args[0];
|
||||
boolean isLeapYear = DateHelper.checkIfLeapYear(dateToCheck);
|
||||
System.out.println("Date given " + dateToCheck + " is leap year: " + isLeapYear);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.baeldung.multireleaseapp;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
public class DateHelper {
|
||||
|
||||
public static boolean checkIfLeapYear(String dateStr) throws Exception {
|
||||
System.out.println("Checking for leap year using Java 1 calendar API ");
|
||||
boolean isLeapYear = false;
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(dateStr));
|
||||
int year = cal.get(Calendar.YEAR);
|
||||
if (year % 4 == 0) {
|
||||
if (year % 100 == 0) {
|
||||
isLeapYear = (year % 400 == 0) ? true : false;
|
||||
} else {
|
||||
isLeapYear = true;
|
||||
}
|
||||
}
|
||||
return isLeapYear;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.baeldung.multireleaseapp;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class DateHelper {
|
||||
|
||||
public static boolean checkIfLeapYear(String dateStr) throws Exception {
|
||||
System.out.println("Checking for leap year using Java 9 Date Api");
|
||||
return LocalDate.parse(dateStr)
|
||||
.isLeapYear();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue