What is a variable? variables are used to refer to a piece of storage area in memory , must have a specific data type, different data types represent different data storage structures, and data types determine the size of the memory area to put what data
Public classDemoone { Public Static voidMain (string[] args) {intA, B, C;//declare three variables at a timeA = 5; b= 6; C= 7; System.out.println ("A=" + A + "\tb=" + B + "\tc=" +c); intD = 1, E = 2;//declare and initialize at the same time intf = 3; System.out.println ("D=" + D + "\te=" + E + "\tf=" +f); intX=a;//Copy the value in memory of the A identity and assign it to the memory identified by XSystem.out.println (x); }}
variable names must begin with a letter, $, or _, followed by numbers, letters, _, and $, not Java keywords and reserved words
A variable must be declared and assigned before it can be used --variable declaration must have a type, the assignment must be of type matching--the variable in the same scope can be repeatedly assigned, but the consent scope cannot be defined repeatedly
Variables for the Java Foundation