{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

03-SimpleDataTypes

# 03-SimpleDataTypes - Chapter III Java Simple Data Types...

This preview shows pages 1–4. Sign up to view the full content.

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

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

View Full Document
Page 108 Exposure Java A, 2008 Edition 06-15-08 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.
Chapter III Java Simple Data Types Page 109 How about first concentrating on one rule at a time? So what exactly is a keyword? You have seen certain words like void , static and println , but that only tells part of the story. Keywords can be divided into three categories. Java Keywords Reserved Words Pre-defined Java Identifiers User-defined Identifiers Reserved Words Reserved words are part of the Java language the same way that table , walk and mother are part of the English language. Each reserved word has a special meaning to Java and these reserved words cannot be used as an identifier for any other purpose in a program. Reserved words that you have seen so far are public, void and static .

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern