Science, Tech, Math › Computer Science Definition of a Declaration Statement in Java Share Flipboard Email Print Flickr usuario Silveira Neto 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 January 09, 2019 One kind of Java statement is a declaration statement, which is used to declare a variable by specifying its data type and name. Below are some examples of declaration statements. A variable, in relation to Java programming, is a container that holds values used in a Java program. Instead of defining a value over and over, a variable that has a value attached to it can be defined. Since variables must be given an initial starting value, you can see how that works in the examples on this page. Examples of Declarations in Java The following three declaration statements declare int, boolean and String variables: int number; boolean isFinished; String welcomeMessage; In addition to the data type and name, a declaration statement can initialize the variable with a value: int number = 10; boolean isFinished = false; String welcomeMessage = "Hello!"; It's also possible to declare more than one variable of the same data type in one declaration statement: int number, anotherNumber, yetAnotherNumber; boolean isFinished = false, isAlmostFinished = true; String welcomeMessage = "Hello!", farewellMessage; The variables number, anotherNumber, and yetAnotherNumber all have int data types. The two boolean variables isFinished and isAlmostFinished are declared with initial values of false and true respectively. Finally, the String variable welcomeMessage is assigned the String value of "Hello!", while the variable farewellMessage is simply declared as a String. There are also control flow statements in Java as well as expression statements. Cite this Article Format mla apa chicago Your Citation Leahy, Paul. "Definition of a Declaration Statement in Java." ThoughtCo, Aug. 25, 2020, thoughtco.com/declaration-statement-2034076. Leahy, Paul. (2020, August 25). Definition of a Declaration Statement in Java. Retrieved from https://www.thoughtco.com/declaration-statement-2034076 Leahy, Paul. "Definition of a Declaration Statement in Java." ThoughtCo. https://www.thoughtco.com/declaration-statement-2034076 (accessed March 21, 2023). copy citation Featured Video