Java programming Chapter 4 array, string, and Exception Handling

Source: Internet
Author: User

Outline:

1) array

It consists of several items of the same type. Arrays are also objects. Int [] C = new int [2]; C. length or Int C [];

Initialization: the basic data type is initialized to 0 or false. The reference data type is initialized to null. You can use a cyclic structure to initialize it. You can also use the initialization statement to create an array int [] n = {1, 3}. in Java, an array is an object and contains its own methods and fields. For example, N. Length indicates the length of the array.

2) string

String value and value assignment. 11 common methods.

3) Exception Handling

Format: The try block contains several statements that may produce exceptions, followed by several catch blocks for exception processing, and the Catch Block and finally block have at least one.

Exceptions may occur: array subscript out of bounds; Illegal File System Call; network connection error; incorrect operand range; illegal class definition; custom exception requirementsProgramProcessing.

Checked exceptions and non-checked exceptions: The checked exceptions are listed by throws during method declaration and can be detected at compilation. Non-checked exceptions are not in the throws table, errors and runtimeexceptions. The exception can be compiled only after the exception is checked. Non-checked exceptions can only be found at runtime.

Catch (superclass ref) captures sub-classes at the same time; exceptions. There is an inheritance relationship between classes.

Finally block: whether or not exceptions occur, the block is always executed and is generally used to release the obtained resources. If system. Exit () exists in try, finally is not executed; if return exists in try, finally is still executed. No catch or finally at the same time. Common methods in the exception: tostring () printstacktree () getmessage ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.