当前位置:网站首页>Variables and constants

Variables and constants

2022-07-07 22:25:00 51CTO

      
      
/*
* author : Stupid teacher
*csdn Certified Instructor
*51cto Senior lecturer
* Tencent classroom certified lecturer
* Netease cloud classroom certified lecturer
* Certified lecturer of Huawei developer school
* Member of iqiyi thousand talents master plan
* Here to share technology 、 Knowledge and life
* All kinds of dry goods , Remember to pay attention !
*/
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.

 Variables and constants _ identifier

1、 What is a variable

        A variable is a reference to a specific value .

2、 The composition of variables

        Variables are composed of three elements, which are data types , Identifier and value .

        The data type of a variable determines the value range of its value , size , Type, etc .Java Is a language that focuses on data types , Therefore, when declaring any variable, we should determine the data type of the variable .

        The identifier of the variable is the unique identifier of the variable , We can determine the variable itself through the identifier . Generally speaking, an identifier is the name of a variable . This name is the only identifier of the variable . The identifier appears mainly to facilitate our manipulation of this variable , Flexibly carry out the subsequent operation of variables .

        The value of a variable is to determine the specific value that its reference points to . stay Java Any variable that is not assigned a value in cannot be operated directly . Before being assigned , It can only be called declaring a variable .

3、 Variable operation

         ① Statement

      
      
int number;
  • 1.

 Variables and constants _ integer _02

        ② assignment

        Assignment of any variable , Will use “=” assignment .

      
      
number = 12;
  • 1.

 Variables and constants _ data type _03

        ③ Other related operations of variables

                Such as arithmetic operation , Value change, etc .

4、 data type

        Because we know that one of the three elements of variables is data type , So what are the data types ?

        stay Java Data types in are divided into , Basic data type and reference type ( object / Packaging ).

        There are four basic data types : integer , floating-point , Boolean type , Character type .

        integer : Integer is the type used to represent the value of the integer part .

        According to the value range, we can divide integers into short integers (short), integer (int), Long integer (long).

      
      
int number = 999995;
short number2 = 33;
long number3 = 1564131365;
  • 1.
  • 2.
  • 3.

 Variables and constants _ integer _04

          Floating point type : Used to describe the type of value with decimal point .

        Floating point type can be divided into single precision according to the precision of decimal point (float) Double precision (double).

        stay Java Double precision is used by default , Double precision is also used more in development . To use single precision , You have to use float Strong go .

      
      
float number =( float) 3.4;
double number1 = 3.1415;
  • 1.
  • 2.

 Variables and constants _ integer _05

        Character types are used to represent letters , Symbol .

      
      
char achar = 'S';
  • 1.

 Variables and constants _ data type _06

        Boolean type is used to indicate right or wrong . There are only two values , One for true, One for false.

      
      
boolean aboolean = true;
boolean aboolean = false;
  • 1.
  • 2.

 Variables and constants _ integer _07

         Reference types are not covered here for the time being , After talking about classes and objects, we will mention them there .

5、 Variable naming rule :

  1. Upper and lower case letters and numbers form
  2. Composed of multiple words , First word lowercase , The rest of the words are capitalized . Such as (strNumber).

6、 Constant

Constants are conventionality values , Such as PI,e, Four parameters of database connection, etc .

Usually constants use static final modification .

Constants are usually used by multiple methods in a class and their values do not change because they are used . This solves the problem that the value of variables will change due to their use .

      
      
static final double PI = 3.1415926;
  • 1.

 Variables and constants _ data type _08

Naming rules : Full name capitalization .

Learn more about

 ​https://edu.51cto.com/lecturer/14175030.html​


原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207072135077568.html