Java interview (1)

Source: Internet
Author: User

1. Basic object-oriented features

Encapsulation, inheritance, polymorphism,

Encapsulation: Encapsulation of objective things into classes

Inheritance: Inheriting a class, you can use all of the functionality of this class and extend these functions without writing the original class

Polymorphic: Child objects call the parent object, and the parent object operates differently depending on the currently called child object

To implement polymorphism: overwrite, reload

The difference between 2.final\finally\finalize

Final declares methods, properties, classes, respectively, that the method is not overwritten, that the property is not mutable, that the class is not inheritable

Finally is part of the exception handling, which means that always executes

Finalize is a method of the object class that calls this method when the garbage collector executes. This method can be overridden to provide garbage collection when other resources are recycled, and the JVM does not guarantee that this method is always called

3,int and integer

int is one of the eight basic types of Java, and integer is the encapsulated class of int

int initial value is 0,integer initial value is null

cannot be used with each other

4. Overloading and rewriting

Overloaded overload, which indicates that there are multiple methods with the same name in a class, but whose argument list is different

Rewrite: A method in a subclass is exactly the same as the parent class, rather than completely overwriting this method in the parent class, so that the class throws fewer exceptions than the parent class.

5. Abstract classes and interfaces

Parameters Abstract class Interface
The default method implementation Can have the default method implementation The implementation of a completely abstract, non-existent method
Realize Extends, if the subclass is not an abstract class, you need to provide an implementation of all the methods declared in the abstract class Implements need to provide implementations of all declarative methods in the interface
Constructors can have Can't have
Differences from normal Java classes Can not be instantiated, other no difference A completely different type
Access modifiers Public/protected/default Public, JDK9 can use private
Main method Can have the main method and can run No
Inherited Can inherit a class and implement multiple interfaces Only one or more interfaces can be inherited
Speed Fast Time to find a way to achieve
Add a new method You can provide the default implementation The implementation class must be changed

6. Use and implementation of reflection

Use reflection to get the type information of an object during run time

Realize:

GetClass () method, Class.forName () method, using Class. class, Implementing getClassLoader with the ClassLoader ()

7.Session and the difference between cookies,

    1. The cookie is stored on the browser and the session is stored on the server
    2. Cookies are unsafe, session safe
    3. Session will be saved in the server for a certain period of time, will occupy the server, affect the performance
    4. A single cookie cannot hold more than 4k of data, and many browsers can save only 20 cookies
    5. Login information placed in session, others placed in cookies

Java interview (1)

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.