1. Home
  2. Computing & Technology
  3. Java

Declaration Statement

By Paul Leahy, About.com

Definition:

A declaration statement is used to declare a variable by specifying its data type and name. For example, 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. And finally, the String variable welcomeMessage is assigned the String value of "Hello!", whilst the variable farewellMessage is simply declared as a String.

Glossary:

# A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Explore Java
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Java
  4. Java Glossary
  5. D
  6. Declaration Statement- Definition for the Term: Declaration Statement>

©2009 About.com, a part of The New York Times Company.

All rights reserved.