Android/Java interview questions-you may not understand it!

Source: Internet
Author: User
Tags float double

1. What is acitsag startup mode?

For such a question, I will write an example myself. I will observe it to understand it.

Activty supports four startup modes. Launchmode:

Standard: each time a new activity window is started (New Operation)

Singletop: if it is a target activity at the top of the stack, It will be opened directly. Otherwise, a new activity window (new) will be opened ).

Singletask and singleinstance are basically the same. The difference is that if the root activity is set to singletask, the enabled activity is also in the same task, that is, the taskid is the same .. If the root activity is set to singleinstance, the activated activity is in the new task, that is, there is only one activity in the stack, and the taskid is different .. The rest is the same.
 
Java interview questions

1.
Is string the most basic data type?
Basic data types include byte, Int, Char, long, float, double, Boolean, and short.
Java. Lang. string class is of the final type. Therefore, it cannot be inherited or modified. To improve efficiency and save space, we should use the stringbuffer class. We can also answer this question from the memory perspective. 2.
INT and integer
What is the difference? 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. Boolean, encapsulation class of the original type
Char character bytebyte short int integer long float double
The behavior of the reference type and the original type is 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. 3.
Difference between string and stringbuffer Java platform provides two classes: string and stringbuffer, which can store and operate strings, that is, character data containing multiple characters. This string class provides a string whose values cannot be changed. The stringbuffer class provides strings for modification. You can use stringbuffer when you know that character data is changing. Typically, you can use stringbuffers to dynamically construct character data. 4. What are the similarities and differences between runtime exceptions and general exceptions? 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. 5. the storage performance and features of arraylist, vector, and shortlist are both stored in arrays. The number of elements in this array is greater than that in actual storage to add and insert elements, both of them Allow Indexing elements by serial number directly, but inserting elements involves memory operations such as array element movement, so index data is fast and data insertion is slow. Vector uses the Synchronized Method (thread-safe ), generally, the performance is inferior to that of arraylist, while the sorted list uses a two-way linked list for storage. Data indexed by serial numbers needs to be traversed in the forward or backward directions, however, when inserting data, you only need to record the items before and after this item, so the insertion speed is fast. 6.
The difference between collection and collections. Collection is the upper-level interface of the Collection class. Its Inheritance and its interfaces mainly include set
And list. collections are a help class for the Collection class. It provides a series of static methods for searching, sorting, thread security, and other operations on various sets. 7.
. & Is a bitwise operator that represents bitwise and operation, & is a logical operator that represents logic and (and ). 8.
The difference between hashmap and hashtable. Hashmap is a lightweight Implementation of hashtable (non-thread-safe implementation). They all complete the map interface. The main difference is that hashmap allows null key values ), because of non-thread security, the efficiency may be higher than that of hashtable.
Hashmap allows null as the key or value of an entry, whereas hashtable does not.
Hashmap removes the contains method of hashtable and changes it to containsvalue and containskey. The contains method is easy to misunderstand. Hashtable inherits from the dictionary class, while hashmap is the map introduced by java1.2.
Interface. The biggest difference is that the hashtable method is synchronize, but hashmap is not. When multiple threads access hashtable, they do not need to implement synchronization for their own methods, while hashmap
You must provide external synchronization for it. The hash/rehash algorithms used by hashtable and hashmap are roughly the same, so there is no big difference in performance. 9.
Differences between final, finally, and finalize. Final
It is used to declare attributes, methods, and classes, indicating that the 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. 10. Sleep ()
What is the difference with wait? Sleep is a thread method, which causes the thread to suspend the execution for a specified time and give the execution opportunity to other threads. However, the monitoring status remains unchanged and will be automatically restored after the time. Calling sleep does not release the object lock. Wait is an object-class method. Calling the wait method for this object causes this thread to discard the object lock and enter the waiting lock pool for this object. Only the notify method (or notifyall) is issued for this object) then this thread enters the object lock pool and prepares to get the object lock and enters the running state. 11. Differences between overload and override. Can the overloaded method change the type of the returned value?
Overriding and overloading are different manifestations of Java polymorphism. Overriding is a manifestation of the polymorphism between the parent class and the Child class, and overloading is a manifestation of the polymorphism in a class. If a subclass defines a method with the same name and parameter as its parent class, we say this method is overwritten.
(Overriding ). When a subclass object uses this method, it calls the definition in the subclass. For it, the definition in the parent class is "blocked. If multiple methods with the same name are defined in a class, they may have different numbers of parameters or different parameter types, it is called overloading ). The overloaded method can change the type of the returned value. 12. What is the difference between error and exception? Error
Indicates that recovery is not a serious problem that is not impossible but difficult. For example, memory overflow. It is impossible to expect the program to handle such a situation. Exception
Indicates a design or implementation problem. That is to say, it indicates that if the program runs normally, it will never happen. 13. What are the similarities and differences between synchronization and Asynchronization? 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. 14. What is the difference between abstract class and interface? The class that declares the existence of a method rather than implementing it is called an abstract class (Abstract
Class), which is used to create a class that reflects certain basic behaviors and declare methods for this class, but cannot implement this class in this class. Abstract cannot be created
Class. However, you can create a variable whose type is an abstract class and point it to an instance of a specific subclass. Abstract constructors or abstract static methods are not allowed. Abstract
Class subclasses provide implementation for all abstract methods in their parent class, otherwise they are also abstract classes. Instead, implement this method in the subclass. Other classes that know their behavior can implement these methods in the class. An interface is a variant of an abstract class. All methods in the interface are abstract. Multi-inheritance can be achieved by implementing such an interface. All methods in the interface are abstract, and none of them have a program body. The interface can only define static final member variables. The implementation of an interface is similar to that of a subclass, except that the implementation class cannot inherit behaviors from the interface definition. When a class implements a special interface, it defines (to be given by the program body) all the methods of this interface. Then, it can call the interface method on any object that implements the interface class. Because there is an abstract class, it allows the interface name as the type of the referenced variable. Normally, dynamic Association editing will take effect. The reference can be converted to the interface type or from the interface type conversion, instanceof
The operator can be used to determine whether the class of an object implements the interface. 15. What is the difference between heap and stack. Stack is a linear set. The operations for adding and deleting elements should be completed in the same section 15. The stack is processed as follows. Heap is an element of stack. 16. Static nested class
Different from inner class. Static nested class is an internal class declared as static. It can be instantiated without relying on external class instances. In general, internal classes must be instantiated before they can be instantiated. 17. When to use assert. Assertion is a common debugging method in software development. Many development languages support this mechanism. In implementation, assertion is a statement in the program. It checks a Boolean expression. A correct program must ensure that the value of this Boolean expression is true. If this value is false, if the program is in an incorrect state, the system will give a warning or exit. Generally, assertion is used to ensure the most basic and critical correctness of the program. The assertion check is usually enabled during development and testing. To improve performance, the assertion check is usually disabled after the software is released. 18. What is GC?
Why does GC exist? GC is the meaning of garbage collection (gabage collection). Memory Processing is a place where programmers are prone to problems. Forgetting or wrong memory collection can lead to instability or even crash of programs or systems, the GC function provided by Java can automatically monitor whether the object exceeded the scope to automatically recycle the memory. the Java language does not provide a display operation to release the allocated memory. 19. short S1 = 1; S1 = S1 + 1; what is the error? Short S1 = 1; S1 + = 1; what is the error?
Short S1 = 1; S1 = S1 + 1; (S1 + 1 is an int type and requires forced conversion) Short S1 = 1; S1 + = 1; (can be compiled correctly ). 20. math. what is the value of round (11.5? Math. Round (-11.5) and so on?
Math. round (11.5) = 12 math. the round (-11.5) =-11 round method returns the nearest long integer to the parameter. After the parameter is added with 1/2, the floor.21. string S = new string ("XYZ "); how many string objects are created?
Two.

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.