TAILIEUCHUNG - Thinking in Java 3rd Edition phần 7

phương pháp tĩnh, bạn thường sẽ sử dụng getClass (). Bạn không cần phải sử dụng lớp hiện tại như là định danh nút, nhưng đó là thực hành thông thường. Phản hồi Một khi bạn tạo ra các nút, nó có sẵn dữ liệu hoặc tải hoặc đọc. | static method you ll usually use getClass . You don t need to use the current class as the node identifier but that s the usual practice. Feedback Once you create the node it s available for either loading or reading data. This example loads the node with various types of items and then gets the keys . These come back as a String which you might not expect if you re used to keys in the collections library. Here they re converted to a List which is used to produce an Iterator for printing the keys and values. Notice the second argument to get . This is the default value which is produced if there isn t any entry for that key value. While iterating through a set of keys you always know there s an entry so using null as the default is safe but normally you ll be fetching a named key as in Feedback Companions 0 In the normal case you ll want to provide a reasonable default value. In fact a typical idiom is seen in the lines int usageCount UsageCount 0 usageCount UsageCount usageCount This way the first time you run the program the UsageCount will be zero but on subsequent invocations it will be nonzero. Feedback When you run you ll see that the UsageCount does indeed increment every time you run the program but where is the data stored There s no local file that appears after the program is run the first time. The Preferences API uses appropriate system resources to accomplish its task and these will vary depending on the OS. In Windows the registry is used since it s already a hierarchy of nodes with key-value pairs . But the whole point is that the information is magically stored for you so that you don t have to worry about how it works from one system to another. Feedback There s more to the preferences API than shown here. Consult the JDK documentation which is fairly understandable for further details. Feedback 684 Thinking in Java Regular expressions To finish this chapter we ll look

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.