Top 200 pages of Baidu Java interview questions (Part 2)
Baidu "Java interview questions" top 200 pages selection part 2
Design pattern
What are design patterns? What design patterns have you used? Where do you use them? What commercial design patterns do you know? Which design patterns can increase the scalability of the system
Singleton mode
Besides the singleton pattern, what other design patterns have you used in your production environment? Write singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton singleton
Adapter mode
When to use the meta mode, when to use the composite mode, when to use the visitor mode, and what is the template method mode? Please give an example of a design mode that conforms to the opening and closing principle
Open questions
Summarize the characteristics of web programming in one sentence. How does Google return search results to users in one second? What dependency injection method do you suggest? Constructor injection, Or setter method injection tree (binary or other) forms the basis of many common data structures. Please describe some such data structures and when they can be used. How to design an online system suddenly becomes extremely slow, how to find problems, what kind of project is not suitable for using the framework, how to push the microblog to the subscriber, and briefly introduce how to enter the URL from the browser After getting the request interface, what happened in the Java Web application? Please talk about the high integration and distribution of SSH, how to safely modify the same line of data, how to realize the booking system of 12306 website, how to ensure that tickets will not be oversold, how to optimize the performance of the website, and how to optimize the server architecture you once participated in the design. Please think about a scheme, To realize countdownlatch in a distributed environment, please consider a scheme to design an automatic adaptive local cache that can control the overall size of the cache. What is the most difficult technical challenge in your career? How to write a design document, what is the directory, and what is the o? For example, how do you consider some design principles in programming, such as opening and closing principles and their application in work? Explain the mode and characteristics of network application, and design an online document system, which can be edited, How to prevent multiple people from editing and updating the same document at the same time? What is the working mechanism of data connection pool? How to obtain the highest frequency of words in a file? Describe your most commonly used programming style. If you have the opportunity to redesign your product, What would you do? How to build a highly available system? How to start without entering a user name and password? How to upload and download files in Java based web projects? How to implement a second kill system to ensure that only a few users can buy a commodity. How to achieve load balancing, what algorithms can be implemented, and how to design a shopping cart? Think about how Taobao's shopping cart is implemented, how to design a high concurrency payment scheme, how to design the architecture, how to establish and maintain a long connection of 100W, and how to avoid browser caching. How to prevent cache avalanche? If AB and ab systems depend on each other, how to remove them? If someone maliciously creates an illegal connection, how to solve it? If there are billions of white lists, high concurrency queries are required every day and updates are required at night, How to design this function? If the system wants to use super large integers (exceeding the length range of long), please design a data structure to store such super large numbers and an algorithm to realize super large integer addition). If you want to design a graphics system, please design basic graphics components (point, line, rectangle, triangle) If you were to implement a concurrent and secure linked list, what would you do to distinguish between an application server and a web server? How does the application server monitor performance and the differences between various methods? What are the application server optimization technologies you have used? What problems should be considered in the architecture of large websites? Have you dealt with online problems? Memory leakage, CPU utilization level, how to deal with applications when they are not responding. What books have you read recently, what impressed you most? Describe the common refactoring skills, and what version management tools do you use? What is the difference between a branch and a tag? Do you know what anti patterns exist? What are the technologies you have used for website front-end optimization? How do you analyze thread dump? How do you understand joinpoint, pointcut, advice, introduction, weaving and faceting in AOP (aspect) how do you deal with memory leakage or stack overflow? What are the JVM parameters of your online application and how do you improve the QPS and throughput of the system
width of knowledge
Explain what is the MESI protocol (cache consistency). Talk about the reactor model, what new functions Java 9 brings, the comparison between Java and C + +, the simple principle and application of exception handling mechanism in C + + or Java, and briefly talk about the Tomcat structure, And what is the class loader process and virtual memory? Please briefly describe your understanding of Test Driven Development (TDD). What is the difference between Maven and ant? What are the commonly used diagrams in UML
Linux
What is the N + 1 problem, what is the Paxos algorithm, what is restful, what is the Zab protocol and what is the domain model? What is the difference between the anemia domain model and the rich domain model? What is domain driven development? Let's introduce the web service framework in the Java field. What are the differences between web server, web container and application server? Microservices and boulder applications What are the differences between (monolithic applications)? Describe the roles, differences and respective application ranges of cookies and sessions, the working principle of session. What are your common continuous integration and static code analysis tools? Briefly describe database regularization (normalization) what are the principles of kiss, dry and YAGNI? The principles, advantages and disadvantages of distributed transactions, how to use distributed transactions, and how to achieve a unique serial number in a distributed cluster
network
Have you seen some code persistence layer design of the framework? What are the problems to be considered? What are the numerical improvements of the persistence layer framework you have used? Can you explain the Richter replacement principle? How do you test an application? What test frameworks do you know? What are the common programming protocols for the transport layer? And say their characteristics
Programming problem
Calculate overtime pay
Overtime for less than 10 hours is 1.5 times the hourly salary. Overtime of 10 hours or more is calculated as 4 yuan / hour. Tips: (26 days a month, 8 hours a day)
Calculate 1000 monthly salary, 2500 monthly salary for 9 hours of overtime, 1000 monthly salary for 11 hours of overtime and 15 hours of overtime
Selling goods
Red apples and green apples are on sale in a shopping mall. (red apple 5 yuan / piece, green apple 4 yuan / piece).
Simulate a purchase. 200 red apples and 200 green apples each. Simulate a sale. Buy 10 red apples and 10 green apples. Statistics are required for each Apple sold.
Tip: an apple is a separate entity.
Date extraction
There is such a time string: 2008-8-8 20:08:08. Please write a regular expression that can match it and write java code to extract the hours, minutes and seconds after the date, that is, 20:08:08
thread
8 design four threads, two of which increase 1 for J each time, and the other two decrease 1 for J each time. Write a program. Write a multithreaded program in Java. For example, write four threads, two plus one, two minus one to a variable, output wait notify, and write a piece of code to solve the producer consumer problem
number
Judge how many primes are between 101 and 200, and output all primes. Use the most efficient method to calculate how many 100 million numbers are equal to 2 times 17, of which 2 are repeated. Quickly find it. The time and space should be the best 200 million randomly generated unordered integers, find the middle large and small value, and find the smallest 10 natural numbers ranging from 100 million to 100 million, Find the sum of the split numbers of all numbers. For example, 286 is split into 2, 8 and 6, for example, 1 to 11. The sum of the split numbers = > 1 +... + 9 + 1 + 0 + 1 + 1. If a number is exactly equal to the sum of its factors, This number is called the perfect number "For example, 6 = 1 + 2 + 3. Program to find all completions within 1000. All elements in an array appear three times and only one element appears once. Find this element. A ball falls freely from a height of 100 meters and jumps back to half of the original height after each landing; then fall again to find how many meters it has passed during the 10th landing? How high is the 10th rebound? Find 100-1000 Sum of endoplasmic numbers find the average of the sum of 1 to 100 and find the value of S = a + A + AAA + AAAA + AA... A, where a is a number. For example, 2 + 22 + 222 + 2222 + 22222 (at this time, a total of 5 numbers are added), and the addition of several numbers is controlled by the keyboard. Find the sum of 1 to 100
Calculate the prime number from 1 to 40 and put it in the array
There are 3N + 1 numbers, of which 3N are repeated, and only 1 is not repeated. How to find it. There is a group of 1.1 2.3. 5.8. 13.21. 34。 Write a program. You can give the first five numbers with the same law as the previous group of numbers by entering any number. Calculate the factorial development of the specified numbers. Fizz buzz gives an array containing N integers, finds out the missing integers, a well ordered array, finds out all combinations with the sum of the two numbers as m, and decomposes a positive integer into prime factors. For example, enter 90 and print out 90 = 2 * 3 * 3 * 5. Print out all the "daffodils". The so-called "daffodils" refers to a three digit number, and the sum of each digit cube is equal to the number itself. For example, 153 is a "daffodils number", because 153 = the third power of 1 + the third power of 5 + the third power of 3, exchange the values of two variables in situ, find out the median of a 4-byte integer, find the square root of the integer, and realize Fibonacci
network
Programming with java socket, read a few characters from the server, and then write them to the local display
reflex
What does the reflection mechanism provide? How is reflection implemented? Where is the reflection mechanism used What are the three ways forname and classloader differ from reflection to create class instances? How to call object methods through reflection? How to obtain and set the value of object private fields through reflection? The advantages and disadvantages of reflection mechanism
database
Write a program connecting JDBC with Oracle and realize data query
algorithm
50 people sit around for a circle. When you count to three or multiple of three, ask who the rest are and what the original position is. Implement an elevator simulator, write a bubble sort, write a half search, randomly generate 20 non repeatable characters, sort and write a function, and pass in two ordered integer arrays, Return an ordered array of integers and write a piece of code to remove an element when traversing the ArrayList. Classical problem: a pair of rabbits give birth to a pair of rabbits every month from the third month after birth, and a pair of rabbits every month after the fourth month. If the rabbits don't die, ask the total number of rabbits every month. Josephine ring game
regular
Please write a regular expression that matches the IP address. Write a regular expression to judge whether a string is a number
character string
Write a method, enter a file name and a string, and count the number of times this string appears in this file. Write a program to find out the combination of all strings and check whether they are palindrome strings. Write a string inversion function, enter ABCDE to convert it into edcba code game, reverse the words in the sentence, and convert the string encoded by GB2312 into the string encoded by iso-8859-1. Please write a code to calculate the number of characters "a" in a given text. Write a function to intercept a string in iterative and recursive ways respectively. The input is a string and the number of bytes, and the output is a string intercepted by bytes. However, to ensure that Chinese characters are not truncated by half, such as "I ABC" 4, it should be truncated as "I AB", and enter "I ABC Han def", 6, It should be output as "my ABC" instead of "half of my ABC + Chinese". Given two files containing word lists (one for each line), program to list the intersection, print out all permutations of a string, and convert the numbers entered by a keyboard into Chinese output (for example, input 1234567, output: 1.2344567) In the process of web application development, we often encounter outputting some coded characters, such as GBK to iso8859-1. How to output a coded string
date
Calculate the difference between two dates
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.