In 2020 java interview questions (a) - Java Fundamentals

------------ ------------ restore content begins

1. Java Fundamentals
1.1 for background verification at login, get back to loginpass contrast with the database values have been?
Method 1.2 Java coverage (Overwrite) and method overloading (Overloading) What does it mean?
Overload Overload represents the name of the same method for a plurality of the same class, but the parameter list of these methods vary (i.e., different number or type of parameters).
Rewrite Override representation subclass can be the name of a method and parameters identical to the parent class, instance of a subclass object created by this method is called, it will call the method defined sub-class, which is equivalent to the parent the class defined in exactly the same manner to the cover, which is object-oriented programming polymorphism of performance.
What is the difference 1.3 interfaces and abstract classes are?
Abstract class: abstract containing the modified class is the abstract class, abstract class can not create an instance of an object. Abstract class containing the method must be defined as an abstract class, an abstract class method need not be abstract. Abstract class must implement the abstract methods defined in a particular subclass, therefore, it is not abstract or abstract static constructor method. If the child does not like all abstract methods abstract parent class implementation, then the subclass must also be defined as abstract types.
Interface: can be said to be a special case of an abstract class, all methods in the interface must be abstract. The method defined interface defaults to public abstract type member variable type interface defaults to public static final.
Compare the syntax of the two following differences
1. An abstract class can have a constructor, interface can not have a constructor.
2. abstract class can have an ordinary member variables, the interface is not an ordinary member variables
3. abstract class may contain non-abstract ordinary methods, all interface methods are abstract must not have non-abstract ordinary method.
4. The method of access type abstraction may abstract class that the public, protected, and the default type, the abstract method only public interface type, and the default is the modified public abstract type.
The abstract class may contain static methods, static methods can not contain an interface
variables 6. The abstract classes and interfaces can contain static member variables, static member variable access type abstract class may be any, but is only defined in the interface public static final type can be, and is the default public static final type.
7. A class can implement multiple interfaces, but can only inherit an abstract class.

1.4 There are several threads to create unreasonable way?

   Custom class inheritance Thread class way

   Custom class that implements Runnable Interface

Basic Interface 1.5 Java Collections Framework What?
Collection Interface
   List Interface
    Set Interface
Map Interface

What 1.6 BlockingQueue that?
1.BlockingQueue: Queue supports two additional operations, these two operations are: queue becomes non-empty, and wait for space to become available when the memory element when retrieving an element.
2.BlockingQueue not accept null elements.
3.BlockingQueue capacity may be defined.
4.BlockingQueue implementation is thread safe. Queue is not thread safe. Therefore Blockingqueue can be used for the producer - consumer model.
For BlockingQueue queue and then, if BlockQueue is empty, the operation to take things from BlockingQueue will be blocked into a wait state until BlockingQueue into something will be awakened, too, if BlockingQueue is full, any attempt to keep inside operation of things will be blocked into a wait state until BlockingQueue space there will be awakened to continue.
What are the two types of exceptions in the 1.7 Java that?
Error: called error generated by the java virtual machine and throws, including dynamic link fails, the virtual machine errors, the program does not process them.
Exception: All parent exception classes, subclasses corresponding to a variety of unusual events that may occur, usually need to declare or to capture the user's display.
Runtime Exception: a special kind of abnormality, such as by 0, an array subscript of range, etc., which produce relatively frequent, troublesome process, or if the statement will be displayed on the captured readability and operation efficiency greatly. Thus automatically detected by the system and to their default exception handler (user does not have to handle them).
1.8 Final, finallyfinalize difference?
final declaration for properties, methods, and classes, attributes can not be changed, respectively, the method can not be overwritten, the class can not be inherited. To access the local inner class variables, local variables must be defined are final.
finally exception handling part of sentence structure, means always executed.
finalize is a method of the Object class, at the time of execution of the garbage collector calls this approach is subject to collection, can override this method to improve the recovery of other resources when garbage collection, such as closing files. JVM does not always guarantee that this method is invoked.

How to achieve the 1.9 Java serialization, what is the point?
It is a kind of serialization mechanism for an object a process stream, that is, so-called content object stream object to be fluidized. After the fluidized objects can read and write operations, the object can also be transmitted after fluidizing between networks. Serialization is to solve the problems may arise when reading and writing a stream of objects (if not the sequence of data may be problematic scrambled).
To implement the sequence, it is necessary to make a class implements Serializable interface, which is an identifier of an interface, such labels may be serialized objects are then used to construct an output stream and output stream through an object writeObject (Object) method write objects can be achieved (i.e., to save its state); if necessary to deserialize the input stream can be an input stream to create an object, then the object is read from the stream by readObject methods. In addition to the sequence of persistent objects can be achieved, but also the depth of the object can be used for cloning.

Threading issues over 1.10
1.11 have used what design patterns
Singleton design pattern
factory design pattern
template design pattern
decorative design mode
proxy design pattern
adapter design pattern
1.12 write out a single-mode embodiment
starving pattern
public class Single {
    // private constructor for this class
    Private Single () {}
    // Creating this class object
    Private static new new Single Single S = ();
    // get the original object methods provide external
    public static Single getInstance () {
        return S;
    }
}
Note the problem:
  due to the outside world can not create a Single object no object, it would not be getInstance method call, then you need to getInstance static method, so that the outside world will be through the class name to call this method directly.

Lazy mode
public class Single
{
    // private constructor
    Private Single () {}
    // Create an object of the present class in this class
    Single instance = null static Private;
    // provide external static access methods, access to this instance of the object class
    public static Single getInstance () {  
        IF (instance == null) // there will be security thread
        {
            instance = new new Single ();
        }
        return instance;
    }
}
class SingleDemo
{
    public static void main (String [] args)
    {
        // Get instance of the object class Single S
        Single Single.getInstance S = ();
        // Get an instance object class S2 Single
        Single s2 = Single.getInstance ();
        System.out.println (S == S2); // to true
    }
}

More java face questions please pay attention to the dark horse java forum

End ------------ ------------ restore content

Guess you like

Origin www.cnblogs.com/ihmlt/p/12382588.html