Java interview fragmentary knowledge

After 1.Java file compiled into JVM byte code file, i.e. .class files, the file byte code running on different operating systems, the operating system then compiled byte code into machine code files. This is the cross-platform Java

2. First be clear, java recovery of GC is completely automatic, manual recovery does not provide api, all memory allocation and deallocation rights in jvm, in the hands of developers garbage collection method is not absolutely mandatory, but can do to do:

For the object is no longer referenced, a reference to it in time assigned to null. obj = null;

If the memory is really tight, call System.gc () method to recommend garbage collector garbage began notifying GC run, but the Java language specification does not guarantee that GC will perform.

Default 3.java basic types and ranges

Integer type byte (1 byte) short (2 bytes) int (4 bytes) long (8 bytes)

Character type char (2 bytes)

Floating point type float (4 byte) double (8 bytes)

4. The common ASCII value of the character as follows: a space ASCII code is 32; a digital ASCII code value of 0 to 9, respectively 48 to 57; capital letters "A" to "Z" of the ASCII values ​​of from 65 to 90 ; lowercase letters "a" to "z" is the ASCII value to 97 to 122.

5.Java identifier naming rules are as follows:

Case by the 26 English letters, numbers: 0-9 Symbols: _ $ ¥ Composition

Identifier should be a letter, _, $ beginning.

Identifiers can not be keywords.

6. abstract classes and interfaces

About abstract class

JDK 1.8 before, the method of abstract class default access to protected

JDK 1.8, the abstract class method becomes default default access

About Interface

JDK 1.8 before, interface methods must be public

When the JDK 1.8, the method may be a public interface, and may be a default

1.9 JDK, the method may be a private interface to

7. boxing and unboxing

Basic data types are converted into packaging containers (such as: int -> Integer).

Packaging is converted into the basic data types unboxing (eg: Integer -> int).

Is a reference to the type of packaging, the basic data type is a value type.

By operation of boxing and unboxing can be set up to do a bridge in value types and reference types. In other words, you can easily implement value types and reference types interchangeable, packing and unpacking can unify inspection system, the ultimate value of any type can be handled in accordance with the object.

8. serialization and deserialization

Java serialization is not in the instance variables of static and transient modification of variables, because the members of the class representatives static, transient temporary data representing an object, is declared both types of data members can not be serialized

There are two ways 9.Java passed, and the value is passed reference. In the basic types and string str = "aaa"; values ​​are created in this way is transmitted, and to create an array of objects are passed by reference, it is determined that the shape function parameters require special attention.

10.Java garbage collection

Garbage collection is aimed primarily at the recycling heap, because the memory stack area, with the release of the thread. Heap divided into three zones: the young generation (Young Generation), the old generation (Old Generation), on behalf of the Permanent (Permanent Generation, that is, the method area).

The young generation: the object is created (new) objects usually placed Young (except for some relatively large memory occupied by objects), after a certain Minor GC (for the young generation garbage collection) still alive object will be moved to the years old generation (some specific details are omitted movement).

The old generation: the young generation is moving up above and some of the larger objects. Major GC (FullGC) is recovered for the older generation.

Permanent Generation: is the final storage of constants, static variables, constants pool.

11. The package references

import java.util. *;

Access java / util all the classes in the directory can not be accessed at java / util subdirectory of all classes

12.Java reserved words and keywords

goto and const keywords are also reserved words.

Java keyword list (in alphabetical ordering a total of 50 groups):

abstract, assert, boolean, break, byte, case, catch, char, class, const(保留关键字), continue, default, do, double, else, enum, extends, final, finally, float, for, goto(保留关键字), if, implements, import, instanceof, int, interface, long, native, new, package, private, protected, public, return, short, static, strictfp, super, switch, synchronized, this, throw, throws, transient, try, void, volatile, while

Reserved word list (in alphabetical ordering a total of 14 groups), Java reserved word refers to the existing Java version has not been used, but later versions may use as keywords:

byValue, cast, false, future, generic, inner, operator, outer, rest, true, var, goto (reserved keywords), const (reserved keywords), null

13. constructor can not be inherited, the method can only be called configured explicit or implicit. (There are no arguments and parameters such)

14. The document is divided into text files and binary files, computers only know binary, so this is actually different interpretations are binary way. Text files are different character encoding format, such as Ascii, Unicode, etc., extension window Chinese in this document are ".txt",, various programming language source code files "log."; Binary files is to use a text document open garbage is not read, as long as the text can open files can be regarded as a text file, but the result displayed is not what you want, binary files only with a special application to read the file, such as ".png", " .bmp "and so on, most of the computer file or binary file

15.servlet applet is running on the server, the network service request is received and a way to produce a response.

servlet functions: accepting http request, generate a dynamic http response. Web container is responsible for the HTTP request into an HttpServletRequest object

16. character stream and byte stream

End of the stream is a stream of bytes, and Reader writer ending character stream are the difference between the two is the time to read and write a byte is read, a character is based. The actual use is usually about the same. In the read and write files need to deal with the contents of rows, such as comparing a particular character, a line of data processing when the general will choose a character stream. Just read and write files, file contents, and unrelated, usually selected byte stream.

When 17.try only suitable for handling abnormal operation, try + catch + for abnormal general exception handling operation. That is, if you just try to deal with common abnormal not to be catch processing, compiling a pass, because the mandatory compiler, common abnormal if you choose to capture, display must be declared with catch for further processing. The run-time exception is not so specified at compile time, so the catch can be omitted, plus catch you feel compiler also understandable.

