JavaEE base face questions 0

2019/7/30
difference 1.java and C ++?
Is an object-oriented language that supports encapsulation, inheritance and polymorphism
Java does not provide a pointer to directly access memory, program memory more secure
Java class is single inheritance, C ++ supports multiple inheritance; although not Java class multiple inheritance, but the interface can be multiple inheritance
Java has automatic memory management mechanism, programmers do not need to manually release the useless memory

-------------- main class "class 2.java main program entry point Java program to be executed.
Main application class:
This class is the main class means comprises main () method of the main class is not necessarily required public class
main applet class:
This is a main class subclasses from the system or the Applet class JApplet , main class required applet class must be public

Summary: simply the application is started (that is, main () method) from the main thread. the applet is not the main method, mainly embedded in the browser page runs (calls init () or thread run () to start)

3. Inherited appreciated
Inheritance is defined using existing classes as a basis to establish a new class of technology, the definition of the new class can add new data or new functions may be functions of the parent class, but can not be selectively inherited father.
By using inheritance we can easily reuse the previous code.
Subclass the parent class has no private properties and methods of
subclasses can have their own attributes and methods that a subclass can extend the parent class.
Subclass the parent class can implement in their own way. ------ override

4. understand polymorphism
have to decide during the operation by the program.
There are two polymorphic forms may be implemented in Java: Inheritance (s Subclasses override the same method) and an interface (an interface and the interface to achieve the same coverage method).

The package appreciated
package privatization of attributes of an object, while some properties of the method can be accessed outside,

6. No reference configuration appreciated that
Java programs before constructing method performed subclass, without using super () to call the parent class constructor particular, will be called the parent class' constructor without parameters
if the parent class only It defines the constructor has parameters, in the constructor of a subclass and does not use super () to invoke a particular constructor parent class, then a compile-time error occurs

No-argument constructor before calling the constructor of a subclass will first call the parent class ------- "Help subclasses to do the initial work! ! !

7. static and instance methods any different
when calling a static method on the outside, you can use the "class name. Method name" approach, you can also use the "object name. Method name" approach. And examples of the latter method only way. In other words, you can call the static method without creating an object.
In this static method to access class members allow access only to the static member (i.e., static member variables and static methods), without allowing access instance variables and instance methods member; instance method does not have this limitation.

. == 8 and the equals ()
==: its role is to determine the target address is not equal to two. That is, it is determined the objects are not the same object. (== basic data type is a value comparison, the comparison reference data type == memory address)
the equals (): its role is to determine whether two objects are equal. It is generally used in two cases:
Case 1: No cover class equals () method. Through equals () comparing two objects of the class, is equivalent to the "==" to compare the two objects.
Case 2: class overrides equals () method. Generally, we cover the equals () method is equal to the contents of two objects; if their contents are equal, returns true (that is, the two objects are considered equal).

9.hashCode () and equals ()
action hashCode () is to obtain the hash code, also called a hash code; it actually returns an int integer. The role of this hash code is to determine the object's index position in the hash table
hashCode () is defined in the JDK Object.java, this means that any Java class contains a hashCode () function.
The relevant provisions of both:
1. If two objects are equal, must also be the same hashcode
2. Two objects are equal, for each two objects equals method call returns to true
3. hashcode two objects have the same value, they it is not necessarily equal to the (storage configuration: the same hash value list to string together, the load factor exceeds turned red-black tree structure)
4. Accordingly, equals overridden the method, the method must be covered hashCode
5. the default behavior hashCode () is to create a unique value to objects on the heap. If no override hashCode (), then the two objects are not equal class anyway (even if these two objects point to the same data)

10. Why JAVA only passed by value?
Passed by reference (pass by reference) means that when you call the function directly address the actual arguments passed to the function, then to modify the parameters carried out, it will affect the actual parameters in functions.
Value transfer (pass by value) refers to when calling function copies the actual parameters passed to a function, so if modify parameters in functions will not affect the actual parameters.
Therefore, the difference value is passed and not passed by reference deliver content. But in the end there is no argument to be a copy of the formal parameter.
So, Java or in fact, passed by value, only the object parameter, the value of the content is referenced object. (Note that reference who is)
Summary:
Whether it is passed by value or passed by reference, in fact, is a kind of evaluation strategy (Evaluation strategy). In the evaluation strategy, there is something called shared by transfer (call by sharing).
In fact, says the Java parameter passing strict sense should be shared by the transfer.

Shared by transmission means when calling the function, the copy function is passed to the argument of the address (if the argument on the stack, the value is copied directly). In the internal parameter function, you need to copy the address to find a specific value, then operation. If the value in the stack, because it is a direct copy of the value, the internal parameter function operation does not affect the external variables. If the original copy of the original value of the address in the stack, then the need to find the location corresponding to the stack based on the address, before proceeding. Because it is transferred to the external variable is visible in the copy function operation on the address value.

Simply put, Java is passed, is passed by value, and this value is actually referenced object.
And in fact, just passed by value passed by sharing a special case only. So we can say that the transfer is based on Java share delivery, or delivery in Java are passed by value.

11. The following four kinds of special circumstances, finally block will not be executed! !
1. abnormality has occurred in the finally block.
2. In the previous code with the System.exit () to exit the program.
3. The program is located thread death.
4. Close the CPU.

12.Java serialization if some field do not want to be serialized how do
who do not want to serialize variables, using the keyword transient modification.
the role of transient keyword: Stop the instance of those variables with this keyword modified serialization; when the object is deserialized, the transient modified variable values are not persisted and recovery.
transient can only modify variables, classes, and methods can not be modified

13. Get common keyboard input two methods
Method 1: Scanner
Scanner Scanner new new INPUT = (the System.in);
String input.nextLine S = ();
input.close ();
Method 2: the BufferedReader
the BufferedReader INPUT the BufferedReader new new = (the InputStreamReader new new (the System.in));
String input.readLine S = ();

 

Guess you like

Origin www.cnblogs.com/slfeng/p/11268927.html