Lesson+02


 * Lesson #02: Variable Types**

code format="java" public static void main(String args[]) {     String s = "Hello world"; System.out.println(s); } code
 * Three variable types:**
 * 1) String - used to store a variety of things, using quotes.

code format="java" public static void main(String args[]) {     int age = 18; System.out.println(age); } code
 * 1) int - used to store integers


 * 1) double - used to store decimal numbers a.k.a. "floating point" numbers. The double means double precision.

code format="java" public static void main(String args[]) {     double d = -137.8036; System.out.println(d); d = 1.45667E23; //It's legal to use scientific notation in doubles. } code

Variables must be declared as a certain data type before they can be used. For example, If I would want to use variable a as a String, I would have to declare it first before assigning it a value. code format="java" String a; int b; double c; a = "Hello"; b = 5; c = 3.141592653; code Afterwords, variables can be initialized, where values are assigned. It is possible to declare and initialize variables in the same line of code. code format="java" String a = "Hello"; int b = 5; double c = 3.141592653; code
 * Declaring and initializing:**

There are certain types of variables that cannot have certain types of values. While strings can take virtually all types of characters, Integers and doubles cannot contain letters (except for capital E used for scientific notation in doubles). Doubles may be assigned values with or without decimals. Integers, however, can only receive numbers without decimals. code format="java" String a = "Hello 5 5.0"; //Legal int b = 5.0; //Illegal double c = 5; //legal code
 * Legal and Illegal values**

Variable names must begin with an upper or lowercase letter. It may not be a number. Variable names may, however, contain numbers in the rest of the name. Names can consist of only one letter, or can be very long. The only variable names that are forbidden are reserved words, such as int, String, and double. Lastly, varible names may have underscores, but not periods. Please keep in mind that variable names are case-sensitive. Here are some examples:
 * Legal and Illegal variable names**


 * Legal Names**||**Illegal Names**||
 * Argo||139||
 * D||139ABC||
 * d31||fast One||
 * hoppergee||class||
 * hopper_gee||show.sally||
 * largeArea||double||
 * goldNugget||gold;nugget||
 * ||hopper-gee||

It is common for variable names to begin with a lowercase letter, and use an uppercase letter for the start of each letter. This is commonly known as "[|CamelCase]", and is used to make variable names consisting of multiple words easier to read. You may also separate words in variables by using underscores. Here are some examples: code variableName - using camel case variable_name - separating words using an underscore code
 * Naming conventions**