Java interview Summary

Source: Internet
Author: User

Java interview Summary

1. What is the difference between static variables and object variables?
Static is a static variable, which can be directly accessed by Class Name
Memory difference: When static is defined, jvm will allocate space,
Object variables allocate space only when an object is created.

2. What is the difference between int integers?
Integer is the packaging class of int.
Integer is an object. The default value is null. The default value of int is 0.

3. What is the difference between public protected friendly private?
The same package of the current class inherits different packages of the class
Public √ OK
Protected √ OK no
Friendly √ OK no
Private √ no

4. What is the difference between Overloading and rewriting?
Overload: The method name is the same and the parameters are different.
Overwrite rewrite: re-write of the parent class Method

5. Database paging Query
Oracle: select * from (select * from table where romnum> 0) where romnum <20;
Mysql: select * from table limit 0, 20

6. webservice?
A Service published by an enterprise can be accessed over the internet and called.
Hardware platform, operating system, and programming language for services
The main components are wsdl: web Service Description Language.

7. What are the characteristics of SOA?
Reusable
Loose coupling

8. webservice
JAX-WS
CXF

9. Differences between abstract classes and common classes:
The only difference between an abstract class and a common class is that you cannot create instance objects or abstract methods;

10. Differences between abstract classes and interfaces:
Abstract class and interface are two methods of defining abstract classes in Java. They have great similarity.
However, their choices often reflect the understanding of the essence of concepts in the problem field, and whether the reflection of design intent is correct,
Reasonable because they represent the different relationships between concepts (although all functions can be implemented as required ).
This is also a common use of language.
To sum up a few words:
Abstract classes and interfaces cannot be directly instantiated. to instantiate an abstract class, the variable must point to a subclass object that implements all abstract methods,
Interface variables must point to class objects that implement all interface methods.
Abstract classes must be inherited by quilt classes, and interfaces must be implemented by classes.
The interface can only be used as a method declaration. The abstract class can be used as a method declaration or method implementation.
The variables defined in the interface can only be public static constants, and the variables in the abstract class are common variables.
Abstract methods in an abstract class must be implemented by all quilt classes. If not all child classes can implement abstract methods of the parent class, the Child classes can only be abstract classes.
Similarly, if an interface cannot be fully implemented, the class can only be an abstract class.
Abstract METHODS can only be declared and cannot be implemented. Abstract void abc (); cannot be written as abstract void abc (){}.
Abstract classes can have no abstract methods.
If an abstract method exists in a class, this class can only be an abstract class.
Abstract methods must be implemented, so they cannot be static or private.
An interface can inherit interfaces and inherit more interfaces, but a class can only inherit from one interface.

Control reversal: dependency injection is not the only option to eliminate dependencies implemented by applications on plug-ins.
IOC: dependency injection: There are three main forms of dependency injection,
They are called Constructor Injection ),
Setter Injection)
And Interface Injection ).
If you have read some recent discussions about IoC, you can easily see:
The three injection modes are type 1 IoC (interface injection), type 2 IoC (Set Value Method injection), and type 3 IoC (constructor injection ).

The so-called AOP, that is, Aspect orientied program, is Aspect-Oriented Programming,
2. What is the aspect: one function of the system that runs through each module of the system is one aspect,
For example, logging, unified Exception Processing, transaction processing, and full-limit checks are all software systems.
A plane, rather than a point, must appear in each module.
3. What is Aspect-Oriented Programming: encapsulate one aspect of the system into an object for processing
4. How to Implement Aspect-Oriented Programming: embed the objects corresponding to the function module into the original system modules as the aspect,
Using proxy technology, the proxy will call the target and add the code (object) of the aspect function. Therefore,
When configuring proxy objects with spring, you only need to configure two attributes to indicate the target and the plane object (Advisor) respectively ).

Ioc refers to the delivery of the Instance interface or instance class to the IOC container (if the factory mode is understood as an IOC, there is no problem)

AOP is the weaving technology. To put it bluntly, the desired effect is to insert the method dynamically before, during, and after the method is executed.
First, let's talk about AOP. In fact, the principle is very simple. It is to wrap the instance you returned and add the method before each method of the instance,
If there is no IOC here, this implementation will be exposed to the programmer. After IOC is added, it will be perfect.
The process is that IOC goes to the Instance Object and calls the AOP program to repackage the object during the instance,
The final object returned to the programmer is the encapsulated object, which is so simple. There are many methods to achieve this.
The most typical is Sprint.net, which is implemented by Emit in reflection.

IOC: Control inversion is also called dependency injection. Using the factory Model
You only need to configure the corresponding bean in the spring configuration file and set relevant attributes so that the spring container can generate class instance objects and manage objects. When the spring container is started, spring initializes all the beans you configured in the configuration file, and when you need to call the bean, assign the beans it has initialized to the classes that you need to call these beans (assuming the Class Name Is A). The allocation method is to call the setter method of a for injection, you don't need to create new beans in.
Note: When you are interviewing, if you have the necessary conditions and draw a picture, you will be more familiar with it.
AOP: Aspect-Oriented Programming. (Aspect-Oriented Programming)
AOP can be said to supplement and improve OOP. OOP introduces concepts such as encapsulation, inheritance, and Polymorphism to establish an object hierarchy to simulate a set of public behaviors. When we need to introduce public behavior to scattered objects, OOP seems powerless. That is to say, OOP allows you to define the relationship from top to bottom, but it is not suitable for defining the relationship from left to right. For example, log function. Log Code is often horizontally distributed across all object layers, but it has nothing to do with the core functions of the objects it spreads. In OOP design, it leads to a lot of code duplication, which is not conducive to the reuse of each module.
Encapsulate the cross-business logic (such as security, logs, and transactions) in a program into a plane and inject it into the target object (specific business logic.

The technology for Implementing AOP is mainly divided into two categories: one is to use dynamic proxy technology, and use the method of intercepting messages to describe the message to replace the execution of the original object behavior; the second is to use static weaving to introduce specific syntax to create "aspect", so that the compiler can weave "aspect" code during compilation.
For example, if you want to add a print 'hello' function to all classes in your biz layer, you can use the aop idea to write a class to write a method, after the method is implemented, print 'hello' to make your Ioc class ref = "biz. * "to inject each class.

Database Connection differences:
Left join, right join, inner join (join)
Left join and right join are opposite:
Basic example: select * from table1 t1 left join table2 t2 on t1.col1 = t2.col2;
The result is as follows: all sets of table1 and partial sets of table2.
If you want to find all the sets of table2: right join:
Select * from table1 t1 right join table2 t2 on t1.col1 = t2.col2;
Inner join and join are exactly the same, and they look for the intersection of two tables.
Select * from table1 t1 inner join table2 t2 on t1.col1 = t2.table2 where t1.id = 1;

Basic data types include byte, int, char, long, float, double, boolean, and short.
Nine encapsulation classes: Byte, Integer, Char, Long, Float, Double, Boolean, Short, String;

Thread implementation method:
Inherit the Thread class to implement the Runnable interface and implement it through the Thread pool.

Sleep (), wait () method differences:
Sleep () The current thread suspends execution, giving CPU resources to other threads for execution. The monitoring status remains unchanged, but sleep () does not discard the object lock.
Wait () The current thread abandons the object lock and enters the waiting state. It can only be awakened when it is running y,
But sleep () immediately enters the execution status after the thread is executed.

Differences between java basic types and encapsulation classes
1. The basic type can only be passed by value, and the encapsulation class corresponding to each basic type is passed by reference.
2. In terms of performance, the basic types in java are created on the stack, and all object types are created on the stack (Object references are created on the stack ).
3. The appearance of encapsulation classes is to make it easier to use methods that are not available to basic types, such as valueOf () and toString.
4. If you want to pass an int object reference instead of a value, you can only use the encapsulation class.
5. basic data can be automatically encapsulated into encapsulation classes. The advantage of basic data types is that the speed is fast (not involving the construction and collection of objects ), the purpose of the encapsulation class is to better process the conversion between data. There are many methods and it is convenient to use.

[The Calling efficiency of allocating memory on the stack is much lower than that of allocating memory on the stack. Although it is highly efficient to allocate memory on the stack, there is a memory leakage problem when allocating memory on the stack.]

23 Design Patterns in Java:
Factory (Factory mode), Builder (construction mode), Factory Method (Factory Method mode ),
Prototype (original model mode), Singleton (Singleton mode), Facade (Facade mode ),
Adapter (Adapter mode), Bridge (Bridge Mode), Composite (merging mode ),
Decorator, Flyweight, Proxy ),
Command (Command mode), Interpreter (Interpreter mode), Visitor (Visitor mode ),
Iterator, Mediator, Memento ),
Observer (Observer mode), State (State mode), Strategy (Policy mode ),
Template Method (Template Method mode), Chain Of Responsibleity (responsibility Chain mode)
Factory mode: The factory mode is a frequently used mode. Classes implemented based on the factory mode can generate instances of a class in a group based on the provided data, generally, this group of classes has a common abstract parent class that implements the same method, but these methods perform different operations on different data. First, you need to define a base class. The subclass of this class implements the methods in the base class through different methods. Define a factory class. The factory class can generate different subclass instances according to the conditions. After obtaining the subclass instance, developers can call the methods in the base class without having to consider which subclass instance is returned.

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.