giáo trình Java By Example phần 6

Tham khảo tài liệu 'giáo trình java by example phần 6', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Of course there are rules for choosing constant and variable names also known as identifiers because they identify a program object . You can t just type a bunch of characters on your keyboard and expect Java to accept them. First every Java identifier must begin with one of these characters A-Z a-z The preceding characters are any uppercase letter from A through Z any lowercase letter from a through z an underscore and the dollar sign. Following the first character the rest of the identifier can use any of these characters A-Z a-z 0-9 As you may have noticed this second set of characters is very similar to the first. In fact the only difference is the addition of the digits from 0 through 9. NOTE Java identifiers can also use Unicode characters above the hexadecimal value of 00C0. If you don t know about Unicode characters don t panic you won t be using them in this book. Briefly put Unicode characters expand the symbols that can be used in a character set to include characters that are not part of the English language. Using the rules given the following are valid identifiers in a Java program number number2 amount_of_sale amount The following identifiers are not valid in a Java program Inumber http amount of sale amount item Example Creating Your Own Identifiers Suppose that you re now ready to write a program that calculates the total number of parking spaces left in a parking garage. You know that the total number of spaces in the garage is 100. You further know that the vehicles in the garage are classified as cars trucks and vans. The first step is to determine which values would be good candidates for constants. Because a constant should represent a value that s not likely to change from one program run to another the number of vehicles that the garage can hold would make a good constant. Thinking hard someone smell wood burning you come up with an identifier of TOTALSPACES for this value. In Java the constant s definition looks like this

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.