Java Interview Summary

Source: Internet
Author: User

1. What is the difference between a static variable and an entity variable?
Static is statically variable, and static can be accessed directly through the class name
Memory differences: When static is defined, the JVM allocates space,
The entity variable allocates space only when the object is created

2, int integer difference?
Integer is the wrapper class for Int.
An Integer is an object, and the default value for Null,int is 0

3, the difference between public protected friendly private?
Currently similar to a package inheriting class different packages
Public√ok OK OK
Protected√ok OK no
Friendly√ok No No
Private√no No No

4. What is the difference between overloading and rewriting?
Overload overloads: Method names are the same, parameters are different
Overwrite rewrite: The rewriting 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?
Services that the enterprise publishes can be accessed over the Internet and invoked now.
Hardware platforms, operating systems, and programming languages to implement services
The main composition has Wsdl:web service Description language

7. What are the characteristics of SOA?
can be reused
Loose coupling

8, WebService
JAX-ws
Cxf

9, the difference between abstract class and ordinary class:
The only difference between an abstract class and a normal class is that you cannot create an instance object and allow an abstract method;

10, the difference between abstract class and interface:
Abstract class and interface are two of the ways in which abstractions are defined in the Java language, and there is a great similarity between them.
But the choice of them often reflects the understanding of the nature of the concepts in the problem domain, the correct reflection of the design intent,
reasonable, as they represent the different relationships between concepts (though they are capable of fulfilling the requirements of the function).
This is actually a kind of language of the customary law.
To summarize a few words:
Abstract classes and interfaces cannot be instantiated directly, and if instantiated, the abstract class variable must point to the subclass object that implements all the abstract methods.
The interface variable must point to the class object that implements all the interface methods.
Abstract classes are inherited by subclasses, and interfaces are implemented by classes.
Interface can only do method declaration, abstract class can do method declaration, can also do method implementation
The variables defined in the interface can only be public static constants, and the variables in the abstract class are ordinary variables.
Abstract methods in abstract classes must all be implemented by the quilt class, and if the subclass cannot fully implement the parent class abstract method, then the subclass can only be an abstract class.
Similarly, when an interface is implemented, if the interface method cannot be fully implemented, then 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 there is an abstract method in a class, then this class can only be an abstract class
Abstract methods are implemented, so they cannot be static or private.
Interfaces can inherit interfaces and can inherit multiple interfaces, but a class can inherit only one root.

Inversion of control: to eliminate the application's dependency on plug-in implementations, dependency injection is not the only option
IOC: Dependency Injection: There are three main types of dependency injection,
I call them the constructor injection (Constructor injection), respectively.
Set Value method Injection (Setter injection)
and interface Injection (Interface injection).
If you have read some recent discussions about the IOC, it is easy to see:
The three injection forms are type 1 IOC (interface injection), type 2 IOC (set value method injection), and type 3 IOC (constructor injection).

The so-called AOP, Aspect orientied program, is aspect-oriented programming,
2. Explain what is the aspect: a system that runs through the various modules of the system one function is one aspect,
For example, logging, unified exception handling, transaction processing, and full-limit checking are all software systems
A face, not a point, appears in each module.
3. What is aspect-oriented programming: The function of one aspect of the system is encapsulated into an object form to handle
4. How to do aspect-oriented programming: the function module corresponding to the object as a tangent plane embedded in the original system modules,
With proxy technology, the agent invokes the target and joins the code (object) of the tangent function, so
When you configure a proxy object with spring, you need to have two attributes, representing both the target and the slice object (Advisor).

The IOC is the instance interface or instance class that is given to the IOC container (if the factory model is understood as an IOC, there is no problem)

