Online Java Compiler By
JavaTpoint.com
import java.net.HttpCookie; public class JavaHttpCookieExample1 { public static void main(String[] args) { HttpCookie object = new HttpCookie("Java", "1"); // Describes the purpose of the cookie. object.setComment("This is for tutorial purpose."); //Returns the comment which describes the purpose of the cookie. System.out.println("Comment: "+object.getComment()); //Specifies the domain within which the cookie can be presented. object.setDomain("javatpoint.com"); //Returns the domain name set for the given cookie. System.out.println("The required domain is: "+object.getDomain()); //Sets the maximum age of the cookie in seconds. object.setMaxAge(2000); System.out.println("The maximum age is given as: "+object.getMaxAge()); //Returns the name of the cookie. System.out.println("Name for the cookie is given as: "+object.getName()); //Returns the hash code of the given HTTP cookie. System.out.println("The hash code for the given cookie is given as: "+object.hashCode()); } }
Output