7aafe16d6ce04301be86b0e38635ed79.ppt
- Количество слайдов: 21
VARIABLES AN INTRODUCTION TO VARIABLES & RAM M Scordilis
Summary ü ü ü § § § So far we have learnt to display information (data) on the monitor This information consists of: Strings E. g. “This is a string” Characters E. g. ‘A’ Numeric values. E. g. 111 Of Course data can also consist of graphics and sounds To display our data we used the text user output methods – print and println. We also typed the data we wanted to display within the print statements E. g System. out. println(“ 3 + 4 = “ + ( 3+ 4)); I think you can see that is very limiting. Programs would not be useful if a person had to continually go into a program to change data.
Variables ü ü ü What we need is a “mechanism” i. e. some way in which we can store and change data without having to go into our programming code each time a change to data must be made. You are all familiar with variables in mathematics such as x + y where x and y are replaced with values when you need to perform a calculation. We make use variables in programming. The term variable in programming is not exactly the same as the term used in mathematics.
DATA and RAM ü ü Computers store “facts” i. e. DATA Data can be numbers, characters (text), pictures, sounds, etc Data must be processed as binary digits (0, 1) BITS Data being processed by a computer is stored in memory locations known as as RAM Human Readable data Machine Readable data
RAM - MEMORY BANK Every computer contains a ‘bank’ of RAM. The amount of primary memory in your computer is determined by the size of the RAM chips This is where a computer stores the data you use in your program
CAPACITORS AND RAM ü ü ü SOME TECHNICAL DATA: Each binary digit (0 or 1) is stored in a capacitor A capacitor is an electronic device that stores electricity. A charged capacitor represents a 1 and An uncharged capacitor represents a 0; When a computers power is turned off – all the capacitors loose their electrical charges i. e unsaved data is lost This is why RAM is referred to as volatile memory Transistors control the flow of electricity to the capacitors
Storing Facts cont ü RAM is used to store data while a program is running. data Memory location in ram ü ü ü Programmers cannot work directly with RAM. You will recall RAM consists of capacitors Programming languages create a connection between the variable a programmer uses (creates) and the computer’s memory. As a programmer you don’t have to worry about RAM – the operating system takes care of the memory for you.
Variables and Data Any type of data can be stored in memory integers decimals graphics Strings character sound
Working with Variables 1 ? Integer Decimal Strings Only one type data may be stored in a variable at any one time.
Working with Variables 2 When working with: Integers Use an integer data type when fractions are not needed. Decimals Use a decimal data type when fractions are needed. Strings Characters Use a String data type for a sequence of characters or for numbers when calculations are not required. E. g. house numbers Use a character data type
“Naming” Memory Locations ü ü ü To store data in memory programmers must (a) determine the type of data to be stored (Strings, character, integers, decimals) (b) create an identifier – i. e. give the variable a name Identifiers are “text labels”. These “labels” meaningful identify the data being stored in the variables.
Refresh your memory So a variable is a memory location that stores a value and is labeled with an identifier. Variable (Storage location) 25 age data identifier “We are not quite home and dry just yet. ”
Technical Info DATA TYPES n n Java uses the term ‘primitive types’ when referring to data types. We will use both these terms Lets look at what Java has to ‘offer’ us: Primitive Data Types INTEGRAL TYPES (Integer types) FLOATING POINT (Decimal types) BOOLEAN (True/False) In Java Strings (“Text”) are known as OBJECTS
Technical Info INTEGRAL DATA TYPES CHAR BYTE SHORT INT LONG
Data Types have a range Technical Info Each data type has a ‘limit’ - i. e. - each type can accurately store a value to a certain minimum or maximum value. Integer Types Range of values Bits needed byte -128. . . +127 8 short -32768. . . +32767 16 int -2, 147, 483, 648. . . +2, 147, 48, 3648 32 long -9, 223, 372, 036, 854, 775, 808 … 64 …+9, 223, 372, 036, 854, 775, 807
FLOATING POINT DATA TYPES Technical Info DOUBLE DATA TYPES FLOAT DOUBLE
Range of values Floating Point float double Technical Info Range of values bits +/- 1. 4*10 -45. . . 3. 4*1038 (approx) 32 +/- 4. 9*10 -324. . . 1. 8*10308 (approx) 64 Boolean true/false 1 bit Character 16 bit Unicode (includes ASCII characters) 16 True/ False
RAM ü ü Summary Variables are memory locations situated in RAM These memory locations are used to store data. Each memory location has a unique numeric reference (number). Identifiers are used as “references” to identify the variables.
RAM Expand your Knowledge ü ü ü Characteristics of RAM. Volatile (loose data once power is turned off) Transistors in Ram need to refreshed every few milliseconds. Relatively expensive to secondary memory DIMMS – (Type of RAM) dual in line memory modules.
RAM Assignment Compile (Research)– create a table in Word and compare the differences between ü RAM, ü ROM ü Cache Memory ü Secondary Memory (in terms of purpose cost, speed and storage size)
Assignment. Create a table in word and complete the table Define ROM CACHE SECONDARY MEMORY SPEED SIZE Brief Description (Explain purpose) RAM COST (Expensive/Inex pensive) (Fast/Slow) (How much data is stored)
7aafe16d6ce04301be86b0e38635ed79.ppt