Section 3.2. Files and Their Names

[Page 40 (continued)]

3.2. Files and Their Names

A programming language isn't the only place where computers associate names and values. Your computer's operating system takes care of the files on your disk, and it associates names with those files. Operating systems you may be familiar with include Windows XP, Windows 2000 (Windows ME, NT, ...), MacOS, and Linux. A file is a collection of values (bytes) on your hard disk (the part of your computer that stores things after the power gets turned off). If you know the name of a file, you can tell it to the operating system, and it can give you the values associated with that name.

You may be thinking, "I've been using the computer for years, and I've never 'given a file name to the operating system.'" Maybe you didn't realize that you were doing it, but when you pick a file from a file choosing dialog in Photoshop, or double-click a file in a directory window (or Explorer or Finder), you are asking some software somewhere to give the name you're picking or double-clicking to the operating system, and get the values back. When you write your own programs, though, you'll be explicitly getting file names and asking for the values stored in a file.

Files are very important for media computation. Disks can store acres and acres of information on them. Remember our discussion of Moore's Law (page 9)? Disk capacity per dollar is increasing faster than computer speed per dollar! Computer disks today can store whole movies, hours (days?) of sounds, and the equivalent of hundreds of film rolls of pictures.

These media are not small. Even in a compressed form, screen size pictures can be over a million bytes large, and songs can be three million bytes or more. You need to keep them someplace where they'll last past the computer being turned off and where there's lots of space. This is why they are stored on your hard disk.

In contrast, your computer's memory (RAM) is impermanent (the contents disappear when the power does) and is relatively small. Computer memory is getting larger all the time, but it's still just a fraction of the amount of space on your disk. When you're working with media, you will load the media from the disk into memory, but you wouldn't want it to stay in memory after you're done. It's too big.

Think about your computer's memory as your desk. You would want to keep books that you are currently working with on your desk, but when you are done you will probably move them to a book shelf. You may have many more books on your book shelf than can fit on your desk. A computer can fit much more data on the hard disk than can fit in memory. However, data must be read from disk into memory before you can work with it.

[Page 41]

When you bring things into memory, you usually will name the value, so that you can retrieve it and use it later. In that sense, programming is something like algebra. To write generalizable equations and functions (those that work for any number or value), you wrote equations and functions with variables, like PV = nRT or e = Mc2 or f(x) = sin(x). Those P's, V's, R's, T's, e's, M's, c's, and x's were names for values. When you evaluated f(30), you knew that the x was the name for 30 when computing f. We'll be naming values when we program.

Introduction to Computing & Programming Algebra in Java(c) A Multimedia Approach
Introduction to Computing & Programming Algebra in Java(c) A Multimedia Approach
Year: 2007
Pages: 191 © 2008-2017.
If you may any questions please contact us: