Javatpoint Logo
Javatpoint Logo

Java HttpCookie getName() Method

The getName() method of Java HttpCookie class is invoked to return the name of the cookie. Once, the cookie is created, the name of the cookie cannot be altered.

Syntax

Parameter

N.A.

Return

The above method is used to return a String which specifies the name of the cookie.

Example 1

Test it Now

Output:

The name of the cookie is given as: Student

Example 2

Test it Now

Output:

The name of the first cookie is given as: Student1
The name of the second cookie is given as: Student2

Example 3

Test it Now

Output:

Exception in thread "main" java.lang.IllegalArgumentException: Illegal cookie name
	at java.net.HttpCookie.(Unknown Source)
	at java.net.HttpCookie.(Unknown Source)
	at javatpoint.JavaHttpCookieGetNameExample3.main(JavaHttpCookieGetNameExample3.java:7)
Next TopicgetPath() Method





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA