Java 1 Basic Questions

Source: Internet
Author: User
1. the scope is public, private, and protected.
A: The differences are as follows:
Scope: current class, same package, Child class, other package
Public √
Protected √ ×
Friendly √ ××
Private √ ×××
When not written, the default value is friendly -------------------
The array does not have the length () method. It has the Length attribute. The string has the length () method.
12. Differences between overload and override. Can the overloaded method change the type of the returned value?
A: polymorphism, with the same name and parameters. methods with the same name, number of parameters, or type of parameters can change the type of returned values.
13. The elements in the set cannot be repeated. How can we identify whether the elements are repeated or not? Is = or equals () used ()? What are their differences?
A: The elements in the set cannot be repeated. Use the iterator () method to identify whether the elements are repeated or not. Equals () is used to determine whether two sets are equal
The equals () and = Methods Determine whether the reference value points to the same object equals () is overwritten in the class, so that when the content and type of the two separated objects match, the true value is returned.
14. Give me the most common runtime exception
A: What are the differences between domexception, illegalstateexception, nullpointerexception, securityexception, systemexception15, error, and exception?
A: Error indicates that the restoration is not an impossible but difficult case. For example, memory overflow. Exception indicates a design or implementation problem. If the program runs normally, it will never happen.
18. can abstract methods be both static, native, and synchronized?
A: neither of them can be used.
20. Can constructor be overwritten?
A: constructor cannot be inherited, so overriding cannot be overwritten, but overloading can be overloaded.
There is a return statement in try {}, so will the code in finally {} following this try be executed? When will it be executed? Before or after return
A: Yes. It will be executed before return.
26. swtich int, short, Char, or byte. Long and string cannot work on swtich ----------------
27. Differences between arraylist and vector, and between hashmap and hashtable
A: arraylist and vector are mainly used in two aspects.
I. synchronization: the vector is thread-safe, that is, synchronous, while the arraylist is not secure, not synchronous. data growth: When we need to increase, the vector grows by default to the original training, while the arraylist is half of the original growth.
Hashmap and hashtable are mainly used in three aspects.
1. hashtable is based on the dictionary class, And hashmap is an implementation of the map interface.
2. Synchronization: hashtable is thread-safe, that is, synchronous, while hashmap is not secure or synchronous.
3. Value: Only hashmap allows you to use a null value as the key or value of a table entry.

 

 

 

 

34. Differences between final, finally and finalize
A: The final-modifier declares variables or methods as final, which ensures they are not changed during use. Finally-The Finally block is provided for troubleshooting to clear the exception. Finalize-method name. Use the finalize () method to perform necessary cleanup before the Garbage Collector clears objects from the memory. 38. What are the similarities and differences between runtime exceptions and general exceptions?
A: An exception indicates an abnormal state that may occur during the running of the program. An exception indicates an exception that may occur during common operations on the virtual machine. It is a common running error. The Java compiler requires that methods must declare and throw possible non-runtime exceptions, but do not require that they throw uncaptured runtime exceptions.
39. Specify the storage performance and features of arraylist, vector, and sorted list.
A: Both arraylist and vector use arrays to store data. The index data is fast but the insertion speed is slow. The vector uses synchronized, which is inferior to the arraylist. The preview list uses a two-way linked list for storage, opposite;
 
46. What are the methods for sorting? List
A: The sorting methods include insert sorting and exchange sorting (Bubble sorting and quick sorting )------------------
58. What are the features of the interfaces list, map, and set when accessing elements?
A: The list holds elements in a specific order. duplicate elements are allowed. Set cannot have repeated elements and can be sorted internally. Map stores the key-value, which can be multiple values.
59. You can name five common classes, packages, and interfaces.
A: common classes: System string integer filereader filewirter common package: Java. Lang java.net java. Io java. util java. SQL
Common interfaces: runnable serializable set list collection

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.