Mr. Truncale - Robert E. Lee High School
  • Home
  • Digital Media
    • HTML
  • Video Game Design
  • Comp. Programming I
  • Comp. Programming II
  • AP Computer Science
  • 3D Printing
  • Teacher Resources
  • Contact Me

Class Notes for Variables


// int - variable that hold integer data
int a = 10;
// double - variable that holds decimal data
double b = 3.14159;
// char - variable that holds a single character
char c = 'C';
// boolean  - variable that is either true or false
boolean d = false;
// String- variable that holds text data
String e = "Hello World";

// The symbol = is called the assignment operator; it assigns values to variables
//              it does not check/declare equality

// Declaring a variable - telling Java the type and name of a variable
int i;

// Initializing that variable - setting the variable to a value
i = 32;
System.out.println(i);

// Declaring and Initializing on the same line
int j = 32;

// A double can store an int but NOT the other way around
double doubleNum = 10.5;
int intNum = 5;
doubleNum = intNum;
System.out.println(doubleNum);

double doubleNum2 = 10.5;
int intNum2 = 5;
//intNum2 = doubleNum2; // does not work

// Scientific Notation
System.out.println(1.234E4);

// Variable names can not start with a number and should be camel cased
// The only symbol it can contain is the _ underscore

Videos


lesson2_part1.swf
File Size: 9847 kb
File Type: swf
Download File

lesson2_part2.swf
File Size: 4532 kb
File Type: swf
Download File

lesson2_part3.swf
File Size: 2842 kb
File Type: swf
Download File

Robert E. Lee High School
1809 Market
Baytown, TX 77520
281-420-4535
digital media | computer programming I and II | BIM
ap computer science | architectural cad | video game design
national technical honor society | contact me