In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "how to use java constants". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. In Java, you often want a constant to be used in multiple methods of a class, and these constants are usually called class constants.
You can set a class constant using the keyword static final.
2. The definition of a class constant is external to the main method, so this constant can be used in other methods of the same class.
Also, if a constant is declared as public, then methods of other classes can also use this constant.
Example
Package cn.itcast.estore.util; public final class Constant {private Constant () {super () } / * * Common constant list * * / / * Common constant list (store common constants) * * / public static final class Common {private static final int INT_ZERO = 0 * private static final int INT_ONE = 1 Private static final String IDENTIFYING_CODE = "identifying_code"; private static final String ENCODING_TYPE_UTF8 = "UTF-8"; private static final String ENCODING_TYPE_ISO8895_1 = "ISO-8859-1"; private static final String ENCODING_TYPE_GBK = "GBK"; private static final String CONTENT_TYPE_TextHtml = "text/html"; private static final String GET = "GET"; private static final String POST = "POST"; private static final String ENCRYPT_TYPE_MD5 = "md5"; private static final String ENCRYPT_TYPE_SHA1 = "sha1" / / Private private Common () {super ();} / constant "0" public static int INT_ZERO () {return INT_ZERO;} / / constant "1" public static int INT_ONE () {return INT_ONE;} / / CAPTCHA constant name public static String IDENTIFYING_CODE () {return IDENTIFYING_CODE;} / / utf8 encoding type public static String ENCODING_TYPE_UTF8 () {return ENCODING_TYPE_UTF8 } / / ISO-8859-1 encoding type public static String ENCODING_TYPE_ISO8895_1 () {return ENCODING_TYPE_ISO8895_1;} / / GBK encoding type public static String ENCODING_TYPE_GBK () {return ENCODING_TYPE_GBK;} / / set text/html text type public static String CONTENT_TYPE_TextHtml () {return CONTENT_TYPE_TextHtml;} / / GETpublic static String GET () {return GET;} / / POSTpublic static String POST () {return POST } / / MD5public static String ENCRYPT_TYPE_MD5 () {return ENCRYPT_TYPE_MD5;} / / sha1public static String ENCRYPT_TYPE_SHA1 () {return ENCRYPT_TYPE_SHA1 }} / * * User constant list * * / / * User stores constants related to the User class * * / public static final class User {private static final String USER_IN_SESSION = "user_in_session"; private static final String USER_NAME = "username" / / Private private User () {super ();} / / public static String USER_IN_SESSION () {return USER_IN_SESSION;} / / public static String USER_NAME () {return USER_NAME;} "how to use java class constants" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.