Basic Java Knowledge

Source: Internet
Author: User

First, the data type

1.java, all numeric types account for the number of bytes and platform-independent, there is no unsigned type in Java

2. For overflow floating-point type, expressed in Nan. Double.isnan (x)

3.char type accounted for 2 bytes

4. Boolean types cannot be converted to integers, avoiding the IF (x=3) problem in C + +, if the conversion is possible. :

5.&& | | Will short circuit

6. Two operands if one is a double, the other is converted to double

If one is float, the other will turn into a float

If one is long, the other is converted to long;


Second, string

A 1.java string is a sequence of Unicode characters.

2.1 A String class object is an immutable string that can be modified to refer to another string.

Pros: The compiler can let strings be shared, with various strings in the common storage pool. Only string constants are shared, and the results of operations such as + or substring are not shared;

equals compares content, and = = Compares location only

2.2 Common APIs:

CharAt (), CompareTo () Endwith () equals () Equalsignorecase () indexOf ()

LastIndexOf () Length () Replace () substring () toLowerCase () toUpperCase () trim ()


3. Building a String

StringBuilder high efficiency, suitable for single thread

StringBuffer low efficiency, suitable for multi-threaded


4.Scanner

Scanner (InputStream in) Scanner (new File ()) Scanner (String str)

Nextline () line next () Word Nextint () nextdouble () Hasnext ()

PrintWriter (file f) constructs a printwriter that writes to a file

Four, array

1.array.copyof (oldarray,length) is often used for expansion, and arrays are allocated on the heap.

2.array.tostring (type[] a)

3.array.sort () BinarySearch () Fill ()



Basic Java Knowledge

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.