Online Java Compiler By
JavaTpoint.com
import java.net.HttpCookie; public class JavaHttpCookieSetMaxAgeExample3 { public static void main(String[] args) { HttpCookie cookie = new HttpCookie("Employee", "2"); // Sets the maximum age of the cookie within seconds. cookie.setMaxAge(-1); //-1 represents that the given cookie exists until the browser is shut down. System.out.println("The maximum age of the cookie is given as: "+cookie.getMaxAge()); } }
Output