Science, Tech, Math › Computer Science Variable Share Flipboard Email Print Computer Science Java Programming PHP Programming Perl Python Javascript Programming Delphi Programming C & C++ Programming Ruby Programming Visual Basic View More By Paul Leahy Paul Leahy Computer Science Expert M.A., Advanced Information Systems, University of Glasgow Paul Leahy is a computer programmer with over a decade of experience working in the IT industry, as both an in-house and vendor-based developer. Learn about our Editorial Process Updated on March 06, 2017 A variable is a container that holds values that are used in a Java program. Every variable must be declared to use a data type. For example, a variable could be declared to use one of the eight primitive data types: byte, short, int, long, float, double, char or boolean. And, every variable must be given an initial value before it can be used. Examples: int myAge = 21; The variable "myAge" is declared to be an int data type and initialized to a value of 21. Cite this Article Format mla apa chicago Your Citation Leahy, Paul. "Variable." ThoughtCo, Jan. 29, 2020, thoughtco.com/variable-2034325. Leahy, Paul. (2020, January 29). Variable. Retrieved from https://www.thoughtco.com/variable-2034325 Leahy, Paul. "Variable." ThoughtCo. https://www.thoughtco.com/variable-2034325 (accessed June 4, 2023). copy citation