Java Fundamentals---Application of Java constants (ix)

Source: Internet
Author: User

Application of Java constants

The so-called constant, which we can understand as a special variable, whose value is set, is not allowed to change during program Operation .

Syntax:final constant name = value;

650) this.width=650; "src=" http://img.mukewang.com/53689a880001620703990081.jpg "/>

Using Constants in your program can improve the maintainability of your code. For example, in project development, we need to specify the user's gender, at this time can be defined as a constant sex, assigned to "male", in the need to specify a user-specific place to call this constant directly, to avoid the user's non-standard assignment caused the program error situation.

Guys, watch out.: Constant names generally use uppercase characters


Code:

public class helloworld{
public static void Main (string[] args) {
Final String male= "male";
Final String female= "female";

SYSTEM.OUT.PRINTLN (male);
SYSTEM.OUT.PRINTLN (female);


}
}


Operation Result:

Man

Woman

This article is from "Ghost" blog, please make sure to keep this source http://caizi.blog.51cto.com/5234706/1547646

Java Fundamentals---Application of Java constants (ix)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.