CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ

Java

Java Programming
Numeric variables
Declare and initialize

Variables and data types
  • A variable stores a value that can change as a program executes.
  • Java provides for eight primitive data types that you can use for storing values in memory.
  • The int data type is used for storing integers (whole numbers).
  • The double data type is used for storing numbers that can have one or more decimal places.
How to declare and initialize variables
  • To initialize a variable, you declare a data type and assign an initial value to the variable.
  • An assignment statement assigns a value to a variable. This value can be a literal value, another variable, or an expression.
  • If a variable has already been declared, the assignment statement doesn't include the data type of the variable.
Naming recommendations for variables
  • Start variable names with a lowercase letter and capitalize the first letter in all words after the first word.
  • Each variable name should be a noun or a noun preceded by one or more adjectives.
  • Try to use meaningful names that are easy to remember.
Previous | Declare and initialize | Assignment statements | Arithmetic expressions | Next