AOP is the weaving technology, plainly, want to achieve the effect is before the method execution, execution, post-execution dynamic insertion method
First of all, AOP, the principle is very simple, is to wrap the instance of your return, the example of each method before adding a method,
Without the IOC here, the implementation will be exposed to the programmer, and after joining the IOC, it will be perfect.
The process is that the IOC goes to the instance object and then calls the AOP program on the instance to re-wrap the object.
The final object returned to the programmer is the wrapped object, so simple. As for how to achieve, there are many ways
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
To give the object to container management, you only need to configure the appropriate bean in the spring configuration file, and set the related properties so that the spring container generates the class's instance object and manages the object. When the spring container is started, spring will initialize the beans you configured in the config file, and then, when you need to call, assign the beans that are already initialized to the class you need to call them (assuming the class name is a), The method of allocation is to call a setter method to inject, without needing you to new these beans in a.
Note: In the interview, if there is a condition, draw, it seems that you understand
AOP: Plane-oriented programming. (Aspect-oriented programming)
AOP can be said to complement and improve OOP. OOP introduces concepts such as encapsulation, inheritance, and polymorphism to create an object hierarchy that simulates a collection of public behavior. When we need to introduce public behavior to scattered objects, oop seems powerless. In other words, OOP allows you to define relationships from top to bottom, but it is not appropriate to define left-to-right relationships. such as logging capabilities. Log code is often spread horizontally across all object hierarchies, and has nothing to do with the core functionality of the objects it spreads to. In OOP design, it leads to a lot of duplication of code, which is not conducive to the reuse of each module.
The cross-business logic in the program (such as security, logs, transactions, etc.) is encapsulated into a slice and then injected into the target object (the specific business logic).

The implementation of AOP technology, mainly divided into two categories: first, the use of dynamic Agent technology, the use of interception of messages to decorate the message to replace the original object behavior, the second is the use of static weaving, the introduction of a specific syntax to create "aspects", so that the compiler can be woven into the relevant "aspects" The Code
Simply explain that you want to add a print ' hello ' function to all classes in your Biz layer, which you can do with AOP, you write a class to write a method, the method is implemented to print ' Hello ' so that your IOC class ref= "biz.*" so that each class is injected.

Database various connection differences:
Left Join,right Join,inner join (join)
The left join is relative to right join:
Basic example: SELECT * FROM table1 T1 left join table2 t2 on t1.col1 = t2.col2;
The result of this time is: all the Table1, the table2 part of the collection
If you want to find all the collections of table2: You can use RIGHT join:
SELECT * FROM table1 T1 right join table2 t2 on t1.col1 = t2.col2;
Inner JOIN is exactly the same as join and looks for the intersection of two tables.
SELECT * FROM table1 t1 inner joins table2 t2 on t1.col1 = t2.table2 where t1.id = 1;

The basic data types are byte, int, char, long, float, double, Boolean, and short.
Nine major package categories: byte,integer,char,long,float,double,boolean,short,string;

How threads are implemented:
Inherits the thread class, implements the Runnable interface, realizes through the thread pool way

The difference between the sleep (), Wait () methods:
Sleep () The current thread pauses execution, yielding the CPU resources to other threads to execute, the monitoring state remains the same, but sleep () does not discard the object lock.
Wait () The current thread discards the object lock and enters the wait state, which can only be awakened when notify.
However, sleep () will enter execution state immediately after the thread executes.

Differences between Java basic types and encapsulation classes
1. The base type can only be passed by value, and the encapsulated class corresponding to each base 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 heap (the object's references are created on the stack).
3. The appearance of the encapsulation class is to make it easier to use some basic types of methods that are not available, such as valueof (), toString (), and so on.
4. If you want to pass a reference to an int object instead of a value, you can only use the encapsulated class.
5. Basic data can be automatically encapsulated into the package class, the basic data type of the advantage is fast (not related to the construction and recycling of objects), the purpose of encapsulation class is to better handle the conversion between the data, many methods, easy to use.

[The efficiency of the call to allocate memory on the stack and the allocation of memory on the heap is much worse.] While allocating memory on the stack is highly efficient, there is a memory leak on the stack. ]

23 Design Patterns in Java:
Factory (Factory mode), builder (build mode), Factory method (factory approach mode),
Prototype (original model mode), Singleton (singleton mode), facade (façade mode),
Adapter (adapter mode), Bridge (bridge mode), Composite (synthetic mode),
Decorator (decorative mode), Flyweight (enjoy meta mode), proxy (proxy mode),
Command (order mode), interpreter (interpreter mode), Visitor (visitor mode),
Iterator (iterative sub-mode), Mediator (mediator mode), Memento (Memo mode),
Observer (Viewer mode), State (status mode), strategy (policy mode),
Template method (pattern mode), Chain of responsibleity (responsibility chain mode)
Factory mode: Factory mode is a frequently used pattern, and classes implemented according to the factory pattern can generate an instance of a class in a set of classes based on the data provided, usually this group of classes have a common abstract parent class and implement the same method, but these methods have different operations for different data. First, you need to define a base class in which subclasses implement methods in the base class in different ways. Then you need to define a factory class where the factory class can generate different subclass instances based on the criteria. When an instance of a subclass is obtained, the developer can call a method in the base class without having to consider which instance of the subclass is returned.

Java Interview Summary

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.