Interview Summary (i)--java Basic related knowledge

Source: Internet
Author: User
Tags modifiers

Interview Summary (i)--java Basic related knowledge

Recently in the interview, so summarize the interview easy to ask the knowledge points, used for backup viewing.
If you need to reprint, please indicate the source.

1. Object-oriented features;
1. Simplifying Complex things
2. Object-oriented to turn the performer in the previous process into a leader
3. Object oriented thinking is in line with people's thinking habits
2. Object-oriented features;
1. Encapsulation: Hide the properties and implementation details of the object, only provide public access to the external
Benefits: Isolate changes, ease of use, improve reuse and security.
Principle: Hides content that does not need to be provided externally, hides properties, and provides access to public methods.
2. Inheritance: Improve code reusability, inheritance is the precondition of polymorphism. All constructors in the subclass have access to the constructor of the parent's hollow parameter by default, the first row has super (), and if there is no null argument constructor, it needs to be specified in the subclass. In addition, the constructor of a subclass can use this to access its own other constructors.
3. Polymorphic: is a reference variable defined by a parent class or interface that can point to a subclass or an instance object of a concrete implementation class.
Benefits: Improved Program extensibility
Cons: When a parent class reference points to a subclass object, it improves extensibility, but accesses only the methods that are available in the parent class, and does not access the unique methods in the subclass, the limitations of access.
Premise: Implement or inherit a relationship, and replicate the parent class method.
3. Abstract class
1. Features: Modified by the abstract, describing classes and methods, as a method of declaration, not specifically implemented. Abstract classes can have non-abstract methods, but cannot be instantiated. Subclasses inherit abstract classes, and all abstract methods must be implemented to instantiate them, otherwise the subclasses are still abstract classes.
2. Relevant knowledge points:
A. Abstract classes can have constructors that are used to initialize a subclass object, even if the constructor is not defined, and a null parameter constructor is defaulted.
B. You can define non-abstract methods, properties, and behaviors.
C. Abstract classes can have no abstract method, the purpose of abstraction is not to let the class be instantiated.
D.abstract can not coexist with final,private,static,native.
4. Inner class
1. When the inner class is defined locally, the inner class defined in the method is a local inner class.
Can not be decorated with member modifiers: public,static,private, etc. External class members can be accessed directly because there is a reference to the external class. You can only access the final modified local variables in the part that it occupies, such as Baseadapter new Onclicklistener, if you need to use position, you need to change to the final type.
2. Anonymous inner class, a shorthand way for an inner class that must inherit a class or implement an interface.
5.final Keywords
1. Classes, methods and variables can be decorated
2. The modified class cannot be inherited
3. The modified method cannot be replicated
4. Modified variable: A. The value of the basic data type is immutable; b. Reference variable---cannot be assigned, but the object pointed to can be changed.
6. Differences in inheritance and implementation
Surface difference: Single inheritance, multi-implementation.
Inheritance: If multiple classes have the same functionality, you can abstract a class and put the same parts in the parent class so that they all inherit from the class. Provides code reusability, multi-state prerequisites.
Implementation: If the target of multiple classes is the same, but handled in a different way, then define an interface, that is, a standard, let them implement this interface, each implement their own concrete methods to deal with the target.
7. The difference between abstract classes and interfaces
Abstract classes can only be inherited by a sheet, and interfaces can be implemented more than one.
Abstract classes can be defined non-abstract methods, subclasses can directly inherit the use, the interface is all abstract methods, need quilt class implementation.
An abstract class is an is a relationship, and an interface is a relationship like a.
The member modifiers of the abstract class can be customized and the interfaces are all public
Abstract classes can have construction methods, static methods, interfaces are not available.
8. The difference between overloading overload and overriding override
Overloading: A method in which the same class allows more than one of the same function names, but with a different number of arguments or types.
Features: independent of return type, see only parameter list
overriding: When a child class appears as a function of the parent class, the subclass object is called, and the function in the method is run as if the parent function were overwritten.
Overloading only looks at the argument list of a function of the same name, which is said for two functions in a class. Overriding is a function of the same name as the parent class, and is a two class.
the difference between 9.StringBuilder and StringBuffer
StringBuffer are thread-synchronized and are typically used for multithreading. StringBuilder are threads that are not synchronized and are typically used for single-threaded.
10. Abnormal exception
1. Exception handling principle: can be processed to capture, throw a few exceptions to capture a few, catch exception to be specific, can not handle the new exception thrown.
2. When multiple catch blocks are included, the parent exception is placed under the subclass exception because the subclasses are more detailed.
3.throws,throw,try,catch,finally Meaning:
A.throws: Defined on a function, used to throw an exception. Can be thrown multiple, need to separate the comma, throw the exception the more specific the better, can be targeted to solve.
B.throw: Defined within a function, used to throw an exception object, when the throw is present alone, the statement cannot be defined below because the compilation fails.
C.try: It can be understood to detect anomalies, which put code that could produce an exception
D.catch: Catch Exception or Exception object, when an exception is thrown, it needs to be caught and processed, where it can throw an exception and throw it to the caller who can resolve it.
E.finally: A block of code that will eventually be executed, even if there is a return.
11. Multithreading
How threads are created: thread,runnable, thread pool (pool).
1. Why do I need to replicate the Run method?
Because the code in the Run method holds the thread running
What is the difference between 2.Thread and runnable creation?
Inheritance mode: Line animations is stacked in the thread subclass Run method.
Implementation: Line animations stacking in the interface subclass of the Run method, to avoid the limitations of single inheritance, it is recommended to use.
3. Thread Status:
NEW: Start
Temporary status: With CPU execution qualification, no execution right
Operational status: CPU execution, executable
Frozen state: Through sleep or wait (there are other methods, there will be interview topics later-multithreading specifically) so that the thread does not have the ability to perform, need to wake up notify, Wake up in a temporary state
Extinction state: The end of the Run method or the thread that causes the threads to die.
4. Thread Safety:
Multiple threads share data, and when a thread executes multiple statements, other threads also execute, causing the data to be modified more than once on a single statement, resulting in incorrect data when the subsequent code executes.
Factor: Multiple threads manipulating shared data
Solve:
Rationale: Only one thread is allowed to perform all operations on shared data at a certain time.
Method: Lock mechanism->synchronized or lock object
5. Thread Synchronization
When two or more two threads need to share resources, they need some way to determine that the resource is occupied by only one thread at a time, and that the process to achieve this is called synchronization.
Sync code block: Synchronized (object) {}; Put in curly braces that need to be synchronized, the object in parentheses is the lock.
Synchronization function: Synchronized is placed on the function, after the modifier, before the return type. The lock of the synchronization function is this, and the lock of the static synchronization function is a class object, such as a lazy synchronous lock of Single.class.
The difference between 6.wait and sleep
Wait: The wait time can be specified, and if not specified, it needs to be awakened by Notify/notifyall. Waits for the thread to release execution and release the lock.
Sleep: The wait time must be specified, the time will be automatically in a temporary (blocking) state, during sleep still hold the lock, do not release the execution rights.
Wait can only be used in synchronization, and sleep can be anywhere (method of object).
12. Collection
Collection
| |–arraylist
|--list-|
| |–linkedlist
|
| |-treeset
|--set-|
|-hashset
Map
|
|--hashmap
|
|--treemap

1.Collection:
List: Ordered, elements repeatable, indexed.
ArrayList: The bottom is the array structure, Find Fast, delete and subtract slow, out of sync.
LinkedList: The bottom is the list structure, adding and deleting fast, find slow, out of sync.
Vector: The bottom is the array structure, thread synchronization, replaced by ArrayList.
Set: Unordered, no index, element not repeatable
HashSet: The bottom is a hash table, threads are out of sync, unordered, funny.
TreeSet: The underlying is a two-fork tree, which allows you to sort the elements, by default the natural order.
2.Map:
HashTable: The underlying is a hash table, thread synchronization, cannot be stored in NULL keys and null values.
HashMap: The underlying is a hash table that allows null keys and null values, is not synchronized, is high efficiency
TreeMap: The underlying is a two-fork tree, is unsynchronized, sortable, and is similar to set. The set bottom uses the Map collection.
3.Collection and map differences
Collection: A single-column collection that saves one element at a time.
Map: A two-column collection that has a pair of elements at a time and a mapping relationship between two elements.
13. Regular Expressions
Overview: Regular expressions are some of the specifications used to manipulate strings, which can be used to simplify the basic operation of strings by using symbols to represent specific code.
Match: Matches (string Regex)
cut in String class: String split
Replace: string ReplaceAll
Get:
Encapsulate Regular Expression as object: Pattern p = Pa Ttern.compile (regex);
Associative string gets the match: Matcher m = p.mathcer (str); The
is obtained using the Matcher method: Find (); Group ();
14.XML parsing
Dom and sax parsing are all read into memory after parsing, Dom suitable additions and deletions, sax suitable to find. If the XML file is large, it is easy to cause memory overflow
Pull parsing is edge edge resolution. Storage of variables in
15.Java
Instance variables and static variables on the heap, local variables on the stack

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Interview Summary (i)--java Basic related knowledge

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.