This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Chapter III Java Simple Data Types Page 107 Chapter III Java Simple Data Types Chapter III Topics 3.1 Introduction 3.2 Declaring Variables 3.3 The Integer Data Types 3.4 The Real Number Data Types 3.5 Numerical Representation Limits 3.6 Arithmetic Shortcut Notations 3.7 The char & String Data Types 3.8 The Boolean Data Types 3.9 Declaring Constants 3.10 Documenting Your Programs 3.11 Mathematical Precedence 3.12 Type Casting 3.13 Escape Sequences 3.14 The AP Java Subset 3.15 Summary Page 108 Exposure Java A, 2008 Edition 061508 3.1 Introduction In the early days of your math courses only constants were used. You know what I mean. Numbers were 5 , 13 and 127 . You added, subtracted, multiplied and divided with numbers. Later, you had more fun with fractions and decimal numbers. At some point  and the exact year does not matter  variables were introduced. In science and mathematics it is useful to express formulas and certain relationships with variables that explain some general principle. If you drive at an average rate of 60 mph and you continue for 5 hours at that rate, you will cover 300 miles . On the other hand, if you drive at a rate of 45mph for 4 hours , you will travel 180 miles . These two problems are examples that only use constants. The method used for computing this type of problem can be expressed in a more general formula that states: Distance = Rate Time The formula is normally used in its abbreviated form, which is d = r t . In this formula d , r and t are variables. The meaning is literal. A variable is a value that is able to change. A constant like 5 will always be 5 , but d is a variable, which changes with the values of r and t . Both r and t are also variables. Variables make mathematics, science and computer science possible. Without variables you are very limited in the type of programs that you can write. In this chapter you will learn how to use variables in your programs. 3.2 Declaring Variables A computer program is made up of words, which usually are called keywords . The keywords in a program have a very specific purpose, and only keywords are accepted by the compiler. A compiler will only create a bytecode file if the source code obeys all the Java syntax rules. The first rule is that only keywords known to the Java compiler can be used in a program. Another syntax rule is that each variable needs to specify its data type. Page 108 Exposure Java A, 2008 Edition 061508 3.1 Introduction In the early days of your math courses only constants were used. You know what I mean. Numbers were 5 , 13 and 127 . You added, subtracted, multiplied and divided with numbers. Later, you had more fun with fractions and decimal numbers. At some point  and the exact year does not matter  variables were introduced. In science and mathematics it is useful to express formulas and certain relationships with variables that explain some general principle. If you drive at an average rate of 60 mph and you continue for...
View
Full
Document
This note was uploaded on 10/14/2010 for the course APSC AP taught by Professor Kurt during the Spring '98 term at Wooster.
 Spring '98
 KURT

Click to edit the document details