CS 1410 Lecture 2: Components of Code and Variables Intro
Document Summary
Components of code (1) variables (2) assignment (3) expressions. Variables; storage locations int number = 0; int elapsedtimeinseconds; Give good names to variables, so they are easier to read: naming variables, the first word isn"t capitalized, continued words are capitalized with no spaces, every variable has. 4) scope; where in the program a variable can be used. 5) lifetime; when does it begin existence and when is the information lost. The variable is gone after the main method (within braces {}), or gone within other pair of braces {: types of variables. Assignment; giving values to a variable int size; //declaration of a variable int x, y; //declaring multiple variables at once: size = 42; //assigning a value to the variable. Expressions; any portion of a java statement that computes a value of some type int t = 4 + 3: operations with different variable types results in the most broad type.