View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide

Declare a variable

See Definition of a Variable

To declare a variable in Java use:

type nameOfVariable;

or

type nameOfVariable = expression;

Common Errors:

You can't create two variables with the same name in the same scope (like in the same method).

Examples:

boolean returnFlag;
boolean success = false;

int count = 0;
int numTimes;

double sum = 0;
double average;



Links to this Page