TAILIEUCHUNG - Lecture Introduction to programming with Java - Chapter 5: Using pre-built methods

Chapter 5 provides knowledge of using pre-built methods. This chapter includes contents: The API library, API headings, math class, wrapper classes for primitive types, lottery example, string methods, formatted output with the printf method. | Chapter 5 - Using Pre-Built Methods The API Library API Headings Math Class Wrapper Classes for Primitive Types Lottery Example String Methods: substring indexOf lastIndexOf Formatted Output with the printf Method 1 The API Library When working on a programming problem, you should normally check to see if there are pre-built classes that meet your program's needs. If there are such pre-built classes, then use those classes (don't "reinvent the wheel"). For example: User input is a rather complicated task. The Scanner class handles user input. Whenever you need user input in a program, use the Scanner class's input methods (rather than writing and using your own input methods). Math calculations are sometimes rather complicated. The Math class handles math calculations. Whenever you need to perform non-trivial math calculations in a program, use the Math class's methods (rather than writing and using your own math methods). 2 The API Library Java's pre-built classes are stored in its class library, which is more commonly known as the Application Programming Interface (API) library. See . Java's API classes are not part of the core Java language. For a program to use an API class, the class first needs to be loaded/imported into the program. For example, to use the Scanner class, include this at the top of your program: import ; The thing that precedes Scanner is called a package. A package is a group of classes. The package contains quite a few general-purpose utility classes. The only one you'll need for now is the Scanner class. 3 The API Library Some classes are considered to be so important that the Java compiler automatically imports them for you. The automatically imported classes are in the package. The Math class is one of those classes, so there's no need for you to import the Math class if you want to perform math operations. The Java compiler .

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.