Android Face questions and Answers

Source: Internet
Author: User
Tags message queue sqlite database

Java

What is 1.GC? Why do you have a GC? GC is the meaning of garbage collection (Gabage Collection), memory processing is where programmers are prone to problems, forgetting or wrong memory recycling can cause program or system instability or even crashes, The GC functionality provided by Java can automatically monitor whether an object exceeds the scope to achieve the purpose of automatically reclaiming memory, and the Java language does not provide a way to release the displayed operation of the allocated memory. What are the explanatory techniques  2.xml, and what are the differences? The DOM and Saxdom parse the document into a document tree that can be traversed, added, modified, and deleted on the node. Read into memory at once and consume large memory. Sax is the first to parse the document, driven by events. Does not read into memory at once, consumes less memory, cannot read nodes arbitrarily, and cannot add, modify, and delete nodes. Can the  3.switch statement function on a byte, on a long, on a string? switch can function on Byte, char, short, and int, and JDK1.7 can be used on a string.  4. " = = "What is the difference between the Equals method?" = = and equals can compare addresses. = = is an operator, Equals is a method, and a method can change its behavior by overriding, such as the Equals of string is the comparison of string contents.  5. Can the construction method be overridden and overloaded? Construction methods cannot be overridden but can be overloaded.  6. What are object-oriented features? Encapsulation, inheritance, polymorphism, and abstraction. 7. What are the differences between abstract classes and interfaces? 1). Abstract class is an abstract class modification, and the interface is interface decorated. 2). Abstract classes can have any type of property, and interfaces can only have static-constant-decorated properties. 3). Abstract classes can have common methods and abstract methods, and the methods of interfaces are abstract methods. 4). Abstract classes and interfaces cannot be instantiated, but abstract classes have a constructor method, and interfaces do not have a constructor method. 5). Abstract classes can only inherit one root, and interfaces can be implemented multiple.  8. Can an inner class reference a member of its containing class? Are there any restrictions?   can be referenced. If you need to specify the current class, use the external class. This to refer to. If you reference a local variable, you need to specify the local variable as final.  9.string s = new string ("XYZ"); several string Object created? What is the difference between the two? 2 of objects. "XYZ" is created in a string constant pool, and new string () is created in the heap.  10.try {} has a return statement, then the last {} immediately following the tryCode will not be executed, when executed, before or after return?  will be executed before return. The difference between  11.integer and int is the wrapper class, int is the basic data type. Wrapper classes have methods and properties that do not have a basic data type. The wrapper class can be converted to the base data type by Intvalue, or the base data type can be converted to a wrapper class by using the new Integer (). After JDK1.5, the wrapper class and the base data type can be converted automatically. What is the difference between  12.sleep () and wait ()? Sleep is a method of the thread class, and wait is a method of the object class. Sleep is automatically awakened, and wait requires other threads to wake up. Sleep does not release the sync lock, and wait releases the sync lock. Sleep can be used in any method, and wait can only be used in synchronous methods or synchronous blocks.  13.sleep () does not release an object lock to auto-recover when wait () frees an object lock into the wait lock pool that waits for this object to be issued notify () method before it enters the wait lock pool to prepare the object lock to get into the running state  14. What are the similarities and differences between synchronous and asynchronous? Under what circumstances are they used separately? Synchronization means that the method can only be executed by one thread at a time, and other threads need to wait. Asynchronous means that multiple threads can execute a method at the same time and share the same resource. Synchronization allows access to a resource with security, because it can only be accessed by one thread at a time. But the efficiency is not high. Asynchronous access to resources can cause instability, such as multiple threads accessing a resource at the same time, one in the modification, one in the delete, one in the read, which can cause confusion of resources. However, the execution efficiency is improved because of the simultaneous operation.  15. Start a thread by using the run () or start ()  start () method to start the thread, which is the main method that the thread executes. How many types of streams are there in  16.java? The JDK provides some abstract classes for inheritance for each type of stream, tell me what classes they are. There are three streams in Java, namely byte stream (InputStream, outputstream), character stream (Reader, Writer), object Flow (ObjectInputStream, ObjectOutputStream).  17. What is the difference between a byte stream and a character stream? The byte stream is used to read or write out data such as binary data, slices, and images. A character stream is used to read or write characters data, such as transmitting a string. All data can be processed by byte stream, but if it is character data, the byte stream will need to be transferred after conversion, if it is convenient to use character streamConversion of data. What's the difference between  18.error and exception? error is a system error, and the code cannot handle errors such as memory overflow, stack overflow, and so on. Exception is a program exception, can be handled by code Try-catch, such as null pointer exception, array out of bounds and so on.  19. Talk about the difference between final,finally,finalize? Final is a modifier that can be decorated with classes (cannot be inherited), attributes (constants), and methods (cannot be overridden). Finally is the block of code in the exception handling block that represents the code block that will execute anyway. Finalize is a method of the object class that executes the method before the object is garbage collected.  20. When a thread enters an synchronized method of an object, does the other thread have access to other methods of this object? If other methods do not add synchronized, they can be entered.  21. When an object is passed as a parameter to a method, this method can change the properties of the object and return the changed result, so is it a value pass or a reference pass? In Java, only the value is passed, and if the object is passed, the address of the object is actually passed.  22. Scope public,private,protected, and the difference between non-write public modifier, which means any class can be accessed. Protected is a protected modifier that represents a homogeneous, identical package, and different package, but the parent-child relationship is accessible. Does not write the default modifier, or the package modifier, which means that only the same class or classes under the same package can be accessed, and the packet cannot be accessed. Private modifier, which means that only the same kind can be accessed, out of which the class cannot be accessed.  23. Use the most efficient method to calculate 2 times 8 for a few 2 3 to shift the binary of 2 to the left 3 bits. Use << to shift in Java. What is the difference between  24.heap and stack. The heap represents heaps, and stack represents stacks. Put the object in the heap, and put the reference variable in the stack. Heap space is an unordered space, the stack is the advanced post-out structure.  25. Runtime exceptions are different from generic exceptions run-time exceptions are exceptions that inherit from RuntimeException, which can be thrown out of the process at compile time if a problem occurs at run time. Common exceptions, such as Nullpointexception, ArrayIndexOutOfBoundsException, are also known as compile-time exceptions, which are subclasses that inherit exception but do not belong to RuntimeException. If the program appears in thisSome exceptions, which must be captured or thrown at compile time, or the compilation cannot pass. such as IOException, filenotfoundexception 26. The advantages and principles of garbage collection. and consider 2 kinds of recycling mechanism a notable feature of the Java language is the introduction of garbage collection mechanism, so that the C + + Programmer's most headache of memory management problem solved, it makes the Java programmer in writing programs no longer need to consider memory management. Because there is a garbage collection mechanism, objects in Java no longer have a "scope" concept, and only references to objects are scoped. Garbage collection can effectively prevent memory leaks and effectively use memory that can be used. The garbage collector is typically run as a separate low-level thread, unpredictable and clear and recyclable for objects that have died in the heap or that have not been used for a long time, and the programmer cannot call the garbage collector in real time for garbage collection of an object or all objects. The recycling mechanism has generational replication garbage collection and token garbage collection, incremental garbage collection.  27. Describe the mechanism by which the JVM loads the class file? The loading of classes in the JVM is implemented by ClassLoader and its subclasses, and Java ClassLoader is an important Java Runtime system component. It is responsible for locating and loading classes of class files at run time.  28. Is it possible to make a call to a non-static method from within a static method? No, unless you first create an object of the same class as the non-static method.  29. What is Java serialization and how do I implement Java serialization?  30. Use an output stream to construct an object flow object using the SERIALIZABLE keyword and then use the object Flow object's WriteObject () to write out the  31.anonymous Inner Class for an object that has a parameter of obj ( Anonymous inner Class) can extends (inherit) other classes, can you implements (implement) interface (interface)? An anonymous inner class can inherit a class or implement an interface, but it is not displayed using extends or implements to inherit or implement. What is the difference between  32.arraylist and vectors, HashMap and Hashtable? ArrayList is a collection class of JDK1.2 and thread insecure, vector is a collection class of 1.0 and thread-safe, both usages are similar. The HashMap thread is unsafe and can vent key or null values, hashtable thread security and cannot empty keys or null values. What's the difference between  33.string and StringBuffer? Under what circumstances should they be used? StringThe base class of the string that is immutable. StringBuffer is the use of heaps to store strings, and can change the contents of a string.  34.new What is the difference between a class object and the use of a class name to create an object? What should you pay attention to when using them? The new object is the most common way to create objects, using a class template to create objects by reflection. Although the object is created at the bottom of the new object through a class template, the new object is more efficient than creating objects directly from the class template. However, the way you use class templates can make your program more flexible. The difference between  35.linkedlist and ArrayList? 1) LinkedList is a collection of linked list structures, a collection of ArrayList array structures. 2) LinkedList efficiency is higher than ArrayList when adding or removing data in the middle or in front. 3) LinkedList is less efficient than ArrayList when the data is last added or deleted. 4) ArrayList efficiency is higher than linkedlist when traversing data.  36. Introducing the Collection Framework (collection framework) commonly used in Java development? The collection framework in Java is divided into collection and map interfaces, and each element of a collection under the collection interface consists of a value, and each element of the collection class under the Map interface is composed of key-value pairs. The collection interface has a list and set interface below, and the common classes under the list interface are ArrayList, LinkedList, and vectors. The elements in them can be repetitive and orderly. The common classes under the set interface are HashSet, TreeSet. The elements in them cannot be duplicated and are unordered.  37. What are the differences and connections between throw and throws in an exception? Throw throws an exception in the code, followed by an exception object, which throws an exception as soon as the virtual machine runs here. Throws is written on the method declaration, indicating that the method may throw an exception, followed by the exception type. The method can be invoked to either process it or continue to throw it out.  38. Overloading and overriding the difference overload is that in a class where two or more than two methods have the same method name and a different parameter list, these methods are overloaded methods. Overrides mean that in a parent class and a subclass, a method of a subclass and a method of the parent class have the same method name, the same argument list, the same return type, the access modifier scope of the subclass is not less than the access modifier scope of the parent class, the type and number of exceptions are not greater than or more than the exception type and number of the parent In other words, an overloaded method is a method that distinguishes the same method name in the same class, overriding the same method as finding the parent classMethod name and re-change the behavior of the method. The role of  android 39.activity, Service, Broadcastreceiver (Android) activity:activity is the window that the Android program interacts with the user, Is the most basic of the Android building block, it needs to maintain the state of the community, do a lot of persistent things, properly manage the life cycle and some jump logic service: Background services to activity, encapsulation has a complete functional logic implementation, accept the upper command, complete the relevant instructions, Define the intent that need to be accepted provide synchronous and asynchronous interfaces broadcast Receiver: Accept one or more intent as triggering events, accept messages, do some simple processing, convert to a notification, Unified the Android Event broadcast model &NBSP;40. Describes the life cycle methods of a complete Android activity lifecycleactivity: OnCreate (), OnStart (), Onrestart (), Onresume (), OnPause (), OnStop (), Ondestory (),  41. What is the difference between explicit intent and implicit intent (Android) Intent definition: Intent is a request message that is passed between different components and is the request and intent of the application. As a complete messaging mechanism, intent requires not only the sending side, but also the receiving end. Explicit intent definition: For intent that explicitly indicates the name of the target component, we call it an explicit intent. Implicit intent definition: for intent that do not explicitly indicate the name of the target component, it is called an implicit intent. Description: The Android system uses Intentfilter to find objects related to implicit intent.  42.android the method of thread synchronization can adopt synchronous method and synchronous block.  43. How to encapsulate an activity as a dialog box? How does the activity package grow as a menu? Simple you just need to set the subject of the activity to define where the activity is in the androidmanifest.xml sentence:  xml code  android:theme= "@android: style/ Theme.dialog " android:theme=" @android: StYle/theme.dialog "  This makes your application into a dialog box pop-up, or  xml code  android:theme=" @android: style/ Theme.translucent " android:theme=" @android: style/theme.translucent "  becomes translucent. Override the Oncreateoptionmenu method to handle the behavior after you press menu, and then pop the activity in the dialog box in the method. You can also use event snooping to listen to the menu button and then press the button to eject the activity in the form of a dialog box.  44. Introduction to the Architecture application layer of Android: Android applications typically involve the user interface and interaction. Application Framework layer: UI components, various managers, and so on. function library Layer: System C library, Media Library, WebKit, SQLite, etc. Linux Core Library: components running on Linux systems.  *45. Description when the activity's life cycle does not set the activity's android:configchanges when the vertical and horizontal screen is switched on, the screen will recall each life cycle, and will be executed once when the screen is cut, and two times when the screen is cut .  When you set the activity's android:configchanges= "orientation", the screen will recall the various lifecycles, and only perform a .  setting of the Android when the activity is cut horizontally or vertically: Configchanges= "Orientation|keyboardhidden", the cut screen does not recall the individual lifecycles, only the Onconfigurationchanged method is executed.  46.android What kinds of animations are there, and what are their characteristics and differences? Two, one is the motion tween (Tween) animation, and the other is the frame animation (frame) animation. Tween animations, which enable the view component to move, zoom in, zoom out, and create transparency, another frame animation, a traditional animation method, is implemented by sequential playback of a well-arranged picture, similar to a movie.  47. The longest short message accounts for about how many byte?140byte,70 characters.  48. Describes the principle of the Handler mechanism Andriod provides Handler and Looper to satisfy the communication between threads. Handler first-out principle. The Looper class is used to manage specific lines rangeMessage exchange between objects.  1) Looper: A thread can produce a Looper object, which manages the message queue of this line thread. &NBSP;2) Handler: You can construct Handler objects to communicate with Looper in order to push new messages into the message queue, or to receive messages sent by Looper from the message queue. &NBSP;3) Message queue (Message Queuing): Used to hold messages placed by the thread. &NBSP;4) Thread: The UI thread is usually the main thread, and the Android launcher will create a message Queue for it.  49. How do I publish a SQLite database (dictionary.db file) with the apk file? You can copy the Dictionary.db file to the Res\raw directory in the Eclipse Android project. All files in the Res\raw directory are not compressed, so that the files in that directory can be extracted directly.   Use the OpenDatabase method to open the database file, and if the file does not exist, the system automatically creates the/sdcard/dictionary directory and copies the dictionary.db files in the Res\raw directory to the/sdcard/  50 in the dictionary directory. Talk about MVC in Android. MVC is the abbreviation of Model,view,controller, MVC contains three parts: Model object: Is the main part of the application, All business logic should be written on that layer. View object: Is the part of the application that is responsible for generating the user interface. It is also the only layer that the user can see in the entire MVC architecture, receiving input from the user and displaying processing results. Controller (Control) object: is based on user input, control the user interface data display and update model object state of the part, the controller more important a navigation function, in response to the user to start the relevant events, to the M layer processing. Android encourages weak coupling and component reuse, and MVC in Android is embodied in the following: 1) View: The general use of XML file interface description, when used can be very convenient to introduce. 2) control layer (Controller): The task of Android control layer usually falls on the shoulders of many acitvity, this phrase also implies not to write too much code in acitivity, to pass ActIvity Delivery model business Logic layer processing, another reason to do this is that Android acitivity response time is 5s, if the time-consuming operation is placed here, the program can easily be recycled. 3) Model: the operation of the database, the operation of the network, etc. should be processed in the model, of course, business calculations and other operations must be placed in the layer.  51. Please introduce the five layout frame layout (framelayout) linear layout (LinearLayout) Table layout (tablelayout) relative layout (relativelayout) Absolute Layout ( Absolutelayout)  52. How to enable service, how to deactivate Service1) StartService to start service, StopService stop service. 2) Bindservice binding Service,unbindservice unbind the service.  53. How to optimize the ListView1, if the custom adapter, then in the GetView method to consider the method passed in parameters Contentview is null, if NULL to create Contentview and return, If it is not NULL, it is used directly. Create as few view as possible in this method. 2, to Contentview set tag (Settag ()), passed in a Viewholder object, used to cache the data to be displayed, can achieve the effect of asynchronous loading of image data. 3. If the ListView needs to display a lot of item, you should consider paging load. For example, to show a total of 100 or more times, we can consider loading 20 first, and so on when the user pulls to the bottom of the list to load the next 20.  54. Describe the startup mode of 4 Activity 1) Standard: The default mode of the system, and a new instance is generated once a jump. Suppose there is an activity named Mainactivity, which executes the statement: StartActivity (New Intent (Mainactivity.this, Mainactivity.class)), Mainactivity will jump to another mainactivity, which is now two instances of mainactivity in the task stack. Press the Back button and you'll find that it's still in mainactivity (the first one). 2) Singletop:singletop is similar to standard mode. If there is already an instanceAt the top of the activity stack, no new instances are generated, but only the newinstance () method in the activity is called. If it is not at the top of the stack, a new instance is generated. Example: When mainactivity is Singletop mode, there is still only one instance in the stack after executing the jump, if you press the return key now the program will exit directly. 3) The Singletask:singletask mode and the subsequent singleinstance mode are all created with only one instance. In this mode, the program does not generate a new instance, regardless of whether the object being jumped is the activity at the top of the stack (as long as the instance is already in the stack). This mode is very useful, in the future of multi-activity development, often because of the relationship between the jump to generate multiple instances of the same page, which is always a bit bad in the user experience, and if you declare the corresponding activity as Singletask mode, this problem will not exist. 4) SingleInstance: Activity set to SingleInstance mode will monopolize a task (sensory task can be understood as a process), and an activity that is exclusive of a task is not so much an activity as an application, This app is independent of other activity, and it has its own context activity.  55. What is intent and how to use it? Android's basic design philosophy is to encourage the reduction of coupling between components, so Android provides intent (intent), intent provides a generic messaging system that allows you to pass intent between your application and its other applications to perform actions and generate events. Use intent to activate the three core components of the Android app: active, service, and broadcast receivers. Start an activity through StartActivity () Orstartactivityforresult (), StartService () Start a service, or interact through Bindservice () and background services, by broadcasting method ( Like Sendbroadcast (), Sendorderedbroadcast (), Sendstickybroadcast ()) What is the database for broadcast receivers 56.android? What is the difference between it and SQL? Why do you use Contentprovide? What is the difference between it and the implementation of SQL? Adnroid is using the SQLite database. It is similar to other network databases and is also via the sqL Manage the data. The operation of SQLite is very simple, including data types that can be not specified when building a table. Using ContentProvider, you can share data with other apps so that apps other than this app can access the app's data. Its bottom layer is implemented with the SQLite database, so its various operations on the data are implemented in SQL, but the upper layer is provided with a URI.  57. What are the methods for passing some binary data through intent? 1) serialization using the Serializable interface, which is a common method of Java. 2) Implement the Parcelable interface, where some classes of Android such as the bitmap class have been implemented, while parcelable in the Android Aidl Exchange data is also very common.   58. How to save the operation of some resources and state, preferably in which function of the life cycle? Onresume () recovers data, OnPause () saves data.  59. How to quit all open activity once to write an activity as a portal, when you need to close the program, you can use the activity's Singletop mode to jump to the activity, All the activity on it will be destroyed. The activity is then closed. Or jump again, set Intent.setflags (Intent.flag_activity_clear_top), which can also destroy the ACTIVITY above.  60. Tell me about the service life cycle? There are two ways to start a service, each with a different life cycle. First, through the StartService start Service:oncreate, Onstartcommand, Ondestory. Second, through Bindservice binding service:oncreate, Onbind, Onunbind, Ondestory.  61. What is Aidl? How does the aidl work? Aidl (Android Interface Description Language) is an interface description language; The compiler can generate a piece of code through the Aidl file, which achieves the purpose of two process internal communication processes through a pre-defined interface. If you need to access an object in another service in one activity, you need to first turn the object into a aidl-recognizable parameter (possibly multiple parameters), then use Aidl to pass these parameters, and at the receiving end of the message, use these parameters to assemble the objects that you need. Aidl is interface-based, but it is lightweight. It uses proxy classes on the client and the realTransfer values between layers:  62.android How to store the files on the sdcard? The permissions to add access to SDcard in Androidmanifest.xml are as follows: <!– Create and delete file permissions in SDcard –><uses-permission android:name= " Android.permission.MOUNT_UNMOUNT_FILESYSTEMS "/><!– to sdcard Write Data permission –><uses-permission android:name=" Android.permission.WRITE_EXTERNAL_STORAGE "/> to SDcard to store files, the program must first determine whether the phone is equipped with sdcard, and can read and write. Note: Access SDcard must have permission to access SDcard in Androidmanifest.xml. The Environment.getexternalstoragestate () method is used to get the state of the sdcard, and if the phone is loaded with sdcard and can read and write, the method returns a state equal to Environment.media_ Mounted. The Environment.getexternalstoragedirectory () method is used to get the SDcard directory.  63. There are several ways to register a broadcast, what are the pros and cons of these methods? Two kinds. One is through code registration, which registers a broadcast that follows the program's life cycle. Two are configured in Androidmanifest.xml broadcast, this kind of resident broadcast when the application is closed, if there is information broadcast, the program will be automatically run by the system call.  64. What is the ANR how to avoid it?  on Android, if your application has been unresponsive for a while, the system will show the User a dialog box called the application is unresponsive (anr:application not Responding) dialog box. Users can choose to keep the program running, but they do not want to process the dialog box every time they use your application. Therefore, it is important to design the response performance in the program so that the system does not show the ANR to the user. To avoid it, you should try to do less time-consuming operations on the main thread, and you should put these actions in the thread.  65.android The API itself does not declare that it throws an exception, is it possible to throw runtime exceptions at run time, have you ever encountered a problem?How to resolve?  possible, such as null pointer exception, array of table out of bounds and other exceptions, these exceptions can cause the program FC. When you write code, you should do a good job of testing, consider situations where errors may occur, and resolve these issues from the code hierarchy.  66. Why use ContentProvider? How does it differ from the implementation of SQL? Using ContentProvider, you can share data with other apps so that apps other than the app can access the app's data. Its bottom layer is implemented with the SQLite database, so its various operations on the data are implemented in SQL, but the upper layer is provided with a URI.  67. What is the difference between Padding and Margin in the UI? Padding refers to the padding, which represents the distance from the component's inner element within the component's bounding rectangle. Marin refers to the margin, which represents the distance between the component and the component.  68. Please describe how to store your Android data. Android provides 5 ways to store data: 1) Use Sharedpreferences to store data, 2) file storage data, 3) SQLite database to store data, 4) to store data using ContentProvider, 5) networked storage data; 

Android face questions and answers

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.