-java Foundation of "Java EE" Enterprise interview problem

Source: Internet
Author: User
Tags thread class

1. What does the Java Foundation section  1.1 method Overrides (Overwrite) and method overloads (overloading) in Java mean? Overloaded overload means that there can be more than one method with the same name in the same class, but the parameter lists of these methods vary (that is, the number of arguments or the type differs). overriding override means that a method in a subclass can be exactly the same as the name and parameters of a method of a parent class, and invoking this method from an instance object created by a subclass invokes the definition method in the subclass, which is equivalent to overwriting the exact same method defined in the parent class. This is also a representation of the polymorphism of object-oriented programming. What is the difference between an  1.2 interface and an abstract class? Abstract class: A class that contains an abstract modification is an abstraction class, and an abstract class cannot create an instance object. The class containing the abstract method must be defined as an abstract class, and the methods in the abstract class do not have to be abstract. Abstract methods that are defined in an abstract class must be implemented in a specific subclass, so there can be no abstract constructor or abstract static method. If the subclass does not implement all the abstract methods in the abstract parent class, then the subclass must also be defined as an abstract type. Interface: It can be described as a special case of an abstract class, and all methods in an interface must be abstract. The method definition in the interface defaults to the public abstract type, and the member variable type in the interface defaults to public static final. Here's a comparison of the syntax differences between the two 1. Abstract classes can have construction methods, and interfaces cannot have constructors. 2. There can be ordinary member variables in an abstract class, and there is no ordinary member variable 3 in the interface. Abstract classes can contain non-abstract ordinary methods, all the methods in the interface must be abstract, and cannot have non-abstract ordinary methods. 4. The access type of an abstract method in an abstract class can make public, protected, and default types, but the abstract methods in an interface can only be of the public type, and the default adornment is the public abstract type. 5. Abstract classes can contain static methods, and interfaces cannot contain static method 6. Both abstract classes and interfaces can contain static member variables, and the access types of static member variables in an abstract class can be arbitrary, but the variables defined in the interface can only be public static final types, and the public static final type is the default. 7. A class can implement multiple interfaces, but can inherit only one abstract class.  1.3 There are several ways to create threads? L Custom class inherits the thread class way L custom class implements runnable interface  1.4 What are the basic interfaces of the Java collection framework? Collection Interface Ølist interface Øset interface map interface  1.What is 5 blockingqueue? 1.BlockingQueue: A queue that supports two additional operations: waits for the queue to become non-empty when retrieving elements, and waits for space to become available when the element is stored. 2.BlockingQueue does not accept null elements. 3.BlockingQueue can be of limited capacity. The 4.BlockingQueue implementation is thread-safe. The queue is not thread-safe. Blockingqueue can therefore be used for producer-consumer models. For the Blockingqueue queue, if Blockqueue is empty, the operation from Blockingqueue will be blocked into the waiting state until blockingqueue into something will be awakened, as well, If the blockingqueue is full, any attempt to store something in it will be blocked into the waiting state until there is space in the blockingqueue to be woken up to continue operation.  1.6 What are the two types of exceptions in Java? Error: Called a bug, generated and thrown by a Java virtual machine, including dynamic link failure, virtual machine error, and so on, the program does not handle it. Exception: The parent class of all exception classes whose subclasses correspond to a variety of possible exception events, typically requiring the user to display a declaration or capture. Runtime Exception: A special kind of exception, such as by 0, array subscript beyond the range, it produces more frequent, processing trouble, if the display of the declaration or capture will have a significant impact on program readability and operational efficiency. Therefore, the system automatically detects them and gives them to the default exception handlers (which the user does not have to handle). The difference between  1.7 final,finallyfinalize? Final is used to declare properties, methods, and classes, respectively, that the property is immutable, that the method is not overridden, and that the class is not inheritable. Internal classes to access local variables, local variables must be defined as final types. Finally is part of the exception-handling statement structure, which indicates that it is always executed. Finalize is a method of the object class that, when executed by the garbage collector, calls this method of the reclaimed object, and can override this method to improve other resource recycling when garbage collection occurs, such as closing a file. The JVM does not guarantee that this method is always called. What is the point of  1.8 in Java for serialization? Serialization is a mechanism for dealing with the flow of objects, so-called object flow is the flow of the object's contents. It is possible to read and write to a Fluidized object, or to transfer the streamed object between the networks. Serialization is a problem that can arise when the object stream reads and writes (if there is no serialization, there may be a problem with data scrambling). To implement serialization,A class is required to implement the Serializable interface, which is an identifying interface, annotated that the class object can be serialized, and then using an output stream to construct an object output stream and to write out the implementation object (that is, save its state) through the WriteObject (object) method If deserialization is required, an object input stream can be established with an input stream, and then the object is read from the stream through the ReadObject method. In addition to being able to implement object persistence, serialization can also be used for deep cloning of objects.  1.9 used to design patterns. Single case design mode factory design pattern template design Pattern decoration design mode proxy design mode adapter design mode  1.10 Write a singleton mode out a hungry man mode public class Single {// Private the constructor in this class, the private single () {}//creates this class object private static Single S = new single ();//provides external access to the original object method public static single GetInstance () {return s;}} Note: Because the outside world cannot create a single object, and there is no object, then the GetInstance method cannot be called, and the GetInstance method needs to be statically initialized so that the outside world can call the method directly from the class name.   Lazy mode public class single{//private constructor () {}//creates this class object in this class private static Single Instance = null;//provides static access to external methods , get this class instance object public static single getinstance () {  if (instance = = NULL)   //Here is a thread security issue {instance = new Single ();} return instance;}} Class Singledemo{public static void Main (string[] args) {//Gets the instance object of the single class Ssingle s = single.getinstance ();// Gets the instance object of the single class S2single s2 = Single.getinstance (); System.out.println (S==S2); True}}

Java EE Enterprise interview problem-java Basics

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.