<> variable

definition : The value stored in memory and can be changed . Our data needs to be put into memory before it can be calculated . The essence of a variable is to represent a variable in computer memory “ Operable storage space ”, The location is certain , But the value inside is uncertain and can be changed . Access the value in the corresponding memory space through the variable name ( The variable name stores the address where the data exists in memory ) To manipulate the value stored in memory
Variables are data stored in memory , Can change , For example, give the variable the name a Assignment integer 10:
int a = 10; // integer
<> data type

Is a strongly typed language , Each variable must declare a data type , The data type of the variable determines the storage space occupied by the variable , To save memory space , We need to choose the appropriate data type according to the size of the data .
Java The data types are :

Let's first learn about numerical data types , Before variable assignment , We all need to declare what type of variable this variable is , with a=10, Take different data types as an example :
int a = 10; // integer occupy 4 byte short a = 10; // Short shaping occupy 2 byte byte a =10; // Byte type occupy 1 byte
be careful :byte Use return as -127—128, long a = 10; // Long integer float a = 10.0 // float , Single precision double a =
10.0 // float . Double precision
<> Variable naming rules

* The initials can be underlined , English letter , symbol number open head , his he Department branch can with yes number word , word mother , lower Row Line ,
Symbol beginning , Other parts can be numbers , letter , Underline , Symbol beginning , Other parts can be numbers , letter , Underline , Symbol
* . If it consists of two words , Named after the hump nomenclature , such as myName
* Variable names should be meaningful , Don't write a,b,c wait , For example, name :name, ID :ID
* Don't write Java Keywords that already exist in , such as int,public etc.
<> Type of variable

local variable :
A variable defined inside a method or statement block , It's called a local variable . The declaration cycle will be destroyed from the declared position to the execution of the method or statement block . Local variables must be declared and assigned before they can be used !

global variable :

It is also called member variable or instance variable , Variables defined inside a class and outside a method are called global variables , Scope the entire class , Subordinate object , The declaration cycle is always accompanied by the object . If not automatically initialized , It will automatically initialize the default initial value of the variable . Because this variable is opened up in heap memory .

Static variable :
Also called class variable , use static modification , Subordinate class , It will be initialized when the class is loaded , Declaration cycle from class loading to class unloading .

<> Data type conversion

The value must be converted directly , Any value +“” An empty string is not a numeric type , You can't calculate .
int a=10; double b=9.8; int c=(int) b; System.out.println(c);// result 9
// Because the value of large space cannot be put into small space , Cast required , // But the accuracy will be lost double d=a; // Put the value of small space into larger space , Can you put it down , Automatic type conversion
System.out.println(d);// output 10.0
<> Console input

Now we need to interact with the program , That is, you can enter data , Only then can the result program be executed , Get output again , First, we need to import the package :
import java.util.Scanner; // Guide Package public class hello { public static void main(
String[] args) { Scanner input=new Scanner(System.in);// establish input Input object System.out.
print(" Please enter your name :"); String name=input.next(); //next() Input string System.out.print(
" Please enter age :"); int age=input.nextInt(); n//nextInt() Enter integer System.out.println(" Hello, I'm "+
name+", My age is "+age+" year !"); } }
After the program runs , Enter name , Age , Then output

<> Arithmetic operator

This is an ordinary arithmetic operator , Nothing special
namely : add , subtract , multiply and divide + - * / %( Surplus )

<> Conditional operator ( compare )
greater than > less than < be equal to = The two values are equal == Not equal to !=
<> Logical operator

And or not :
&& also : condition A&& condition B condition A And conditions B Both are satisfied at the same time true, Will return the result as true
|| perhaps : condition A|| condition B condition A Or conditions B One of them is true, The returned result is true
!: wrong Reverse != Not equal to !true return false

<> Assignment Operators =
int a=10; // Right click the value through = Assign to left
<> ternary operator
// grammar :/ Comparison conditions ? satisfy true Assigned value : satisfy false Assigned value int r1=8>5?1:0; System.out.println(r1); //
if it is true, output 1, if it is false, output 0
<> constant

use final Modified variables are called constants , Used to frequently use fixed values and do not often send changed values
final int WEEKDAY=7; // For example, one week equals 7 day , This will not change , We can prefix the variable name with final, It becomes a constant
All right , That's all for today , See you next time ~~~~

©2019-2020 Toolsou All rights reserved,
C++ of string of compare usage Python Study notes ( one )evo Tool usage problems ——Degenerate covariance rank, Umeyama alignment is not possibleRISC-V_GD32VF103-TIMER0 timer interrupt java Array subscript variable _Java Basic grammar : array be based on stm32 Control four-wheel trolley motor drive ( one ) be based on redis Design of liking function Software engineering career planning mysql Query random data by conditions _MySQL Random query of several qualified records centos7 install RabbitMq