The first 6 allow for storage of different kinds of numerical values, the last stores a single character (think "keyboard" character). These include: int, byte, short, long, float, double, boolean, and char. There are 8 primitive types of data built into the Java language. The amount of memory allocated for a given variable and how the value associated with that variable should be encoded into 1's and 0's in memory are specified by its type. The information being stored is called the value of the variable, regardless of whether the information is numerical or not. A variable in Java gives us a way to store numerical or other kinds of information for later use, addressing all of the aforementioned considerations. The concept of a (typed) variable solves all of our problems here. The computer also needs to have some reference to where it stored the value in memory, so it can find it again. Examples of types of encodings used include Two's Complement, IEEE 754 Form, ASCII, Unicode, etc. In addition to telling the computer how much memory we want to use to store the value in question, we also need to tell the computer how the value should be stored in memory (i.e., what method of "encoding" should be employed to turn the value into a string of 1's and 0's). For example, it will certainly take more memory to store the Declaration of Independence than it will to store a single letter (i.e., a "character"). These things too, come in different sizes. Of course, sometimes we need to store information that isn't explicitly numerical. Different kinds of numbers require different amounts of memory (more on this in a minute). First, we need to tell the computer how much memory to use to store the value in question. To this end, we will need to do a couple of things. Looking at step 1 in the program above, we will need to tell the computer that it needs to remember the value it is reading in - it needs to store this value in its memory somewhere so we can use it in a computation later. Remember: a computer will read and act upon these instructions one at a time - it is not aware of what is coming up until it gets there! Print the area to the standard output stream (i.e., the console window).Compute the area of a circle with this radius.Read a value representing the radius of a circle from the standard input source/stream.You can think of a simple program as a list of instructions to be read and acted upon sequentially Variables and the 8 Primitive Data Types The Purpose of a Variable (and some vocabulary)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |