Interview questions collated have experience in their own language

Source: Internet
Author: User
Tags sorts java web redis cluster

4. What about your understanding of the JVM?

A: a very important feature of the Java language is its independence from the platform . The use of Java virtual machines is the key to achieving this feature. The Java compiler generates code or bytecode files that the JVM can understand as long as it is oriented to the JVM. The Java source file is compiled into a bytecode program that translates each instruction into a different platform machine code through the JVM, running through a specific platform.

The process by which the JVM executes the program: I. Load. class file, II. Managing and allocating memory, Iii. performing garbage collection

JRE (Java Runtime Environment) the running environment of Java programs constructed by the JVM

1, the principle of SPRINGMVC and how to render the return data to jsp/html?

A: The core of Spring MVC is dispatcherservlet, a request passed through Dispatcherservlet, forwarded to handlermapping, then reflected, corresponding The @requestmapping address of the controller and the methods inside it, and the final return to the corresponding view via Modelandview and Viewresoler

2. How do I let the caller know when a Class object property has changed?

A: Java event time monitoring, which is triggered when the Set method changes properties, this mode can also be understood as the observer pattern, specific view: Observer pattern simple case and description


IO NIO
Stream-oriented buffering
Blocking IO non-blocking IO
No selector

The difference between Java NiO and IO

Stream-oriented and buffer-oriented

The first major difference between Java NiO and Io is that IO is stream-oriented and NIO is buffer-oriented. The Java io-oriented stream means that one or more bytes are read from the stream every time, until all bytes are read, and they are not being slowed anywhere. In addition, it cannot move data in the stream back and forth. If you need to move the data read from the stream before and after it, you need to cache it to a buffer first. Java NiO has a slightly different buffer-oriented approach. The data is read to a buffer that it processes later, and can be moved back and forth in the buffer if needed. This increases the flexibility of the process. However, you also need to check if the buffer contains all the data that you need to process. Also, make sure that when more data is read into the buffer, do not overwrite the data that has not been processed in the buffer.

Red-black tree, two-pronged tree

26066409

How the Index Works

Why do I need an index (why it needed)?

When the data is stored on a disk class storage medium, it is stored as a block of data. These data blocks are accessed as a whole, which guarantees the atomicity of the operation. Hard disk block storage structures are similar to linked lists, contain data parts, and a pointer to the next node (or block of data), and do not require continuous storage.

A recordset can only be sorted on a key field, so if you need to search on an unordered field, you should perform a linear search (Linear search), with an average access to the N/2 data block, and N is the number of blocks of data that the table occupies. If this field is a non-primary key field (that is, does not contain a unique access entry), then you need to search for the entire table space on n blocks of data.

But for an ordered field, you can use binary search, which accesses log2 (N) data blocks. This is why performance can be improved in nature.

What are indexes (what is indexing)?

An index is a way to sort multiple fields of a recordset. Creating an index for a field in a table creates another data structure that contains the value of the field and a pointer to the related record, and then sorts the index structure to allow the binary ordering of the data.

The side effect is that the index requires additional disk space, and for the MyISAM engine, these indexes are uniformly stored in a single table, which will quickly reach the size limits that the underlying filesystem can support, if many fields are indexed.

How indexing works (How does it work?)

First, we set up a model database table:

Field name data type size
ID (Primary key) Unsigned INT 4 bytes
FirstName Char (bytes)
LastName Char (bytes)
EmailAddress Char (+)-bytes
Note: Char is used in order to specify an accurate disk consumption size. This model database contains 5 million rows and has no indexes. We will analyze the performance of some query statements, one is to use the primary key ID (ordered) query, and one is to use FirstName (non-critical unordered field).

Example 1

Our model database has r=5,000,000 records, each record length r=204 bytes and uses MyISAM engine storage (the default chunk size is b=1024 bytes), the table block factor (blocking factor) will be BFR = (B/R) = 1024/ 204 = 5 records per disk data block. The disk block required to save this table is n = (r/bfr) = 5000000/5 = 1,000,000 blocks.

The linear search on the ID field averages the need for N/2 = 500,000 block access to find a record assuming the ID field is a query key value, but since the ID field is ordered, you can execute a binary query so that the average only needs to access log2 (1000000) = 19.93 = 20 blocks of data. We immediately saw a great improvement.

Now that the FirstName field is neither ordered nor performs a binary search nor is the value unique, the lookup for this table must go to the last record, that is, full table scan n = 1,000,000 blocks of data access. This is where the index is used to improve.

If the index record contains only one index column and one pointer to the original record data, it is obviously smaller than the original record (multiple columns). So the index itself requires fewer disk blocks and fewer scans. The FirstName Index table structure is as follows:

Field name Data type Size on disk
FirstName Char (bytes)
(Record pointer) Special 4 bytes
Note: MySQL pointers may be 2, 3, 4, or 5 bytes apart, depending on the size of the table.

Example 2

Suppose our database has R = 5,000,000 Records, a long R = 54 Byte index is established, and a default disk block size of 1,024 bytes is used. Then the block factor for the index is BFR = (B/R) = 1024/54 = 18 records per disk block. The total disk block required to accommodate this index table is n = (r/bfr) = 5000000/18 = 277,778 blocks.

You can now use the FirstName field to search to improve performance by using indexes. This allows the use of a binary lookup, averaging log2 (277778) = 18.08-19 data block access. Find the address of the actual record, which requires further block reads, so that the total is 19 + 1 = 20 block access, which is a vastly different number of data block accesses to the stoplist.

When to use the index (when should it is used?)

Given that additional disk space is required to create an index (the above example requires an additional 277,778 disk blocks), and that too many indexes cause problems with file system size limitations, it is critical to consider which fields to index and when to use the index.

Since indexes are only used to speed up data queries, it is clear that indexing a field that is only used for output wastes disk space and processing time when an INSERT or delete operation occurs, so this situation should be avoided as much as possible. In addition, given the characteristics of binary search, the cardinality or independence of the data is important. Indexing on a field with a base of 2 will split the data by half, and a base of 1000 will return approximately 1000 records. The low-cardinality binary lookup efficiency is reduced to a linear sort, and the query optimizer might avoid using indexes to query the original table directly if the cardinality is less than a certain scale of records, such as 30%, so the index in this case wastes space.

Stream-oriented and buffer-oriented

The first major difference between Java NiO and Io is that IO is stream-oriented and NIO is buffer-oriented. The Java io-oriented stream means that one or more bytes are read from the stream every time, until all bytes are read, and they are not being slowed anywhere. In addition, it cannot move data in the stream back and forth. If you need to move the data read from the stream before and after it, you need to cache it to a buffer first. Java NiO has a slightly different buffer-oriented approach. The data is read to a buffer that it processes later, and can be moved back and forth in the buffer if needed. This increases the flexibility of the process. However, you also need to check if the buffer contains all the data that you need to process. Also, make sure that when more data is read into the buffer, do not overwrite the data that has not been processed in the buffer.

Red-black tree, two-pronged tree

26066409

How the Index Works

Why do I need an index (why it needed)?

When the data is stored on a disk class storage medium, it is stored as a block of data. These data blocks are accessed as a whole, which guarantees the atomicity of the operation. Hard disk block storage structures are similar to linked lists, contain data parts, and a pointer to the next node (or block of data), and do not require continuous storage.

A recordset can only be sorted on a key field, so if you need to search on an unordered field, you should perform a linear search (Linear search), with an average access to the N/2 data block, and N is the number of blocks of data that the table occupies. If this field is a non-primary key field (that is, does not contain a unique access entry), then you need to search for the entire table space on n blocks of data.

But for an ordered field, you can use binary search, which accesses log2 (N) data blocks. This is why performance can be improved in nature.

What are indexes (what is indexing)?

An index is a way to sort multiple fields of a recordset. Creating an index for a field in a table creates another data structure that contains the value of the field and a pointer to the related record, and then sorts the index structure to allow the binary ordering of the data.

The side effect is that the index requires additional disk space, and for the MyISAM engine, these indexes are uniformly stored in a single table, which will quickly reach the size limits that the underlying filesystem can support, if many fields are indexed.

How indexing works (How does it work?)

First, we set up a model database table:

Field name data type size
ID (Primary key) Unsigned INT 4 bytes
FirstName Char (bytes)
LastName Char (bytes)
EmailAddress Char (+)-bytes
Note: Char is used in order to specify an accurate disk consumption size. This model database contains 5 million rows and has no indexes. We will analyze the performance of some query statements, one is to use the primary key ID (ordered) query, and one is to use FirstName (non-critical unordered field).

Example 1

Our model database has r=5,000,000 records, each record length r=204 bytes and uses MyISAM engine storage (the default chunk size is b=1024 bytes), the table block factor (blocking factor) will be BFR = (B/R) = 1024/ 204 = 5 records per disk data block. The disk block required to save this table is n = (r/bfr) = 5000000/5 = 1,000,000 blocks.

The linear search on the ID field averages the need for N/2 = 500,000 block access to find a record assuming the ID field is a query key value, but since the ID field is ordered, you can execute a binary query so that the average only needs to access log2 (1000000) = 19.93 = 20 blocks of data. We immediately saw a great improvement.

Now that the FirstName field is neither ordered nor performs a binary search nor is the value unique, the lookup for this table must go to the last record, that is, full table scan n = 1,000,000 blocks of data access. This is where the index is used to improve.

If the index record contains only one index column and one pointer to the original record data, it is obviously smaller than the original record (multiple columns). So the index itself requires fewer disk blocks and fewer scans. The FirstName Index table structure is as follows:

Field name Data type Size on disk
FirstName Char (bytes)
(Record pointer) Special 4 bytes
Note: MySQL pointers may be 2, 3, 4, or 5 bytes apart, depending on the size of the table.

Example 2

Suppose our database has R = 5,000,000 Records, a long R = 54 Byte index is established, and a default disk block size of 1,024 bytes is used. Then the block factor for the index is BFR = (B/R) = 1024/54 = 18 records per disk block. The total disk block required to accommodate this index table is n = (r/bfr) = 5000000/18 = 277,778 blocks.

You can now use the FirstName field to search to improve performance by using indexes. This allows the use of a binary lookup, averaging log2 (277778) = 18.08-19 data block access. Find the address of the actual record, which requires further block reads, so that the total is 19 + 1 = 20 block access, which is a vastly different number of data block accesses to the stoplist.

When to use the index (when should it is used?)

Given that additional disk space is required to create an index (the above example requires an additional 277,778 disk blocks), and that too many indexes cause problems with file system size limitations, it is critical to consider which fields to index and when to use the index.

Since indexes are only used to speed up data queries, it is clear that indexing a field that is only used for output wastes disk space and processing time when an INSERT or delete operation occurs, so this situation should be avoided as much as possible. In addition, given the characteristics of binary search, the cardinality or independence of the data is important. Indexing on a field with a base of 2 will split the data by half, and a base of 1000 will return approximately 1000 records. The low-cardinality binary lookup efficiency is reduced to a linear sort, and the query optimizer might avoid using indexes to query the original table directly if the cardinality is less than a certain scale of records, such as 30%, so the index in this case wastes space.

Java serialization mechanisms and principles important role of Serialversionuid value           Based on the above analysis, it can be found that if a class can be serialized, Serialversionuid suggests a definite value, not automatically generated by the system, otherwise, if the field type and length cannot be modified, the deserialization will fail if the different versions of the classes on both sides of the class.3. Why should I use cache in the project? How do I understand Nginx + tomcat + redis cluster cache?
Answer 1: The most direct performance is to reduce the pressure on the database. Avoid the possibility of a program outage due to frequent or oversized data reads that affect database performance
2:nginx often do static content services and proxy servers, facing the external request forwarded to the back of the application services. Nginx itself can also do cache, such as static page cache what. Tomcat is an application server that handles Java Web program functionality and so on. You can also understand that, assuming the user's request as a river, then Nginx is equivalent to a water conservancy project, Tomcat is equivalent to a diversion of tributaries, and Redis is equivalent to a single reservoir next to a branch. When you flood, Nginx distributes different amounts of water according to the strength of each tributary, distributing it to each tributary (Tomcat) in a way that ensures the program is running normally. And the Redis equivalent of a tributary of the reservoir, storage water, reduce pressure, so that the back of the water smooth.

Talk about your understanding of distribution.

A: Personal understanding: Distributed is to split a system/business into multiple subsystems/sub-business to work together, this process is called distributed,

Redis implements Message Queuing to be lighter than activemq

51246449

Java Combat Development Experience Podcast sharing question and answer form

https://ask.csdn.net/subjects/16?page=11

JVM and JC

When it comes to GC, remember two points: 1, GC is responsible for reclaiming all memory spaces without any reference objects. Note: Garbage collection is collected without any reference to the object occupied by the memory space instead of the object itself, 2, GC recovery mechanism of two algorithms, a, reference counting method B, the Accessibility analysis algorithm (here the accessibility, you can see the basic 2 Java object What period), as for more detailed GC algorithm introduction, we can

4. When a and B fields in a data table are indexed together, will there be an index effect by using a alone or using B alone? (How to use a like query for indexed effects)

A: Look at a, B two fields do the combination index, who in front, who in the back, if a in front, then use a alone will have an index effect, using B alone is not, and vice versa. Similarly, when using a like fuzzy query, if you use only the previous%, then there is an index effect, if you use a double% number match, then no index effect

Some methods of the object class

Protected Object   Clone () creates and returns a copy of this object.   
Boolean equals (Object obj) indicates whether an other object is "equal" to this object.
protected void Finalize () This method is called by the object's garbage collector when the garbage collector determines that there are no more references to the object.
Class<?> GetClass () returns the run-time class for this Object.
int hashcode () returns the hash code value of the object.
void Notify () wakes a single thread waiting on this object monitor.
void Notifyall () wakes all the threads waiting on this object monitor.
String toString () returns the string representation of the object.
void Wait () causes the current thread to wait before another thread calls this object's notify () method or the Notifyall () method.
void Wait (long timeout) causes the current thread to wait before another thread calls this object's notify () method or the Notifyall () method, or exceeds the specified amount of time.
void Wait (long timeout, int nanos) causes the current thread to wait while another thread calls this object's notify () method or the Notifyall () method, or some other thread interrupts the current thread, or has exceeded an actual amount of time.


5, a SQL execution too long time, how do you optimize, from what?

A: 1, to see whether SQL involves multiple tables or subqueries, if any, to see if the business can be split, related fields redundant or merged into a temporary table (Business and algorithm optimization)
2, related to the list of queries, whether it can be divided into table query, the results of a single table query after the field integration
3, if the above two can not operate, not to list query, then consider the corresponding query conditions to do the index. Speed up queries
4, for a large number of tables for the separation of historical tables (such as the trade table)
5, the database master-slave separation, read and write separation, reduce reading and writing for the same table pressure, as for master-slave synchronization, MySQL has its own binlog to achieve master-slave synchronization

6, explain analysis SQL statement, view execution plan, analyze index is used, analyze scan line number, etc.

7. Check the MySQL execution log to see if there are any other issues

Personal understanding: Fundamentally, the query is slow to occupy more than MySQL memory, then you can consider this aspect of the hand

What is the use of design patterns?

Personal views

As a loyal fan and promoter of design pattern, before formally learning the design pattern, I combined with many years of pattern application and education training experience to share some personal views with you for reference:

(1) Mastering the design pattern is not a difficult thing, the key is to think more, more practice, do not hear people say that understand a few design patterns is very "cow", as long as the intention to learn, design mode is so, you can also very "cow", must have confidence.

(2) At least the following points should be mastered in learning each design pattern: what is the intent of this design pattern, what is it to solve a problem, when it can be used, how it is solved, how to master its structure, to remember its key code, to think of at least two instances of its application, a life, In a software, what are the pros and cons of this pattern, and what to pay attention to when using it. When you can answer all the above questions, congratulations, you understand a design pattern, as for mastering it, it is in development to use it, with more than you naturally mastered.

(3) "If you want to experience the feeling of using patterns, then the best way is to use them." As stated at the beginning of this chapter, the design pattern is "internal strength Heart", it is to be combined with "practical moves" to be able to complement each other. The purpose of learning design patterns is to apply, if you do not know how to use a design pattern, but just learned, can say its purpose, draw its structure, at best, you can only say that you understand this mode, strictly speaking: not in the development of flexible use of a pattern is basically equal to not learn. So be sure to do it: say less and do more.

(4) Do not abuse the pattern, do not try to use all the patterns in a system, perhaps there is such a system, but at least I have not encountered at present. Each pattern has its own scenario and cannot be used in order to use patterns? "How to understand, we think," the abuse pattern is not as good as the pattern, because the result of abuse is not the same as the "artwork" software, it is likely to be a bunch of junk code.

(5) If the design pattern is likened to "36", then each model is a strategy, it to solve a certain type of problem, regardless of the difficulty of the design mode, the use of high frequency, I suggest that everyone should learn to learn, learn a model also means that you have more "one count", Maybe when you accidentally use it,. Therefore, the mode of learning on the road to be afraid of difficulties, the courage to challenge, some patterns although difficult, but repeatedly pondering, repeated study, should still be able to conquer.

(6) design mode of "Superior" state: "The hands of no mode, the heart has a pattern." The highest level of use of the pattern is that you do not know the definition and structure of a specific design pattern, but you will be flexible to choose a design scheme "is actually a design pattern" to solve a problem, design patterns have become a part of your development skills, can extremely easy, "internal strength" and "moves" has been seamless, To achieve this level is not to read a book or develop one or two projects can be achieved, it needs to constantly precipitation and accumulation, so, the mode of learning not to be anxious.

(7) The last point comes from Gof's late member, one of my most revered and admired software engineering gurus, John Vlissides's book, "The Contemplation of Design patterns" (Pattern hatching design Patterns applied): Patterns never guarantee anything, It does not guarantee that you will be able to make reusable software, improve your productivity, and not guarantee world peace. Patterns do not replace people with the creation of software systems, they only give hope to those who are inexperienced but talented and creative.

Interview questions collated have experience in their own language

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.