Java interview questions Summary (coming soon ...)

Source: Internet
Author: User

It has been four days for the interview, and I feel a lot of it. You only know how many pounds you have when you ask the interviewer an "aggressive" question. Generally, the interviewer is a leader or a project manager. People must have a hand in doing this. If you have the skills, you will know when you ask. However, if you have a specialization in the industry, you will not necessarily be able. For example, I said I would use flex technology on my resume, but I don't know anyone. If I ask what Flex is, I will take out all my skills, even though it's okay, do people know you're right? I think the most important part of the interview is the psychological quality. Even if you don't, you have to say with a thick face and smile, "This really doesn't know." Maybe people understand it very well, mainly because of your attitude towards things, how much work experience do you have? People should have an approximate scope.


This interview has basically no written questions. Now I have made two written questions. Generally, people ask you questions with their resumes. I still have some advantages, when a leader finally leaves, he says, "You have a sound logic and a programmer's qualities." (* ^__ ^ ...... In addition, I wrote my csdn blog link on my interview resume. I didn't expect an interviewer to really look at it. After reading it, I immediately gave him a good impression. In fact, this company also wanted me, but I didn't go because I didn't negotiate on my salary. Therefore, I also suggest that programmers should develop a good habit of writing blogs. This is not only writing articles, but also a learning process, A lot of things can't be clearly understood. This is the truth.


This evening I summarized the many questions I asked during the interview and won't ask any questions, hoping to lay the foundation for future interviews. If the answer is incorrect, please note it.


---------------------------------------------------------------------- Gorgeous split line ------------------------------------------------------------------

● Java Basics



1. Use Java to output 10 numbers that are not repeated. The number range is 1.

 

A: When I first saw this question, I repeatedly thought about the three words "do not repeat". I thought that the Set set saved non-duplicate data and wrote some. After the interviewer saw the problem, he said that I had something wrong with it. Let me write it again. So I thought about it again and rewritten it. The interviewer was barely satisfied after reading it. Back, I ran the code I wrote in eclipse and found that the code was redundant. After modification, the Code is as follows. If you have more simple or other ideas, please kindly advise.

package com.ldfsoft.test; import java.util.HashSet;import java.util.Set; public class RandomTest {                  public static void main(String[] args) {                                 numTest();                }                 static void numTest(){                                 Set set= new HashSet();                                 for(int i=0;i<10;i++){                                                 while(true){                                                                 int num=(int) (Math.random()*100);                                                                 if(!set.contains(num)){                                                                                 System.out.println(num);                                                                                 set.add(num);                                                                                 break;                                                                 }                                                 }                      }                                }                 }

2. Differences between hashmap, treemap, and linkedhashmap in Java.


A: I know hashmap and treemap. I have heard of linkedhashmap for the first time and can only leave it empty. By the way, I mentioned hashtable, which has many interviews. Query online information, the difference is as follows:

Java defines an interface java. util. Map for ing in the data structure. It has four implementation classes: hashmaphashtable linkedhashmap and treemap.

MAP is mainly used to store the key-value pairs and obtain values based on the keys. Therefore, duplicate keys are not allowed (repeated overwrites), but repeated values are allowed.

HashmapIs the most commonly used map. It stores data based on the hashcode value of the key, and can directly obtain its value based on the key, with fast access speed and time elapsed, the order in which data is obtained is completely random. Hashmap allows a maximum of null keys for one record, and the value of multiple records is
NULL; hashmap does not support thread synchronization. At any time, multiple threads can write hashmap at the same time, which may cause data inconsistency. If synchronization is required, you can use the synchronizedmap method of collections to synchronize hashmap or use concurrenthashmap.

HashtableSimilar to hashmap, It inherits from the dictionary class. The difference is that it does not allow null keys or values to be recorded. It supports thread synchronization, that is, only one thread can write hashtable at any time, as a result, hashtable is slow in writing.

LinkedhashmapThe record insertion sequence is saved. When iterator is used to traverse the linkedhashmap, the first record is certainly inserted first. You can also use parameters to sort the records by the number of times of application during construction. It is slower than hashmap during traversal, but in some cases, when the hashmap capacity is large and the actual data is small, the traversal may be slower than linkedhashmap, because the traversal speed of linkedhashmap is only related to the actual data and has nothing to do with the capacity, and the traversal speed of hashmap is related to its capacity.

TreemapThe sortmap interface can sort the records stored by the key. By default, the key value is sorted in ascending order. You can also specify the sort comparator. When you use iterator to traverse the treemap, the obtained records are sorted in ascending order.

 

Generally, hashmap is used most often. The key-value pairs stored in hashmap are random when they are retrieved. It stores data based on the key's hashcode value, you can directly obtain its value based on the key, with fast access speed. Hashmap is the best choice for inserting, deleting, and locating elements in a map.

Treemap obtains the sorted key-value pairs. However, if you want to traverse keys in the natural or custom order, it is better to use treemap.

Linkedhashmap is a subclass of hashmap. If the output sequence is the same as that of the input, you can use linkedhashmap to implement it. It can also be arranged in the read order, as it can be applied in the connection pool. The following code example shows the differences among hashmap, linkedhashmap, and treemap:

 

 

Package COM. ldfsoft. test; import Java. util. hashmap; import Java. util. iterator; import Java. util. linkedhashmap; import Java. util. map; import Java. util. treemap; public class Ceshi {@ suppresswarnings ("unchecked") public static void main (string [] ARGs) {// hashmapsystem. out. println ("------ hashmap unordered output ------"); hashmap hsmap = new hashmap (); hsmap. put ("3", "value3"); hsmap. put ("1", "value1"); hsmap. put ("2", "value2"); hsmap. put ("B", "valueb"); hsmap. put ("A", "valuea"); iterator it = hsmap. entryset (). iterator (); While (it. hasnext () {map. entry E = (map. entry) it. next (); system. out. println ("key:" + E. getkey () + "-- Value:" + E. getvalue ();} // treemapsystem. out. println ("------ treemap output by key ------"); treemap temap = new treemap (); temap. put ("3", "value3"); temap. put ("1", "value1"); temap. put ("2", "value2"); temap. put ("B", "valueb"); temap. put ("A", "valuea"); iterator tit = temap. entryset (). iterator (); While (tit. hasnext () {map. entry E = (map. entry) tit. next (); system. out. println ("key:" + E. getkey () + "-- Value:" + E. getvalue ();} // linkedhashmapsystem. out. println ("-- linkedhashmap outputs according to the input sequence --"); linkedhashmap lhsmap = new linkedhashmap (); lhsmap. put ("3", "value3"); lhsmap. put ("1", "value1"); lhsmap. put ("2", "value2"); lhsmap. put ("B", "valueb"); lhsmap. put ("A", "valuea"); iterator outputs = lhsmap. entryset (). iterator (); While (iterator. hasnext () {map. entry E = (map. entry) enabled. next (); system. out. println ("key:" + E. getkey () + "-- Value:" + E. getvalue ());}}}

 

3. How many forms does the XML document define? What are the essential differences between them? How can I Parse XML documents?


Answer the essential difference between two types of DTD Schema: the schema itself is XML and can be parsed by the XML Parser (this is also the fundamental purpose of developing the schema from the DTD). C: dom, sax, Stax, etc.
DOM:When processing large files, the performance is greatly reduced. This problem is caused by the DOM tree structure. This structure occupies a large amount of memory and the Dom must load the entire file into the memory before parsing the file, which is suitable for Random Access to XML.
Sax: It does not exist in Dom. Sax is an event-driven XML parsing method. It reads XML files sequentially without loading the entire file at a time. When a file starts with a file, the document ends, or the tag starts with a tag, it triggers an event. You can write the processing code in the callback event to process the XML file, suitable for sequential access to XML
Stax: Streaming API for XML (Stax)


4. Write a singleton file.


A: The Singleton mode ensures that only one instance of a class exists in a Java application.
The Singleton mode generally has several forms:
The first form: defines a class. Its constructor is private. It has a static private class variable. When the class is initialized, use a public getinstance method to obtain its reference, and then call the method.
 

Public class Singleton {private Singleton () {}// define your own instance internally. Isn't it strange? // Note that this is private only for internal calls. Private Static Singleton instance = newsingleton (); // here we provide a static method for external access to this class, you can directly access public static Singleton getinstance () {return instance ;}}

 
Second form:
 

Public class Singleton {Private Static Singleton instance = NULL; public static synchronized Singleton getinstance () {// This method is better than above, so you do not need to generate objects every time, it is only the first time that an instance is generated/used, improving the efficiency! If (instance = NULL) instance = new Singleton (); Return instance ;}}

Other forms: Define a class. Its constructor is private and all methods are static.
It is generally considered that the first form is more secure.

● Javaweb


1. Let's talk about the nine built-in objects of JSP.

 

Answer: This is a basic question, and there are many interviews.

RequestIndicates the httpservletrequest object. It contains information about browser requests and provides several useful methods for obtaining cookie, header, and session data.

ResponseIndicates the httpservletresponse object, and provides several methods (such as cookies and header information) for setting the response to the browser)

OutThe object is an instance of javax. jsp. jspwriter and provides several methods for you to send the output results back to the browser.

PagecontexT indicates a javax. servlet. jsp. pagecontext object. It is used to facilitate access to various namespaces and servlet-Related Object APIs, and encapsulates common servlet-related functions.

 SessionIndicates the javax. servlet. http. httpsession object of a request. Session can store user status information

ApplicatonIndicates a javax. servle. servletcontext object. This helps you find information about the servlet engine and Servlet environment.

ConfigIndicates a javax. servlet. servletconfig object. This object is used to access the initialization parameters of the servlet instance.

PageIndicates a servlet instance generated from this page.

 

● Framework-related

 

1. Differences between struts1 and struts2.

 

Answer: It is undeniable that some companies are still using struts1, which is an old project, and some are used in their work. The differences are as follows:

1. Different configuration file formats

2. struts1 has the from class and action class, and its attributes are encapsulated in the from class. In struts2, there are only action classes, and properties are encapsulated in the action class.

3. The page call is struts1 *. Do struts2 *. Action

Source: http://zhidao.baidu.com/question/349509852.html&__bd_tkn__=6e8f493f2c3c9b37460be16eeeb332aac71fdae38078338d51fed8133ea5c69d362ad36bb4bcda3b39bb3949f6bbe47087ac3af56e60b1f4e7eb60157b58f4379d6ea1fd5c0f03de01252778d037cb7a4a06ed757d2ac28fd64a3609705d305ac5120d4540b5a4a39d08fcaccbdc8c0acb3120f746a0

 

2. Tell me how to clear the cache in hibernate.

 

Answer: I don't know how to answer this question. I thought about it: Can I clear the browser cache to solve it? The boss asked me: Is hibernate applied on the server or the client? I heard about my 2!

The answer to the query is as follows:

 

I. hibernate primary Cache
(1) hibernate supports two levels of caching. By default, only one level of caching is supported;
(2) Each session has a primary cache;
(3) When a session is closed, its corresponding level-1 cache is automatically cleared;
(4) the save, update, saveorupdate, load, get, list, iterate, and lock methods all store objects in the cache.
(5) Only get, load, and iterate data can be read from the cache.
(6) The query object does not read the cache by default. To enable caching, use the Syntax:
Query. setcacheable (true );
<Property name = "cache. use_query_cache"> true </property>
(7) after the query cache is enabled, the cache will match successfully only when the query conditions are exactly the same as those of the previous query.
(8) criteria does not support caching;
(9) The number of objects in the cache cannot be controlled in the first-level cache. Note that memory overflow may occur when a large volume of data is operated. You can clear the cache.
Session. Clear () Clear all objects in the cache
Session. evict (User) clears the specified object
Ii. hibernate secondary Cache
* The save, update, saveorupdate, load, get, list, query, and criteria methods all fill the second-level cache.
* Get, load, and iterate fetch data from the second-level cache
* Session. Save (User) if the user's primary key is generated using "native", it is not placed in the second-level cache. (1) Enable the second-level cache.
<Propertyname = "cache. use_second_level_cache"> true </property> (2) specifies the implementation class of the second-level cache for hibernate
<Property name = "cache. provider_class">
Org. hibernate. cache. oscacheprovider
</Property> (3) create a configuration file for the Oscache cache (hibernate_advance_surpport_lib is required)
Src/Oscache. propertiescache. capacity = 1000 specify how many objects the cache can hold
(4) Specify the classes that need to be placed in the second-level cache, and the objects that need to be used for a long time must be placed in the second-level cache.
<Class-Cache class = "entity. petinfo" usage = "read-only"/> // objects in the cache cannot be updated.
<Class-Cache class = "entity. petinfo" usage = "read-write"/> // allows you to update objects in the cache or in the orm file:
<Class name = "entity. petinfo" table = "petinfo" schema = "DBO" catalog = "epet">
<Cache Usage = "read-only"/> </class> (5) to clear the second-level cache, use the following syntax
Sessionfactory. evict (user. Class) Clear all users
Sessionfactory. evict (user. Class, ID) clears the specified user

 

Source: http://www.24xuexi.com/w/2011-04-29/89139.html

 

● Oracle/MySQL database


1. Write the SQL statement used to query the first 10 pieces of data in Oracle.


Answer: The SQL statement is select * from table where rownum <= 10.


2. Write SQL statements that query 11th to 20 records in Oracle.


Answer: The SQL statement is select * from (select T. *, rownum R from table t where rownum <= 20) Where R> = 10.


3. What are the differences between Oracle and MySQL.


A: I said two things at the time: 1. oracle has "pseudo column" rownum, while MySQL does not. mySQL uses auto_increment to implement auto-increment, while Oracle uses sequences or triggers to implement auto-increment. The interviewer said this is enough, (* ^__ ^ *)...


● Html/JavaScript/jquery


1. Differences between onload () in JavaScript and ready () in jquery.

 

A: I often use onload in JS. As for jquery's ready (), I heard it for the first time, and the results can be imagined. The solution for querying information is as follows:

 

◆ Execution time: the window. onload method is executed only after all the elements (including all associated files of the elements) in the webpage are fully loaded into the browser. In jquery, $ (document ). the event handler registered by the ready () method can be called as long as the Dom is fully ready. For example, if the label of an image is complete, you do not need to wait until the image is loaded, you can set attributes or styles of an image.

◆ $ (Document ). the ready () method can be used multiple times to register different event handlers, while the window. onload can only store reference to one function at a time. Multiple binding functions only overwrite the previous functions.

 

Source: http://blog.csdn.net/ymjring/article/details/7733129

 

2. (To be resolved) use JavaScript or jquery to implement the following functions: When a webpage is loaded, set the first input box of the webpage to focus and press Enter, set the second input box as the focus, and so on until the last input box. Assume that you do not know the id value of the input box.

 

Answer: I have not understood this question yet. What I don't understand is that "when you press the Enter key, set the second input box as the focus". I hope the people with lofty ideals can solve this problem.



● Eclipse/myeclipse


1. There are several shortcut keys for myeclipse, including Ctrl + C and CTRL + v.


Answer: I want to test the proficiency of IDE tools. I have mentioned the following:


Alt +/code prompt key

CTRL + Shift + R open the resource manager to find the file

Shift + Ctrl + enter insert blank lines in the current row

CTRL + k quickly locate to the next

CTRL + Shift + k quickly locate to the previous


● Questions


1. Explain how you optimize the front-end page, background code, and database.


Q: I have met this interview twice in total, but I cannot answer the question. How long did my brother work? I really don't have any experience. I hope you can give me some advice.


2. How do you control the memory during development.


A: It's another headache. I gave a few remarks at the time. It seems that this is a combination of hardware and I hope you can answer it.

3. Assume that a website has been running slowly for a period of time. How can you solve this problem?


Q: I am still thinking about this question. I was talking about restarting the server. The interviewer smiled. Do you dare to restart the server in the production environment? Well, this does not seem to work now. I hope you can give me some advice.

 

In the future, it is pending ......


This is my learning result. You can reprint it. You are welcome to share it with me. However, you must provide the link to this article at http://blog.csdn.net/youqishini/article/details/8113008. Thank you ~

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.