Monday, May 11, 2020
Java Declaration Statement Definition
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!; Its 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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.