Java related basics (1)

xiaoxiao2021-03-06  13

Java related basics

1. What are the object-oriented features?

Abstract:

Abstraction is to ignore those aspects that have nothing to do with current goals in a topic in order to pay more attention to aspects related to current goals. Abstract does not intend to understand all the questions, but just choose some of them, temporarily do not use some details. Abstract includes two aspects, one is abstract, and the other is data abstraction.

2. Inherit:

Inheritance is a hierarchical model of a joint, and allows and encourages the reuse of classes, which provide a clear expression of a commonality. A new class of an object can be derived from the existing class, which is called class inheritance. New categories inherit the characteristics of the original class, the new class is called the original class (subclass), and the original class is called a new class (parent class). Detective classes can inherit methods and instance variables from its base class, and class can modify or add new methods to make it more suitable for special needs.

3. Package:

The package is surrounded by processes and data, and access to data can only pass through the defined interface. Object-oriented calculations began in this basic concept, that is, the real world can be depicted into a series of complete autonomous, encapsulated objects, which access other objects through a protected interface.

4. Polymorphism:

Polymorphism refers to allowing different types of objects to respond to the same message. Polymorphisms include parameterized polymorphisms and polymorphisms. The polymorphic language has the advantages of flexible, abstract, behavioral sharing, code sharing, and well solves the application function of the same name.

2, is String a basic data type?

Basic data types include Byte, int, char, long, float, double, boolean, and short.

The java.lang.string class is final type, so this class cannot be inherited, and this class cannot be modified. In order to improve efficiency, we should use the StringBuffer class

3. What is the difference between int and integer?

Java offers two different types: reference types and original types (or built-in types). INT is the original data type of Java, and Integer is a package class provided by Java for INT. Java provides package classes for each original type.

Original type package

BooleanBoolean

Charcharacter

BYTEBYTE

Shortshort

Intinteger

Longlong

Floatfloat

Doubledouble

The reference type and the original type of behavior are completely different, and they have different semantics. Reference Types and Original Types have different features and usage, including: size and speed problems, this type of data structure store, when the reference type and the original type are used as an instance data of a class Default. The default value of the object reference instance variable is NULL, and the default value of the original type instance variable is related to their type.

4, String and StringBuffer difference

The Java platform provides two classes: String and StringBuffer, which can store and operate strings, which contain characters data of multiple characters. This String class provides a string of values ​​that cannot be changed. The string provided by this StringBuffer class is modified. You can use StringBuffer when you know that character data is changed. Typically, you can use StringBuffers to dynamically construct character data.

5. What is the difference between abnormality at runtime?

An abnormality indicates the abnormal state of the program during operation, and the runtime exception indicates an exception that may be encountered in the usual operation of the virtual machine is a common run error. The Java compiler requires that the method must declare that the possible non-running abnormality, but does not require a statement that the abnormality that is not captured.

6. Say the life cycle of the servlet and say the difference between servlet and cgi.

After the servlet is instantiated by the server, the container runs its init method, the request is reached, the service method is automatically dispatched with the DOXXX method (Doget, DOPOST) corresponding to the request, and calls its Destroy when the server decides to destroy the instance. method. The difference from the CGI is that the servlet is in the server process, which runs its service method by multithreading, and an instance can serve multiple requests, and its instance is generally not destroyed, and CGI has a new process for each request. After the service is completed, it is destroyed, so it is less efficient than servlet.

7. Say the storage performance and feature of ArrayList, Vector, LinkedList

All ArrayList and Vector are stored in an array. This array element is larger than the actual stored data to increase and insert an element, which allows direct sequence index elements, but inserts an element to involve memory operation such as array elements, so index data Fast and inserted, Vector due to the use of the Synchronized method (thread security), usually more arraylist, and LinkedList uses two-way linked lists to store, and sequence index data needs to be forwarded or rearward, but inserting data only You need to record the front and rear items of this item, so the insert is faster.

8, EJB is based on which technologies are implemented? And said the difference between SessionBean and EntityBean, the difference between STATEFULBEAN and STATELESSBEAN.

EJB includes session beans, Entity Beans, JNDI, RMI, JAT, etc.

SessionBean is used in the J2EE application to complete some server-side business operations, such as accessing the database, calling other EJB components. EntityBean is used to represent the data used in the application system.

For clients, SessionBean is a non-persistent object that implements certain business logic running on the server.

For clients, EntityBean is a persistent object that represents an object view that stores entities in a persistent memory, or an entity implemented by existing enterprise applications.

Session Bean can also be subdivided into Stateful Session Bean with Stateless Session Bean. Both Session beans can perform system logic in Method, and the different is the stateful session bean to record the caller's status, so usually Say, a user will have an entity of a corresponding Stateful Session bean. Although Stateless Session Bean is also a logical component, but he is not responsible for recording the user's state, that is, when the user calls Stateless Session Bean, EJB Container does not look for the specific STATELESS SESSION BEAN entity to perform this Method. In other words, it is very likely that several users are executing the same bean's instance when executing a STATELESS SESSION bean's Methods. From memory, Stateful Session Bean compares the STATELESS SESSION bean, and Stateful Session Bean consumes more memory more than J2EE Server, but the advantage of the Stateful Session bean is that he can maintain the status of the user.

