2019 senior Java interview questions summary (7), 228 series leak filled!

2019 Java interview questions senior series 228

Java interview questions (a)

1 to update the first to answer 20 questions resolved
The second update to resolve an answer 21 to 50 questions
Part III Updated 51 to answer 95 questions resolved

Java interview questions (b)

Title IV Update 1 to answer 20 questions resolved
The fifth chapter update 21 to 50 questions answer analysis
Part VI update 51 to answer 80 questions resolved


Java interview questions (b)

81, say the best practice method overloading of several Java?
82, in a multithreaded environment, SimpleDateFormat is thread safe?
83, Java How to format a date? Such as formatting in the form of ddMMyyyy?
84, Java in how time zone in the date format in?
85, Java with java.util.Date in java.sql.Date What is the difference?
86, in Java, how to calculate the difference between two dates?
87, Java, how to convert a string YYYYMMDD date?
89, how to test a static method? (answer)
90, how to use JUnit to test a method of abnormality?
91, which you have used the unit test library to test your Java program?
92, @ Before and @BeforeClass What is the difference?
93, how to check a string contains only numbers? solution
94, how to use generics in Java to write a LRU cache?
95, write a Java program to convert byte long?
96, without the use of StringBuffer, how to reverse a string?
97, Java in how to obtain the highest frequency word appears in a document?
98, how to check out the two given string to reverse order?
99, Java in, how to print out all permutations of a string?
100, in Java, how to print out the array of repeating elements?
101, Java how to convert a string to an integer?
102, How to swap the values ​​of two integer variables without the use of temporary variables?
103, what interfaces are? Why use an interface instead of using concrete classes?
What is the difference between 104, Java, the abstract classes and interfaces?
105, in addition to a singleton, you used any design patterns in a production environment?
106, can you explain the substitution principle Leeb it?
107, under what circumstances would violate the Law of Demeter? Why this question?
108, what adapter model is? When to use?
109, what is the "dependency injection" and "inversion of control"? Why would anyone use?
110, what is abstract class? It is the interface What is the difference? Why do you want to use too abstract class?
111, constructor injection and setter dependency injection, that way better?
112, what is the difference between dependency injection and engineering model?
113, the adapter mode and Decorator What is the difference?
114, what's the difference before the adapter mode and proxy mode?
115, what is the template method pattern?

This update 81 to answer 115 questions resolved

81, say the best practice method overloading of several Java?

Here are a few best practices that can be followed to avoid overloading the automatic packing of confusion.
a) Do not overload a method: a method of receiving int parameter, and another method of receiving a parameter Integer.
b) Do not overload same number of parameters, but different parameters and sequential method.
c) If the number of parameters overloaded method more than 5, with variable parameters.

82, in a multithreaded environment, SimpleDateFormat is thread safe?

No, unfortunately, all the realization DateFormat, including SimpleDateFormat is not thread-safe, so you should not be used in multi-line program, unless the external thread is used in a safe environment, such as SimpleDateFormat will be limited to a ThreadLocal. If you do not, when parsing or formatting dates, you may get an incorrect result. Therefore, from the date all practice, treatment time, I strongly recommend joda-time library.

83, Java How to format a date? Such as formatting in the form of ddMMyyyy?

Java, you can use SimpleDateFormat class or joda-time library to format dates. DateFormat class allows you to use a variety of popular formats to format dates. See the example code in the answer, the code demonstrates the date format into a different format, such as dd-MM-yyyy or ddMMyyyy.

84, Java in how time zone in the date format in?

Use SimpleDateFormat for the formatting dates, but all realize DateFormat, including SimpleDateFormat is not thread-safe, so you should not be used in multi-line program, unless the external thread is used in a safe environment, such as SimpleDateFormat will limit the ThreadLocal in. If you do not, when parsing or formatting dates, you may get an incorrect result. Therefore, all date from practice, processing time, strongly recommended joda-time library.

85, Java with java.util.Date in java.sql.Date What is the difference?

86, in Java, how to calculate the difference between two dates?

87, Java, how to convert a string YYYYMMDD date?

89, how to test a static method?

You can use PowerMock library to test a static method.

90, how to use JUnit to test a method of abnormality?

Abnormality code to be tested using a try, catch block. For example: public void testException () {try {Long.parseLong (null);} catch (NumberFormatException expected) {}} is then used Junit fail to function for the intended exception code without throwing

91, which you have used the unit test library to test your Java program?

92, @ Before and @BeforeClass What is the difference?

@Before: Before each test method is executed once, the method should be declared public
@beforeclass: only in a class once, it must be declared as public static

93, how to check a string contains only numbers? solution

It comes with the Java function, regular expression, determined by ascii code

94, how to use generics in Java to write a LRU cache?

This is a hybrid data structure, we need to build a list based on the hash table. But Java has provided this type of data structure we -LinkedHashMap! It even provides a method to cover the recovery strategy. The only thing is we need to pay attention to, change the order of the list is the order of insertion, rather than sequential access. However, there is a constructor provides an option, you can use sequential access.

95, write a Java program to convert byte long?

96, without the use of StringBuffer, how to reverse a string?

