-
Book Overview & Buying
-
Table Of Contents
OCA: Oracle Certified Associate Java SE 8 Programmer I Study Guide: Exam 1Z0-808
By :
We've seen some variables already. A variable is a name for a piece of memory that stores data. When you declare a variable, you need to state the variable type along with giving it a name. For example, the following code declares two variables. One is named zooName and is of type String. The other is named numberAnimals and is of type int.
String zooName;
int numberAnimals;
Now that we've declared a variable, we can give it a value. This is called initializing a variable. To initialize a variable, you just type the variable name followed by an equal sign, followed by the desired value:
zooName = "The Best Zoo";
numberAnimals = 100;
Since you often want to initialize a variable right away, you can do so in the same statement as the declaration. For example, here we merge the previous declarations and initializations into more concise code:
String zooName = "The Best Zoo";
int numberAnimals = 100;
In the following sections...
Change the font size
Change margin width
Change background colour