The hole in the Java written test interview

Source: Internet
Author: User

1. About type initialization

For a class member variable, the compilation system automatically assigns the initial value, but it must be defined before it can be used, and you do not have to initialize

The default value for the member data type of the class is:

Boolean:false byte:0 short:0 char: ' \u0000 ' int: ' 0 ' float:0.0f double:0.0 object:null

But local variables, not only the first definition, but also must be initialized, otherwise it will be an error.

******************************************************************************************

2. Passing values and passing references

The 8 basic data types in Java, when passing in a method, are passing their copy into the method, manipulating it in the method, and when the method returns, its value remains in the state before the method call.

Other types, such as map,list, arrays, and so on, are passed in by passing their references directly to them, manipulating them in the method, and when the method returns, the values changed in the method remain.

Test code:

View Code

******************************************************************************************

The parameter type in 3.MAP must be an object, cannot make the base type, to override the Hashcode and Equles two methods. List is the same.
******************************************************************************************

4.java: [Type (bytes)] Byte (1) short (2) int (4) long (8) flout (4) double (8) (can have e = power) char (2) Boolean (1bit)

c: char (1) Int (4) short int (2) long int (4) double (8)

******************************************************************************************

The difference between 5.HashMap and Hashtable

(1) HashMap and Hashtable all implement the map interface. Hashtable inherits from the dictionary class. HashMap can have null key and null Value, but its key must be unique. The presence of null values is not allowed in Hashtable.

(2) HashMap is not thread-safe, and Hashtable is thread-safe. HashMap is a lightweight implementation of Hashtable.

******************************************************************************************

6.Collection, List, Set, map relationships

(1) Collection is the base interface for list and set. The list was added in order based on the collection. Set is the only one added on the basis of collection. And the Java JDK does not provide a class that inherits collection directly, only the classes that inherit from list and set. There is a iterator () method. can traverse its children.

(2) Map is an interface that is tied to collection. is a mapping of key-value.

******************************************************************************************

The difference between 7.ArrayList and vector

(1) synchronization: Vector is thread-safe. ArrayList is not thread-safe. The weakness of thread safety is the complexity and inefficiency of the implementation.

(2) Data growth: When the number of data exceeds the length of the array, the length of the array needs to be extended. ArrayList is the extension of the original length of the 50%,vector is one times longer than the original array.

******************************************************************************************

8.String, StringBuffer and StringBuilder

(1) Essential Comparison: string is a constant character array, and when its value changes, it must be re-instantiated; StringBuffer is a string variable, thread safe; StringBuilder is also a string variable, non-thread safe.

(2) Speed comparison: In the condition of changing length or content, stringbuilder>stringbuffer>string. Note string s = "a" + "B" + "C"; in the JVM with string s = "abc"; is equivalent.

(3) StringBuffer can be understood as a string of character buffers that can be changed by append and insert. Append is the addition of content at its tail, such as a Z-reference to the current content is "start", after the execution of Z.append ("le"), its contents become "startle". After executing Z.insert (4, "le"), its contents become "Starlet". StringBuilder is a lightweight alternative class of stringbuffer that exits in 5.0, and is fast in the absence of multi-threaded shared variables. The method is similar to StringBuffer.

******************************************************************************************

9.switch (A) {case B:}

Where a part must be of type int, or can be implicitly converted to an int (byte,short,char,int), or an item in an enum.

Part B must be a single byte,short,char,int type, or final type, and the final type must be a compile-time constant.

******************************************************************************************

10.try{return;} finally{}, return is executed after finally execution.

******************************************************************************************

11.try{}catch{syso ("1")}catch{syso ("2")}finally{syso ("3")} SYSO ("4")

Where catch cannot be cascaded, the contents of finally are executed when the first catch ends. When you are finished executing, you will continue to execute the try in sequence: The contents after the catch block.

******************************************************************************************

12.JAVA of JVM memory can be divided into 3 zones: heap, stack (stack) and method area

Reference: http://www.blogjava.net/yaoyaojj/archive/2011/07/31/355438.html

http://java-mzd.iteye.com/blog/848635

******************************************************************************************

13. Abstract classes cannot be instantiated

******************************************************************************************

14. These are thread-safe

HashTable Vector stringbuffer concurrentlinkedqueue concurrenthashmap

******************************************************************************************

How many two-fork trees can be composed of 15.N nodes

H (N) = C (n,2n)/n+1

******************************************************************************************

16.Java life cycle of objects inside

Within the JVM runtime space, the entire declaration cycle of an object is broadly divided into the following phases:

Stage of Creation (Creating)--Non-visual phase (using)--Non-Invisible phase (unreachable)--the collection stage (collected), End stage (finalized), release phase (free)

"1" Creation phase:

The creation process takes several steps:

Allocating memory space to objects

Start Constructing objects

The construction method of recursive call Super class

object instance initialization and variable initialization

Execution constructor Method body

"2" Application Phase features:

The system maintains at least one strong reference to the object (strongreference)

All references to this object are strongly referenced unless we display a soft reference, weak reference, or virtual reference

"3" is not the View stage:

The non-visual stage is that we can no longer reference it in the area code, that is, the strong reference has disappeared, in general we set the object at this time to NULL, its main purpose is to let the JVM find it, and can be in time to reclaim the resources occupied by the object

"4" unreachable stage:

An unreachable stage object that can no longer find a direct or indirect strong reference in the object reference root collection managed by the virtual machine, which usually refers to the temporary variables of all line stacks and related references, which are objects to be reclaimed, but cannot be reclaimed by GC directly.

"5" can be collected phase, end stage, release phase:

At the end of the object life cycle, objects of this stage may be in three states:

The garbage collector found that the object is unreachable

Finalize method has been executed

Object has been reused

******************************************************************************************

17.Hibernate caching mechanism

First-level cache is the session level of the cache, a session to do a query operation, it will put the results of this operation in a cache, if a short period of time this session (must be the same session) and do the same operation, Hibernate then takes it directly from the primary cache, and no longer connects to the database, fetching data.
Second-level cache is the sessionfactory level of cache, as the name implies, query results will be cached to the level two cache, if the same sessionfactory created by a session to perform the same operation, Hibernate will take the results from the level two cache and will not connect to the database.
Reference:
http://blog.csdn.net/xiashan17/article/details/6049664

******************************************************************************************

18.Hibernate Common Interview Questions

http://blog.163.com/peripateticism_lxt/blog/static/183211290201139102743814/

******************************************************************************************

19. Primary key and index relationship

Creates a primary key, and it automatically creates a unique index with the same name associated with it. When you delete a primary key, both the primary KEY constraint and the corresponding unique index are deleted.

A PRIMARY key constraint exists, there must be a unique index corresponding to it, and a unique index does not necessarily correspond to a primary key constraint.

******************************************************************************************

20. Transcode UTF-8 characters to Iso-8859-1

String name =new string ("SOI". GetBytes ("Iso-8859-1"), "iso-8859-1");
String nameutf = new String (Name.getbytes ("UTF-8"), "UTF-8");
System.out.println (NAMEUTF);

******************************************************************************************

21.B Tree

http://blog.csdn.net/sws9999/article/details/3018519

******************************************************************************************

22.java Common written test questions. It's enough to have this one.

Http://www.blogjava.net/fanyingjie/archive/2007/06/27/126467.aspx

******************************************************************************************

23.java class loading process, and the existing problems

http://www.dewen.org/q/7140

******************************************************************************************

The hole in the Java written test interview

Related Article

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.