18. Generics java merely syntactic sugar, it does not affect the java virtual machine assembly code generated at compile phase, the virtual machine will erase the generic type, reduced to no generic code, compiled at the most slightly slower speed, speed of execution is absolutely no different.

19.Set not have repeated elements, and is disorderly, a null value will be only one. Because it is not allowed to repeat. L ist element can be repeated, and the ordered, values ​​may be available to a plurality, it may be repeated as

The four properties 20.DBMS affairs

Atomicity: A transaction is a set of indivisible operation unit, the set of cells while either succeed or fail concurrently (DBMS implemented by the transaction management subsystem);

Consistency: the integrity of the data before and after the transaction to be consistent (testing tasks by the integrity of the subsystem DBMS);

Isolation: a plurality of users do not influence each transaction, separated from each other to (controlled by the DBMS subsystem enables concurrent);

Durability: Once a transaction commits, the impact on the database is generated permanent irreversible, then later rolled back or if abnormal, will not affect the transaction has been submitted (by the DBMS recovery management subsystem implementation)

volatile keyword in 21.Java function

java is a volatile type of modifier. It is designed to be modified by different threads access and modify variables. If you do not join volatile, essentially lead to this result: either not to write multithreaded programs, or lose the opportunity to a large number of compiler optimization.

Visibility

Visibility refers to the modifications to the variable in one thread will immediately by the working memory (Work Memory) written back to main memory (Main Memory), it will immediately respond in the read operation other thread. Incidentally, working memory and main memory may be approximately understood that the actual computer cache and main memory, a working memory exclusive thread, main memory is shared by the threads.

Prohibit instruction reordering optimization

Prohibit instruction reordering optimization. You know the code (especially multi-threaded code) we write, because the compiler optimizations, may differ from ours in the actual execution of the order written. The compiler only guarantee execution result with the same source code, not the actual sequence of instructions to ensure that the same source code. It seems no problem in single-threaded, multi-threaded but once introduced, this disorder can lead to serious problems. The volatile keyword can solve this problem on semantics.

Note that prohibit instruction reordering optimization of this semantic until after jdk1.5 to work correctly. Prior to the JDK even if the variable is declared as volatile can not completely avoid the problems caused by reordering.

22.Java difference with C, and C after the assignment will be compared with 0, if greater than 0, it is considered to be true; but Java does not compare to 0, integer type is int, boolean is Boolean.

23.Math class provides three rounding methods associated with: ceil, floor, round, the role of these methods are defined in the corresponding English names, for example: English meaning ceil is the ceiling, which represents up to rounding the result Math.ceil (11.3) is 12, the result Math.ceil (-11.6) is - 11; floor is a floor in English, then the method indicates rounding down results Math.floor (11.6) of is 11, Math.floor (-11.4) results --12; the most difficult to grasp is round approach, he said, "rounding" algorithm Math.floor (x + 0.5), soon after the original figures to plus 0.5 under rounding, so that the result Math.round (11.5) is 12, the result Math.round (-11.5) is --11.

24. immutable class (Immutable Class) is instantiated once does not change its state (or value) of the class.

String is a typical immutable class. (Using built-in string functions to change the string content is equivalent to creating a new string, namely new String)

The main purpose of the class is immutable object thread-safe in a multithreaded environment.

Modifier 25.java interfaces are public, interface variables public static final, the method is public abstract interface

26. A variable declared in the class has a default initial value (member variables); variable method declared no default initial value must be initialized when defined otherwise in error when accessing the variables (local variables).

27. The method of use can not be modified private variable (class may be)

Because the private modifier is used in the class, if, after using the private modifier in the class declare a member variable that can only be the class of the access method, and declared in the method body variable, the variable scope from this variable is declared until the end of the method body, if we use the private modifier, then the two will conflict, so you can not declare a variable in vivo is private, and declare variables in a method where nothing is private meaning, variables declared within a method scope already in vivo, but also in his own class, natural methods will not be accessed by other classes

28. Pipeline

For the pipe, which has the following types:

① Normal pipeline (PIPE): There are usually two restrictions, one simplex, i.e. only one-way transmission; Second blood, i.e. commonly used between parent and child (or inter-process the blood).

② flow conduit (s_pipe): In addition to the above-mentioned first limits, to achieve a two-way transmission.

③ named pipes (name_pipe): In addition to the above-mentioned second limit to achieve different processes unrelated communication.

Requirements for communication between different servers, required to form the full-duplex, half-duplex and the pipe only, although both directions, but only one direction at the same time transmission, full and half duplex the difference may be as follows appreciated icon:

29.Vector class in java array object can be achieved automatic growth

vector is thread-safe ArrayList (Vector and List usage is almost, but is now rarely used, List has been able to replace all the Vector), occupy contiguous space in memory. Initially it has an initial size, when the number of pieces of data is greater than the initial size distribution overwrites a larger contiguous space. If Vector is defined as Object can hold any type of store.

30. The difference between the start method on multiple threads and run method

There are two ways to start multi-threading, but whether it is to rely on that way, ultimately need to call the start method of thread, and the thread determine what to do, you need to override the run method, if we rewrite the run method, at the same time new main thread in a thread, the first case, call the start method of the thread, then it creates a new thread, which is in a ready state, waiting for the CPU scheduling; the second case, call the thread run method, then you will not have a new thread, still perform in the main thread.

Like the author of this article can give a point endorsed, look, will share Java-related articles every day! There are benefits presented from time to time, including the consolidation of learning materials, interview questions, such as source code ~ ~

Guess you like

Origin blog.51cto.com/14440597/2422489