9, the difference between Collection and Collectes. Collection is the superiors of the collection class, inheriting, with his interface, mainly SET and LIST.

Collections is a helper class for the collection class, and he provides a series of static methods to achieve search, sorting, thread security, etc. of various collections.

10, & and &&.

& A bit operator, representing bit and operation, && is a logical operator, representing logic and (AND).

11, the difference between HashMap and HashTable.

HashMap is a lightweight implementation of HashTable (non-thread security), they all completed the MAP interface, mainly distinguishing the HashMap allows empty (NUY) key value (key), due to non-threaded security, efficiency may be higher than HashTable.

Hashmap allows null as a key or value of Entry, while HashTable is not allowed.

Hashmap removes the HashTable's Contains method, changed to ContainSvalue and Containskey. Because the Contains method is easy to cause misunderstandings.

HashTable inherits from the Dictionary class, and HashMap is an implementation of the Map Interface introduced by Java 1.2.

The biggest difference is that the HashTable method is Synchronize, and HashMap is not, when accessed HashTable, does not need to be synchronized for its method, and HashMap must provide external synchronization.

Hash / rehash algorithms used by HashTable and Hashmap are probably, so performance will not have a big difference.

12, Final, Finally, Finalize distinction.

Final is used to declare attributes, methods, and classes, indicate that attributes are unambiguous, and the method is not covered, and the class cannot be inherited.

Finally is part of an exception handling statement structure, which is always executed.

Finalize is a method of the Object class. This method of recycling object is called when the garbage collector is executed, and other resource recycles when this method is available, such as turning off files.

13. What is the difference between SLEEP () and WAIT ()?

Sleep is a thread method, causing this thread to suspend the specified time, give the executive opportunity to other threads, but the monitoring state remains, and will automatically recover. Calling SLEEP does not release the object lock.

WAIT is the object of the object class. Call the WAIT method for this object causes the lecture to abandon the object lock. Enter the waiting lock pool waiting for this object, only the NOTIFY method (or NotifyAll) is issued after this object, after entering the object lock pool ready to get Object locks enter the operating state.

14, the difference between overload and override. Can OVERLOADED methods change the type of return value?

The method of rewriting Overriding and overloading overloading is a different manifestation of Java polymorphism. Overriding Overriding is a manifestation of polymorphism between parent class and subclasses, and overloading overloading is a manifestation in a class. If a method is defined in the subclass with the same name and parameters as its parent class, we say that this method is overriddled. When the subject of subclass uses this method, the definition of the subclass will be called. For it, the definition in the parent class is like "shielded". If a plurality of the same names are defined in a class, they or have different parameters or different parameter types, called overloading. The way OVERLOADED is to change the type of return value. 15. What is the difference between ERROR and EXCEPTION?

Error indicates a serious problem that recovery is not impossible but difficult. For example, memory is overflow. It is impossible to expect the program to handle this situation.

Exception represents a design or implementation problem. That is, it means that if the program runs normally, it will never occur.

16. How is it in synchronization and asynchronous, in what circumstances use them? for example.

If the data will be shared between the thread. For example, the data being written may be read by another thread, or the data being read may have been written by another thread, then the data is shared data, and must be synchronously.

When an application calls a method that takes a long time to perform, it is often used asynchronous programming when it takes a long time to perform, and it is often more efficient in many cases.

17. What is the difference between Abstract Class and Interface?

The presence of a declaration method does not implement its class called abstract class, which is used to create a class that reflects certain basic behavior and declares the class, but cannot implement this class in this class. Case. An instance of the Abstract class cannot be created. However, you can create a variable, which is an abstract class and let it point to an instance of the specific subclass. There is no abstract constructor or abstract static method. Subclasses of the Abstract class provide implementation for all abstraction methods in their parent class, otherwise they are also abstract classes. Instead, this method is implemented in the subclass. Other classes that know their behavior can be implemented in the class.

Interface is a variant of an abstract class. In the interface, all methods are abstract. Multiple inheritance can be obtained by achieving such an interface. All methods in the interface are abstract, no probabilities. The interface can only define the Static Final member variable. The implementation of the interface is similar to the subclass, except that the implementation class cannot inherit behavior from the interface definition. When the class implements a special interface, it defines the method of all such an interface (that is, the program body is given). Then, it can call the interface to call the interface on any object of the class of the interface. Because there is an abstract class, it allows the interface name as the type of reference variable. The usual dynamic cable will take effect. The reference can be converted to an interface type or a slave interface type, and the InstanceOf operator can be used to determine whether an object is implemented.

18. What is the difference between Heap and Stack.

The stack is a linear set, and the operation of adding and deleting elements should be completed in the same paragraph. The stack is processed in the way in which it is advanced.

Pile is a constituent element of the stack

19, the difference between Forward and Redirect

Forward is the server request resource, the server directly accesses the URL of the destination address, reads the response content of that URL, then sending these content to the browser, the browser does not know where the server sent is from, so Its address bar is still the original address.

转载请注明原文地址:https://www.9cbs.com/read-46919.html

New Post(0)