How to use variables in Java
Editor to share with you how to use variables in Java, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
/ * Note: 1. Variable naming is not allowed to repeat 2. Variable naming rules: consist of characters, underscores, $, numbers, and the first letter must be a character The drop line or $cannot be a number * / public class TestVariable {public static void main (String [] args) {/ / variable definition: a block of memory allocated by the system to store data / / String type string of data: a word enclosed in double quotation marks Symbol or Chinese character / / bottle variable name / / equal sign = represents the assignment, that is, the "mineral water" data is stored in the memory area named bottle String bottle= "mineral water" / / print the data named bottle memory area to System.out.println (bottle) on the console; / / modify the value of the variable to replace the value of bottle memory area with "juice"; System.out.println (bottle) / / empty variables, empty bottle memory data bottle= ""; System.out.println (bottle); / / delete variables, assign null values to delete variables. At this time, the garbage collector GC will automatically reclaim the allocated memory space bottle=null if it scans the / / bottle variable. System.out.println (bottle); / / Note: / / 1. Variable names cannot be defined repeatedly, otherwise the compiler cannot pass / / String bottle= "milk"; / / System.out.println (bottle) Naming rules for / / variables: consists of characters, underscores, $, numbers, and the first letter must be a character, and the underline or $cannot be a number / / String 1a = "a"; / / System.out.println (1a); String $b = "b"; System.out.println ($b) String _ c = "c"; System.out.println (_ c);}} these are all the contents of the article "how to use variables in Java". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!