Android interview questions (2) and android interview questions

Source: Internet
Author: User

Android interview questions (2) and android interview questions

1. What is the difference between int and Integer?

Java provides two different types: The reference type and the original type (or the built-in type ). Int Is the original data type of java, and Integer is the encapsulation class provided by java for int. Java provides encapsulation classes for each original type. BooleanBoolean character byteByte primitive short intInteger longLong floatFloat doubleDouble reference type and original type behavior are completely different, and they have different semantics. The reference type and the original type have different features and usage, they include: size and speed problems, which type of data structure is stored, the default value specified when the reference type and original type are used as instance data of a class. The default value of the instance variables referenced by the object is null, and the default value of the original type of instance variables is related to their types.

 

2. Specify the storage performance and features of ArrayList, Vector, and sorted list.

Both ArrayList and Vector use arrays to store data. The number of elements in the array is greater than that in the actual data storage to add and insert elements. They allow the element to be indexed by serial number directly, however, inserting elements involves memory operations such as array element movement, so index data is fast and data insertion is slow. Because Vector uses the synchronized Method (thread-safe), its performance is generally inferior to that of ArrayList, the sorted list uses a two-way linked list for storage. Data indexed by serial number needs to be traversed in the forward or backward direction. However, when inserting data, you only need to record the items before and after this item, so the insertion speed is fast.

 

3. Differences between Collection and Collections.

Collection is the upper-level interface of the Collection class. Its inherited interfaces include Set and List. collections is a help class for collection classes. It provides a series of static methods for searching, sorting, thread security, and other operations on various sets.

 

4. Can an internal class reference its members in the class? Are there any restrictions?

An internal class object can access the content of its external Class Object

 

5. In JAVA, how does one jump out of the current multi-nested loop?

Use the break; return method.

 

6. What is java serialization and how to implement java serialization?

Serialization is a mechanism for processing object streams. Object streams are called object streams that stream object content. You can perform read and write operations on Streaming objects, or transfer streaming objects between networks. Serialization aims to solve the problems caused by read/write operations on Object streams. Serialization implementation: implement the Serializable interface for the class to be serialized. There is no implementation method for this interface. implements Serializable is only to mark that the object can be serialized, then, an output stream (such as FileOutputStream) is used to construct an ObjectOutputStream (Object stream) Object. Then, the writeObject (Object obj) of the ObjectOutputStream Object is used) method, you can write the object whose parameter is obj (that is, save its status). To restore the object, use the input stream.

 

7. What are the differences between static variables and instance variables?

Static I = 10; // constant class A a; a. I = 10; // variable

 

8. What technologies are used to implement MVC? How to implement it?

MVC is short for Model-View-Controller. "Model" indicates the business logic of the application (implemented by the JavaBean and EJB components), and "View" indicates the application surface (generated by the JSP page ), "Controller" provides application processing process control (generally a Servlet). This design model divides the application logic, processing process and display logic into different components for implementation. These components can be used for interaction and reuse.

 

9. What are the similarities and differences between JSP and Servlet, and what are their connections?

JSP is an extension of Servlet technology. It is essentially a simple Servlet method, with more emphasis on the external expression of the application. After JSP compilation, it is "servlet-like ". The main difference between Servlet and JSP is that the application logic of Servlet is in the Java file and is completely separated from the HTML in the presentation layer. In JSP, Java and HTML can be combined into a file with the extension. jsp. JSP focuses on views. Servlet is mainly used for control logic.

 

10. Under what conditions do I call doGet () and doPost ()?

The method attribute in the form label in the Jsp page is doGet () when get is called, and doPost () is called when post is called ().

11. The two objects have the same value (x. equals (y) = true), but different hash codes are available, right?

No. It has the same hash code.

 

12. How many equals 2x8 in the most efficient way?

2 <3

 

13. Can I inherit the String class?

The String class is a final class, so it cannot be inherited.

 

14. Does the array have the length () method? Does String have the length () method?

The array does not have the length () method. It has the length attribute. String has the length () method.

 

