Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Variables, Types, and Operators in Java

Variables, Types, and Operators in Java

This is an introduction to variables, types, and operators in Java as used in my AP Computer Science classes

Cameron Lane

August 26, 2013
Tweet

More Decks by Cameron Lane

Other Decks in Education

Transcript

  1. HelloWorld.java 1 /** 2 * HelloWorld.java 3 */ 4 5

    /** 6 * @author cameronlane 7 * 8 */ 9 public class HelloWorld { 10 11 ! /** 12 ! * @param args 13 ! */ 14 ! public static void main(String[] args) { 15 ! ! // prints Hello, World! to the console 16 ! ! System.out.println("Hello, World!"); 17 ! } 18 19 }
  2. Java Variables • In Java, all variables must have a

    type and an identifier • size in memory
  3. Java Variables • In Java, all variables must have a

    type and an identifier • size in memory • possible operations (strongly-typed)
  4. Java Variables • In Java, all variables must have a

    type and an identifier • size in memory • possible operations (strongly-typed) • variables refer to values (primitives) or pointers to memory locations (objects)
  5. Identifiers Identifiers are the human-readable labels associated variables, classes, or

    methods Identifier Rules: (compiler enforced) A-Z,a-z, 0-9, _ and $ int symb*l = 0;
  6. Identifiers Identifiers are the human-readable labels associated variables, classes, or

    methods Identifier Rules: (compiler enforced) A-Z,a-z, 0-9, _ and $ Exception in thread "main" java.lang.Error: Unresolved compilation problems: Syntax error on token "*", ; expected Name cannot be resolved to a variable
  7. Identifiers Identifiers are the human-readable labels associated variables, classes, or

    methods Identifier Rules: (compiler enforced) A-Z,a-z, 0-9, _ and $ cannot start with number or symbol int 1numberFirst = 0;
  8. Identifiers Identifiers are the human-readable labels associated variables, classes, or

    methods Identifier Rules: (compiler enforced) A-Z,a-z, 0-9, _ and $ cannot start with number or symbol Exception in thread "main" java.lang.Error: Unresolved compilation problem: Syntax error on token "1", delete this token
  9. Identifiers Identifiers are the human-readable labels associated variables, classes, or

    methods Identifier Rules: (compiler enforced) A-Z,a-z, 0-9, _ and $ cannot start with number or symbol no reserved words int public = 0;
  10. Identifiers Identifiers are the human-readable labels associated variables, classes, or

    methods Identifier Rules: (compiler enforced) A-Z,a-z, 0-9, _ and $ cannot start with number or symbol no reserved words Unresolved compilation problem: Syntax error on token "public", invalid VariableDeclaratorId
  11. Identifiers Identifiers are the human-readable labels associated variables, classes, or

    methods Identifier Rules: (compiler enforced) A-Z,a-z, 0-9, _ and $ cannot start with number or symbol no reserved words Style Conventions: (programmer enforced)
  12. Identifiers Identifiers are the human-readable labels associated variables, classes, or

    methods Identifier Rules: (compiler enforced) A-Z,a-z, 0-9, _ and $ cannot start with number or symbol no reserved words Style Conventions: (programmer enforced) use descriptive names int aThing = 0;
  13. Identifiers Identifiers are the human-readable labels associated variables, classes, or

    methods Identifier Rules: (compiler enforced) A-Z,a-z, 0-9, _ and $ cannot start with number or symbol no reserved words Style Conventions: (programmer enforced) use descriptive names int studentCounter = 0;
  14. Identifiers Identifiers are the human-readable labels associated variables, classes, or

    methods Identifier Rules: (compiler enforced) A-Z,a-z, 0-9, _ and $ cannot start with number or symbol no reserved words Style Conventions: (programmer enforced) Upper CamelCase for class names use descriptive names public class JumpingCritter {...}
  15. Identifiers Identifiers are the human-readable labels associated variables, classes, or

    methods Identifier Rules: (compiler enforced) A-Z,a-z, 0-9, _ and $ cannot start with number or symbol no reserved words Style Conventions: (programmer enforced) Upper CamelCase for class names lower camelCase for everything else use descriptive names public static void getAllStudents(){...}
  16. Identifiers Identifiers are the human-readable labels associated variables, classes, or

    methods Identifier Rules: (compiler enforced) A-Z,a-z, 0-9, _ and $ cannot start with number or symbol no reserved words Style Conventions: (programmer enforced) don’t use $ Upper CamelCase for class names lower camelCase for everything else use descriptive names
  17. HelloWorldImproved.java 1 import java.util.Scanner; 2 3 4 public class HelloWorldImproved

    5 { 6 7 ! /** 8 ! * @param args 9 ! */ 10 ! public static void main(String[] args) 11 ! { 12 ! ! Scanner keyboard = new Scanner(System.in); 13 ! ! System.out.println("Enter your name:"); 14 ! ! String name = keyboard.nextLine(); 15 ! ! // prints whatever the value of name is when the 16 ! ! program runs 17 ! ! System.out.println(name); 18 ! ! keyboard.close(); 19 20 ! } 21 22 }
  18. (Primitive) Variable Declaration int i; Set aside 4 bytes (32

    bits) of memory for a variable with the label i 0x198f1327 i 0x198f1347 Java will interpret this data as an int until otherwise directed
  19. (Primitive) Variable Declaration int i; Set aside 4 bytes (32

    bits) of memory for a variable with the label i 0x198f1327 i 0x198f1347 Java will interpret this data as an int until otherwise directed Declaration creates a variable of a given type for use in your program, but does not assign that variable a value.
  20. (Primitive) Variable Assignment int i; Java will interpret this data

    as an int until otherwise directed 0x198f1327 i 0x198f1347
  21. (Primitive) Variable Assignment i = 0; int i; Java will

    interpret this data as an int until otherwise directed 0x198f1327 i 0x198f1347 Fill up the memory location referenced by the label i with the binary representation of 0 00000000000000000000000000000000
  22. (Primitive) Variable Assignment i = 0; Assignment gives a value

    to a variable that has already been declared. int i; Java will interpret this data as an int until otherwise directed 0x198f1327 i 0x198f1347 Fill up the memory location referenced by the label i with the binary representation of 0 00000000000000000000000000000000
  23. (Primitive) Variable Declaration + Assignment int i = 0; 0x198f1327

    i 0x198f1347 00000000000000000000000000000000 Java will interpret this data as an int until otherwise directed Set aside 4 bytes of memory referenced by the label i and fill it with the binary representation of 0
  24. (Primitive) Variable Declaration + Assignment int i = 0; 0x198f1327

    i 0x198f1347 00000000000000000000000000000000 Java will interpret this data as an int until otherwise directed Set aside 4 bytes of memory referenced by the label i and fill it with the binary representation of 0 Usually, we initialize variables by declaring and assigning them a value in a single line of code.
  25. (Primitive) Variable Declaration + Assignment int i = 127; 0x198f1327

    i 0x198f1347 00000000000000000000000001111111 Java will interpret this data as an int until otherwise directed Set aside 4 bytes of memory referenced by the label i and fill it with the binary representation of 127
  26. (Primitive) Variable Declaration + Assignment int i = 127; 0x198f1327

    i 0x198f1347 00000000000000000000000001111111 Java will interpret this data as an int until otherwise directed Usually, we initialize variables by declaring and assigning them a value in a single line of code. Set aside 4 bytes of memory referenced by the label i and fill it with the binary representation of 127
  27. Referencing Variables int i = 127; 0x198f1327 i 0x198f1347 00000000000000000000000001111111

    System.out.println(i); Any references to a primitive variable after it is declared and initialized will return the value stored in the variable Console output: 127
  28. Assigning Values to Variables int i = 127; 0x198f1327 i

    0x198f1347 00000000000000000000000001111111 System.out.println(i); i = 128; System.out.println(i);
  29. Assigning Values to Variables int i = 127; 0x198f1327 i

    0x198f1347 00000000000000000000000001111111 System.out.println(i); i = 128; System.out.println(i); Console output: 127
  30. Assigning Values to Variables int i = 127; 0x198f1327 i

    0x198f1347 00000000000000000000000001111111 System.out.println(i); i = 128; System.out.println(i);
  31. Assigning Values to Variables int i = 127; 0x198f1327 i

    0x198f1347 00000000000000000000000001111111 System.out.println(i); i = 128; 00000000000000000000000010000000 System.out.println(i);
  32. Assigning Values to Variables int i = 127; 0x198f1327 i

    0x198f1347 00000000000000000000000001111111 System.out.println(i); i = 128; 00000000000000000000000010000000 System.out.println(i); Console output: 128
  33. Assigning Values to Variables int i = 127; 0x198f1327 i

    0x198f1347 00000000000000000000000001111111 System.out.println(i); i = 128; 00000000000000000000000010000000 System.out.println(i);
  34. Assigning Values to Variables int i = 127; 0x198f1327 i

    0x198f1347 00000000000000000000000001111111 System.out.println(i); After a variable is declared and initialized, we can change its value at any time by reassigning it. Any previous data stored in the variable is destroyed. i = 128; 00000000000000000000000010000000 System.out.println(i);
  35. Assigning Values to Variables int i = 127; 0x198f1327 i

    0x198f1347 00000000000000000000000001111111 System.out.println(i); After a variable is declared and initialized, we can change its value at any time by reassigning it. Any previous data stored in the variable is destroyed. i = 128; 00000000000000000000000010000000 System.out.println(i); Note that I don’t have to refer to a variable’s type after it has been initialized.
  36. Assigning Values to Variables int i = 5 + 5;

    System.out.println(i); i = i * 500 + 7; System.out.println(i);
  37. Assigning Values to Variables int i = 5 + 5;

    0x198f1327 i 0x198f1347 00000000000000000000000000001010 System.out.println(i); i = i * 500 + 7; System.out.println(i); One can also assign the result of expressions to a variable
  38. Assigning Values to Variables int i = 5 + 5;

    0x198f1327 i 0x198f1347 00000000000000000000000000001010 System.out.println(i); i = i * 500 + 7; System.out.println(i); Console output: 10 One can also assign the result of expressions to a variable
  39. Assigning Values to Variables int i = 5 + 5;

    0x198f1327 i 0x198f1347 00000000000000000000000000001010 System.out.println(i); i = i * 500 + 7; System.out.println(i); One can also assign the result of expressions to a variable
  40. Assigning Values to Variables int i = 5 + 5;

    0x198f1327 i 0x198f1347 00000000000000000000000000001010 System.out.println(i); i = i * 500 + 7; 00000000000000000001001110001111 System.out.println(i); One can also assign the result of expressions to a variable The right hand side of an assignment is always evaluated first, so it is possible to reference declared variables (and reassign them).
  41. Assigning Values to Variables int i = 5 + 5;

    0x198f1327 i 0x198f1347 00000000000000000000000000001010 System.out.println(i); i = i * 500 + 7; 00000000000000000001001110001111 System.out.println(i); Console output: 5007 One can also assign the result of expressions to a variable The right hand side of an assignment is always evaluated first, so it is possible to reference declared variables (and reassign them).
  42. Assigning Values to Variables int i = 5 + 5;

    0x198f1327 i 0x198f1347 00000000000000000000000000001010 System.out.println(i); i = i * 500 + 7; 00000000000000000001001110001111 System.out.println(i); One can also assign the result of expressions to a variable The right hand side of an assignment is always evaluated first, so it is possible to reference declared variables (and reassign them).
  43. Assigning Values to Variables int i = 5 + 5;

    0x198f1327 i 0x198f1347 00000000000000000000000000001010 System.out.println(i); Note that Java evaluates mathematical expressions using the same order of operations you know from algebra class. i = i * 500 + 7; 00000000000000000001001110001111 System.out.println(i); One can also assign the result of expressions to a variable The right hand side of an assignment is always evaluated first, so it is possible to reference declared variables (and reassign them).
  44. (Primitive) Variable Declaration long num; Set aside 8 bytes (64

    bits) of memory for a variable with the label num 0x198f1327 num 0x198f1367 Changing the type changes the size set aside for the variable
  45. (Primitive) Variable Declaration + Assignment 0000000000000000000000000000000000000000000000000000000000000000 0x198f1327 long num =

    0; num 0x198f1367 Set aside 8 bytes (64 bits) of memory for a variable with the label num Changing the type changes the size set aside for the variable
  46. Primitive Types - Signed Integers byte b = 0; short

    s = 0; 0000000000000000 00000000
  47. Primitive Types - Signed Integers byte b = 0; short

    s = 0; int i = 0; 0000000000000000 00000000
  48. Primitive Types - Signed Integers byte b = 0; short

    s = 0; int i = 0; 00000000000000000000000000000000 0000000000000000 00000000
  49. Primitive Types - Signed Integers byte b = 0; short

    s = 0; int i = 0; long l = 0; 00000000000000000000000000000000 0000000000000000 00000000
  50. Primitive Types - Signed Integers byte b = 0; short

    s = 0; int i = 0; long l = 0; 0000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000 0000000000000000 00000000
  51. Primitive Types - Signed Integers byte b = 0; short

    s = 0; int i = 0; long l = 0; 0000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000 0000000000000000 00000000 1 byte
  52. Primitive Types - Signed Integers byte b = 0; short

    s = 0; int i = 0; long l = 0; 0000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000 0000000000000000 00000000 1 byte 2 bytes
  53. Primitive Types - Signed Integers byte b = 0; short

    s = 0; int i = 0; long l = 0; 0000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000 0000000000000000 00000000 1 byte 2 bytes 4 bytes
  54. Primitive Types - Signed Integers byte b = 0; short

    s = 0; int i = 0; long l = 0; 0000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000 0000000000000000 00000000 1 byte 2 bytes 4 bytes 8 bytes
  55. Primitive Types - Signed Integers byte b = 0; short

    s = 0; int i = 0; long l = 0; 0000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000 0000000000000000 00000000 One bit of each signed integer is used to represent the sign of the integer. 1 byte 2 bytes 4 bytes 8 bytes
  56. Primitive Types - Signed Integers byte b = 0; short

    s = 0; int i = 0; long l = 0; 0000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000 0000000000000000 00000000 1 byte 2 bytes 4 bytes 8 bytes What is the range of values that can be stored in each type?
  57. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  58. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  59. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  60. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  61. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  62. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  63. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  64. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  65. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  66. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  67. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  68. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  69. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  70. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  71. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  72. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  73. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  74. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  75. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  76. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  77. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  78. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  79. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  80. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  81. Primitive Data Types Type Size Range byte 1 byte -27

    to 27 short 2 bytes -215 to 215 int 4 bytes -231 to 231 long 8 bytes -263 to 263 float 4 bytes 3.4E±38 double 8 bytes 1.8E±308 boolean 1 byte true or false char 2 bytes Unicode character codes
  82. Assignment variableIdentifier = value; counter = 5 * 5; weight

    = 4.4; canDrive = false; c = 0x48; = is the assignment operator
  83. Assignment variableIdentifier = value; counter = 5 * 5; weight

    = 4.4; canDrive = false; c = 0x48; Assigns result of right hand side to variable on left hand side = is the assignment operator
  84. Initialization (Declaration + Assignment) typeName variableIdentifier = value; int counter

    = 0; double weight = 45.7; boolean canDrive = false; char c = ‘H’; Creates space in memory based on type of the variable, then assigns result of right hand side
  85. int 3 /** a normal assignment statement */ 4 !!

    int counter = 0; 5 !! 6 !! /** reassigning the value of counter */ 7 !! counter = 10; 8 9 !! /** the largest and smallest possible int values 10 !! * have constants associated with them 11 !! */ 12 !! int big = Integer.MAX_VALUE; 13 !! int small = Integer.MIN_VALUE; 14 !! 15 !! /** assigining the result of an expression 16 !! * that returns an int */ 17 !! int result = 5 + 5; 18 19 !! /** note that this returns and int! */ 20 !! int quotient = 10 / 3;
  86. double 22 !! /** double values */ 23 !! double

    weight = 1.5; 24 !! 25 !! /** if either of the operands is a double, the 26 !! * result is a double 27 !! */ 28 !! double product = 4 * 3.2;
  87. double 22 !! /** double values */ 23 !! double

    weight = 1.5; 24 !! 25 !! /** if either of the operands is a double, the 26 !! * result is a double 27 !! */ 28 !! double product = 4 * 3.2; A double is 8 bytes of space, but there are infinitely many real numbers (even between 0 and 1).
  88. double 22 !! /** double values */ 23 !! double

    weight = 1.5; 24 !! 25 !! /** if either of the operands is a double, the 26 !! * result is a double 27 !! */ 28 !! double product = 4 * 3.2; How can finite space be used to represent infinitely many numbers?
  89. double 22 !! /** double values */ 23 !! double

    weight = 1.5; 24 !! 25 !! /** if either of the operands is a double, the 26 !! * result is a double 27 !! */ 28 !! double product = 4 * 3.2; http://introcs.cs.princeton.edu/java/91float/ How can finite space be used to represent infinitely many numbers?
  90. boolean 31 !! boolean isDifficult = false; 32 !! boolean

    isEasy = true; 33 !! boolean isAwesome = isEasy; A boolean could be represented in one bit, but it actually uses and entire byte.
  91. char 34 ! 35 !! /** char takes unicode character

    code (hex, bin , dec ) 36 !! * or letter in single quotes */ 37 !! char hex = 0x48; 38 !! char bin = 0b1001000; 39 !! char dec = 72; 40 !! char letter = 'H'; 41 !! A char is 16 bits of unsigned space. What is the range of values that can be assigned to a char?
  92. Code Examples Describe what will happen when each code segment

    is executed int factor = 5 * 10 + 3; double root = “x”;
  93. Code Examples Describe what will happen when each code segment

    is executed int factor = 5 * 10 + 3; double root = “x”; boolean isActive = False;
  94. Code Examples Describe what will happen when each code segment

    is executed int factor = 5 * 10 + 3; char c = “H”; double root = “x”; boolean isActive = False;
  95. Code Examples Describe what will happen when each code segment

    is executed int factor = 5 * 10 + 3; int factor = 5.0375; char c = “H”; double root = “x”; boolean isActive = False;
  96. Code Examples Describe what will happen when each code segment

    is executed int factor = 5 * 10 + 3; int factor = 5.0375; double weight = 45.7; char c = “H”; double root = “x”; boolean isActive = False;
  97. Code Examples Describe what will happen when each code segment

    is executed int factor = 5 * 10 + 3; int factor = 5.0375; double weight = 45.7; char c = “H”; double root = “x”; boolean isActive = False; double number = 6;
  98. Code Examples Describe what will happen when each code segment

    is executed int factor = 5 * 10 + 3; int factor = 5.0375; double weight = 45.7; boolean canDrive = “false”; char c = “H”; double root = “x”; boolean isActive = False; double number = 6;