1. Home
  2. Computing & Technology
  3. Java
photo of Paul Leahy
Paul's Java Blog

By Paul Leahy, About.com Guide to Java

Java Term of the Week: Declaration Statement

Saturday June 27, 2009

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.

Comments

No comments yet. Leave a Comment

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Discuss
Community Forum
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

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

All rights reserved.