15. Does List, Set, and Map inherit from the Collection interface?

List, Set is, Map is not

 

16. can abstract methods be both static, native, and synchronized?

None

 

17. Do I use run () or start () to start a thread ()?

When a thread is started, the start () method is called to make the virtual processor represented by the thread in a running state, which means that it can be scheduled and executed by JVM. This does not mean that the thread will run immediately. The run () method can generate the exit sign to stop a thread.

 

18. Differences between forward and redirect

Forward is a server request resource. The server directly accesses the URL of the target address, reads the response content of that URL, and then sends the content to the browser, the browser does not know where the content sent by the server comes from, so its address bar is still the original address. Redirect means that the server sends a status code based on logic to tell the browser to request the address again. Generally, the browser will re-request the address with all the parameters just requested, so the session and request parameters can be obtained.

 

19. What are the similarities and differences between synchronization and Asynchronization? Under what circumstances should they be used separately? Examples.

If data is shared among threads. For example, if the data being written may be read by another thread or the data being read may have been written by another thread, the data is shared and must be accessed synchronously. When an application calls a method that takes a long time to execute on an object and does not want the program to wait for the return of the method, asynchronous programming should be used, in many cases, adopting asynchronous channels is often more efficient.

 

20. Differences between final, finally, and finalize.

Final is used to declare attributes. Methods and classes indicate that attributes are unchangeable, methods cannot be overwritten, and classes cannot be inherited. Finally is a part of the structure of the exception handling statement, indicating that it is always executed. Finalize is a method of the Object class. This method is called when the garbage collector is executed. It can overwrite this method to collect other resources during garbage collection, for example, close a file.

 

 

21. What are the four components of Android and their functions?

: Activity is the window for interaction between Android programs and users. It is an Android

The most basic type of block construction, which requires a lot of persistence to maintain the state of all sectors

And properly manage the lifecycle and some jump logic.

Service: the backend service serves the Activity and encapsulates a complete functional logic implementation to accept

Upper-layer commands to complete related things and define the Intent to be accepted to provide synchronous and asynchronous

Interface

Content Provider: a third-party Application Data Access solution provided by Android.

To derive the Content Provider class and provide external data, which can be selected like a database

Select sorting, block the storage details of internal data, and provide a unified excuse model to greatly simplify

It provides a more convenient way to integrate data.

BroadCast Receiver Er: accepts one or more Intent triggers.

Message, which is converted into a Notification by simple processing.

Event broadcast model

 

22. ListView optimization solution

1. If the custom adapter is used, the parameters passed in by the method should be considered in the getView method.

Whether contentView is null. If it is null, contentView is created and returned. If it is not

If it is null, it is used directly. Create as few views as possible in this method.

2. Set tag (setTag () for contentView and input a viewHolder object,

It is used to cache the data to be displayed to achieve asynchronous loading of image data.

3. If the listview needs to display a large number of items, it is necessary to consider paging loading. For example, to display

When there are 100 or more, we can consider loading 20 first, and wait for the user to pull to the bottom of the list

Then load the next 20 items.

 

23. What are the startup modes of activity? What does it mean?

In android, there are four activity startup modes:

"Standard" (default)

"SingleTop"

"SingleTask"

"SingleInstance"

 

24. Describe the lifecycle of an Activity.

Activity lifecycle methods include:

OnCreate (), onStart (), onReStart (), onResume (), onPause (), onStop (), on

Destory ();

Visible life cycle: from onStart () to onStop () called by the System ()

Foreground lifecycle: From onResume () to onPause () called by the System ()

 

25. lifecycle of an activity during screen Rotation

When the android: configChanges of the Activity is not set, the split screen will call

Life cycle, which is executed once when the landscape screen is switched, twice when the landscape screen is switched; set the Activity

Android: configChanges = "orientation"

Cycle: Only one time is executed when the screen is split horizontally or vertically.

Android: configChanges = "orientation | keyboardHidden ",

Only the onConfigurationChanged method is executed for each new life cycle call.

 

 

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.