97, Java in how to obtain the highest frequency word appears in a document?

This is an algorithm interview questions, the more Chinese Java.
1, the file contents into String string.
2, using the split () function split string, as a direct replacement for space or in English, can be separated by commas, and the like Chinese, separated to obtain an array.
3, through the array of all the words, the statistical results Map, key = word, the number of value = word appears.
4, use TreeSet type, the Map of the sort the results, according to statistics the number.
5, the output of the highest ranked top N results

98, how to check out the two given string to reverse order?

The main idea is that, a further comparison and from the end of characters from the beginning characters, first determine whether the same length, different possible direct anti text. And then compare.

99, Java in, how to print out all permutations of a string?

100, in Java, how to print out the array of repeating elements?

101, Java how to convert a string to an integer?

String s="123";
int i;
The first method: i = Integer.parseInt (s);
The second method: i = Integer.valueOf (s) .intValue ();

102, How to swap the values ​​of two integer variables without the use of temporary variables?

Addition and subtraction, multiplication and division, XOR method

103, what interfaces are? Why use an interface instead of using concrete classes?

Interface defines the API. It defines the class rules have to be followed. At the same time, it provides an abstraction, because clients only use interface so you can have multiple implementation, such as the List interface, you can use a randomly accessible ArrayList, can also be used to facilitate insertion and deletion of LinkedList. The interface is not allowed to write the code, in order to assure the abstract, but in Java 8 in the interface you can declare static default method, which is concrete.

What is the difference between 104, Java, the abstract classes and interfaces?

Java, abstract classes and interfaces have many differences, but the most important one is the limit in a Java class can only inherit a class, but can implement multiple interfaces. An abstract class can define the default behavior of a good class family, and the interface to better define the type of help achieve polymorphism mechanism behind.

105, in addition to a singleton, you used any design patterns in a production environment?

This needs to answer based on your experience. In general, you can say that dependency injection, factory pattern, decorative patterns or observer mode, you can select a random used. But you should be prepared to answer based on the model of your choice to take over the problem.

106, can you explain the substitution principle Leeb it?

First, it is required compiler, if you do not do this, can not compile. Second, the object-oriented programming, which has a large inheritance principle, the object of any subclass can be used as the object of the parent class to use.

107, under what circumstances would violate the Law of Demeter? Why this question?

Demeter recommend "Only friends and talk, do not talk to strangers" in order to reduce the coupling between classes.

108, what adapter model is? When to use?

Mode conversion adapter provides the interface. If your client uses some interfaces, but you have some other interfaces, you can write an adapter to connect these interfaces.

109, what is the "dependency injection" and "inversion of control"? Why would anyone use?

Inversion of Control (IOC) is the core idea of ​​the Spring framework, with my own words, what you do one thing, do not own can be fresh new, you say you want to doing, then outsource dependency injection like ~ (DI) in my shallow mind, the reference is expressed by the interface and construction methods, some of the things a good place to turn to pass the whole need to use ~

110, what is abstract class? It is the interface What is the difference? Why do you want to use too abstract class?

a. for the interface specification for the abstract class common.
b. declare the existence of methods to achieve it without the class is called abstract class
C. Interface (interface) is a variant of the abstract class. In the interface all methods are abstract.

111, constructor injection and setter dependency injection, that way better?

Each approach has its advantages and disadvantages. Constructor injection to ensure that all injection are initialized, but setter injection to provide better flexibility to set an optional dependency. If a dependency is described using XML, Setter injection may be read will be stronger. The rule of thumb is to use a constructor dependency injection mandatory, optional dependencies using setter injection.

112, what is the difference between dependency injection and engineering model?

Although the two models are the creation of objects separate from the application logic, but dependency injection clearer than the engineering model. Via dependency injection, like you it is POJO, and not rely only know how they get care. Using the factory pattern, you need to get the dependent class through the factory. Therefore, DI will be easier to test than using the factory pattern.

113, the adapter mode and Decorator What is the difference?

While similar structures and decorative patterns adapter mode, but different intention appears each mode. Adapter mode is used for bridging two interfaces, the purpose is decorative pattern type to add new functions without modifying classes.

114, what's the difference before the adapter mode and proxy mode?

The problem with previous similar, except adapter mode and proxy modes is their intention. Since the adapter mode and a proxy mode are encapsulated operation performed real class, the structure is the same, but the adapter mode for switching between interfaces, while the proxy model is adding an additional middle layer, in order to support the distribution, control or smart access.

115, what is the template method pattern?

Template approach to provide a framework algorithm, you can go to configure or define the steps. For example, you can sort algorithm seen as a template. It defines the step of ordering, but specific comparisons, can use their language Comparable or something similar, you will have to configure specific strategies. Summary of the methods listed algorithm is known as the template method.

At last

I welcome everyone's attention the public No. [programmers] Herd, finishing the 1000 and 2019 a number of companies java face questions over 400-page pdf document, the article will be updated on the inside, data compilation will be on the inside.

Remember the point of a paper like praise yo, thanks for the support!


Guess you like

Origin juejin.im/post/5df5e3af51882512480a81c9