The difference between keywords in Java basic from arrays to collections !!!!, Java keywords

Source: Internet
Author: User
Tags java keywords

The difference between keywords in Java basic from arrays to collections !!!!, Java keywords

1. & differences and contacts:

Similarities:The results are the same.

Differences:If the double & number is used for determination, if condition 1 is false, condition 2 is not judged, but the single & number will continue to be judged.

2. | and | Differences and connections:

Similarities:The results are the same.

Differences:If the | number is used for judgment, if the condition is true, condition 2 is not judged, but the single | number will continue to be judged.

 

3. = and equals:
=:Compare the address (reference data type ).

Equals:Compares the value of a string.

4. Differences between exceptions and errors:

Exception:The program is abnormal in the Java program.
Error:Errors are generally caused by the Java Virtual Machine or hardware. If the program is abnormal, the message ends with an Error, which means an Error. Other errors occur.

5. What is the difference between constructor and general function?

Structure:
1. the constructor does not return a value. The method name is the class name.
2. the constructor is called by jvm and cannot be called manually. It will only be called once.
Purpose:
1. assign a value to the attribute during initialization.
2. Describe an object's behavior.

6. Differences between equals and equalsIgnoreCase:

Equals is case-insensitive.

EqualsIgnoreCase is case-insensitive.

7. Differences between StringBuffer and StringBulider:

Similarities:
(1). It is a string buffer class.
(2). The methods of the two mines are the same.
Differences:
(1). the StringBuffer thread is safer and has low operation efficiency. The StringBulider thread is insecure and has high efficiency.
(2). StringBuffer is available in JDK and only available in StringBulider1.5.

8. What are the features of the List, Map, and Set interfaces when accessing elements?

List interface, which can have repeated elements and is an ordered set.

Map interface, double-row set, stores data in the form of keys and values. Duplicate keys are not allowed, and duplicate values are allowed.
Set interface. duplicate elements cannot exist. It is an unordered Set.

9. Differences between Vector and ArrayList:

 Similarities:The underlying layers of Vector and ArrayList are implemented through the Objec array.
Differences:
1. ArrayList is highly efficient because threads are not synchronized.
The Vector thread is synchronous and the operation efficiency is low.
2. ArrayList appears in jdk1.2, and Vector is in jdk1.0.

10. What is the difference between the ArrayList and ArrayList?

Shortlist:Elements are added quickly, deleted, and found slowly. The elements are unordered in the memory.
ArrayList:There is an array (Object []). It is slow to add or delete elements, and the search is fast. The elements are ordered in the memory. The default capacity is 10.
It is 1.5 times that of the original version.

11. What is the difference between Array and list set (ArrayList:

Array:It can contain basic data types and object types. Its space is fixed and cannot be added again when there is not enough space. If necessary, set the size of debugging space in advance.
ArrayList:It can only contain object types, and its space increases dynamically. If there is not enough space, it will create a new array that is twice as large as the original one.

12. Differences between member variables and local variables:

Location defined:
1. defined in the class outside the method.
2. Local variables are defined in methods.
Role:
1. member variables are common attributes used to describe the same class of things (objects.
2. A local variable is used to provide a variable for the method.
 Lifecycle:
1. member variables are created with the creation of objects and disappear with the disappearance of objects.
2. When a local variable is created with the method call, the scope of the method disappears.
To distinguish the initial values:
1. member variables. If you do not assign values, they have default values.
Int Is 0 by default.
Float is 0.0f by default.
The default value of double is 0.0.
Boolean defaults to false
Char default''
String (reference type) null;
2. Local variables: local variables have no initial values and must be initialized before they can be used.

 

Related Article

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.