VariablesAndDataTypes

VariablesAndDataTypes - Variables and Data Types COE318...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 1 Variables and Data Types
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 2 Two kinds of variables: Primitive type Object Reference type Variables must have a type and a name. int count; type name
Background image of page 2
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 3 Type Bit Depth Value Range boolean (JVM specific) true or false char 16 bits 0 to 65535 byte 8 bits -128 to 127 short 16 bits -32268 to 32767 int 32 bits -2147483648 to 2147483647 long 64 bits -huge to huge float 32 bits varies double 64 bits varies Primitive Types
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 4 int x; x = 234; byte b = 89; double d = 34.98; char c = ‘f’; int z = x; boolean found = true; long b = 3456789; float f = 32.5f; Primitive Declarations with assignments
Background image of page 4
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 5 Which conversions are legal ?? int x = 24; byte b = x; byte b = 127; int j = b;
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 6 Primitive: byte, short, int, long, float, double, char, boolean. int x; x = 6; 6 x
Background image of page 6
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 7 Object Reference (Non-primitive) Circle y; y = new Circle(5); 5 radius y a Circle object public class Circle { int radius; Circle(int j) { radius = j; } int getRadius() { return radus; } ……… }
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 8 Primitive: byte, short, int, long, float, double, char, boolean. int x; x = 6; int y = x; Reference (Non-primitive) Circle p; p = new Circle(5); Circle q = p; 5 radius p 6 x a Circle object 6 y q p and q are aliases
Background image of page 8
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 9 Arrays objects that help us organize large amount of information An array is a structure that can hold multiple values of the same type. After creation, an array is a fixed-length structure. is an object in Java
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 10 Arrays: Example public class ArrayTest { public static void main(String[] args) { int[] ia = new int[4]; for (int i = 0; i < ia.length ; i++) { ia[i] = i; } for (int i = 0; i < ia.length; i++) { System.out.println( ia[i] ); } } } Answer: 0 1 2 3
Background image of page 10
COE318 Fall 2008, Olivia Das, Elec. and Comp. Engg., Ryerson University 11 Once an array is created, it has a fixed size the index value must be in range 0 to N-1
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/12/2010 for the course COE 318 taught by Professor Ken during the Spring '08 term at Ryerson.

Page1 / 39

VariablesAndDataTypes - Variables and Data Types COE318...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online