Java Study Notes
1. What are the aspects of object-oriented features
(1) Abstract:
Abstraction is about ignoring aspects of a topic that are not related to the current goal, so that you can more fully focus on the aspects that are relevant to the current goal. Abstractions do not intend to understand all of the problems, but simply select one part of them, temporarily without some detail. Abstract includes two aspects, one is the process abstraction, the other is the data abstraction.
(2) Inheritance:
Inheritance is a hierarchical model of a junction class and allows and encourages the reuse of classes, which provides a way to articulate commonalities. A new class of objects can be derived from existing classes, a process known as class inheritance. The new class inherits the attributes of the original class, which is called the derived class (subclass) of the original class, and the original class is called the base class of the new class (The parent Class). Derived classes can inherit methods and instance variables from their base classes, and classes can modify or add new methods to make them more suitable for special needs.
(3) Package:
Encapsulation is the process and data is surrounded, access to data only through the defined interface. Object-oriented computing begins with this basic concept that the real world can be portrayed as a series of fully autonomous, encapsulated objects that access other objects through a protected interface.
(4) Polymorphism:
Polymorphism refers to allowing objects of different classes to respond to the same message. Polymorphism consists of parameterized polymorphism and inclusion polymorphism. Polymorphism language has the advantage of flexibility, abstraction, behavior sharing and code sharing, which solves the problem of application function with the same name.
2. Is string the most basic data type?
The basic data types are byte, int, char, long, float, double, Boolean, and short. The Java.lang.String class is of the final type, so you cannot inherit the class or modify the class. To improve efficiency and save space, we should use the StringBuffer class.
3. What is the difference between int and Integer
Java offers two different types: reference types and primitive types (or built-in types). int is the raw data type of Java, and integer is the wrapper class provided by Java for Int. Java provides a wrapper class for each primitive type.
Raw type Encapsulation class
Booleanboolean charcharacter bytebyte shortshort intinteger longlong floatfloat doubledouble
The behavior of reference types and primitive types is completely different, and they have different semantics. Reference types and primitive types have different characteristics and usages, including: size and speed
degree problem, which type of data structure is stored as the default value that is specified when the reference type and the original type are used as instance data for a class. Object reference instance variable
defaults to NULL, and the default values of the primitive type instance variables are related to their type.
4. The difference between String and StringBuffer
The JAVA platform provides two classes: string and StringBuffer, which can store and manipulate strings, which are character data that contain 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 going to change. Typically, you can use Stringbuffers to dynamically construct character data.
5. What are the similarities and differences between abnormal operation and general anomaly?
An exception represents an unhealthy state that may occur during a program's run, and a run-time exception that represents an exception that may be encountered in a typical operation of a virtual machine is a common run error. The Java compiler requires the method to declare a non-runtime exception that might occur, but does not require that a runtime exception that is not caught to be thrown must be declared.
6. Speak the life cycle of the servlet and tell the difference between servlet and CGI.
When the servlet is instantiated by the server, the container runs its Init method, the service method is run when the request arrives, and the service method automatically dispatches the Doxxx method (Doget,dopost) corresponding to the request, etc. The Destroy method is called when the server decides to destroy the instance.
The difference from CGI is that the servlet is in a server process, it runs its service method in a multithreaded manner, one instance can serve multiple requests, and its instances are generally not destroyed, and CGI generates a new process for each request, which is destroyed after the service is completed. So the efficiency is lower than the servlet.
7, say Arraylist,vector, LinkedList storage performance and characteristics
Both ArrayList and vectors use arrays to store data, which is larger than the actual stored data in order to add and insert elements, both of which allow the element to be indexed directly by ordinal, but the insertion element involves memory operations such as array element movement, so the index data is fast and the data is inserted slowly. Vector because of the use of the Synchronized method (thread-safe), usually performance is worse than ArrayList, and LinkedList using a doubly linked list for storage, index data by ordinal need to be forward or backward traversal, but when inserting data only need to record the item before and after items can be , so the insertion speed is faster.
8. What technology is EJB based on? And say the difference between Sessionbean and Entitybean, Statefulbean and Statelessbean.
EJB includes session bean, Entity Bean, Message driven bean, which is implemented based on Jndi, RMI, Jat and so on.
Sessionbean is used in the Java EE application to perform some server-side business operations, such as accessing the database and invoking other EJB components. Entitybean is used to represent
Data used in the system.
For a client, Sessionbean is a non-persistent object that implements some business logic that runs on the server.
For a client, Entitybean is a persistent object that represents an object view of an entity stored in persistent storage, or an entity implemented by an existing enterprise application.
The session bean can also be subdivided into Stateful session bean and stateless Sessionbean, both of which can execute the system logic in the method, the difference is Stateful S The ession bean can record the status of the caller, so usually a consumer will have a corresponding entity of the stateful Session Bean. Stateless session Bean is also a logical component, but he is not responsible for recording the user state, that is, when the user calls the stateless Session bean, the EJB Container does not find a specific stateless The entity of the Session Bean to execute this method. In other words, it is likely that several users will be executing the Instance of the same bean when executing the methods of a stateless Session bean. In terms of memory, the Stateful session bean compared to stateless sessionbean, the statefulsession bean consumes more memory from the Java EE Server, but Stateful session The Bean's advantage is that he can maintain the user's state.
9. The difference between Collection and collections.
Collection is the ancestor interface of the collection class, and the main interface for inheriting it is set and list.
Collections is a helper class for a collection class that provides a series of static methods for searching, sorting, threading, and so on for various collections.
10, the difference between & and &&.
& is a bitwise operator that represents the bitwise AND Operation,&& is a logical operator that represents the logical and (and).
11. The difference between HashMap and Hashtable.
HashMap is a lightweight implementation of Hashtable (non-thread-safe implementation), they all complete the map interface, the main difference is that the HASHMAP allows null (NULL) key value (key), because of non-thread security, the efficiency may be higher than Hashtable.
HashMap allows NULL to be used as a entry key or value, and Hashtable is not allowed.
HashMap hashtable contains method removed, changed to Containsvalue and ContainsKey. Because the contains method is easy to cause misunderstanding.
Hashtable inherits from the dictionary class, and HashMap is an implementation of the map interface introduced by Java1.2.
The biggest difference is that the Hashtable method is synchronize, and HashMap is not, when multiple threads access Hashtable, they do not need to synchronize their methods, and HashMap must provide external synchronization.
The Hash/rehash algorithms used by Hashtable and HashMap are probably the same, so there is no big difference in performance.
12, final, finally, finalize the difference.
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.
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 provide additional resources for garbage collection
Recycling, such as closing files.
13. What is the difference between sleep () and wait ()?
Sleep is a thread-class method that causes this thread to pause execution for a specified time, giving the execution opportunity to other threads, but the monitoring state remains and is automatically restored after that time. Calling sleep does not release the object lock.
Wait is a method of the object class that calls the wait method on this object to cause this thread to discard the object lock, enter the waiting lock pool waiting for this object, and only after the Notify method (or Notifyall) is issued for this object the thread enters the object lock pool ready to get the object lock into the running state.
14, the difference between overload and override. Can the overloaded method change the type of the return value?
The overridden overriding and overloaded overloading of a method are different manifestations of Java polymorphism. Overriding overriding is a representation of polymorphism between a parent class and a subclass, and overloading overloading is a representation of polymorphism in a class. If you define a method in a subclass that has the same name and arguments as its parent class, we say that the method is overridden (overriding). When an object of a subclass uses this method, the definition in the subclass is called, and for it the definition in the parent class is "masked". If more than one method with the same name is defined in a class, they either have a different number of arguments or have different parameter types, which is called a method overload (overloading). The overloaded method is to change the type of the return value.
15. What is the difference between error and exception?
Error indicates a serious problem in situations where recovery is not impossible but difficult. For example, memory overflow. It is impossible to expect the program to handle such situations.
Exception represents a design or implementation issue. That is, it means that if the program runs normally, it never happens.
16. What are the similarities and differences between synchronous and asynchronous, and under what circumstances are they used separately? An example is described.
If the data will be shared between threads. For example, the data being written may be read by another thread later, or the data being read may have been written by another thread, then the data is shared and must be accessed synchronously.
When an application calls a method that takes a long time to execute on an object and does not want the program to wait for the method to be returned, it should use asynchronous programming, which is often more efficient in many cases with asynchronous approaches.
17. What is the difference between abstract class and interface?
A class that declares the existence of a method and does not implement it is called an abstract class, which is used to create a class that embodies some basic behavior, declares a method for that class, but does not implement the class in that class. An instance of the abstract class cannot be created. However, you can create a variable whose type is an abstract class that points to an instance of a specific subclass. Cannot have abstract constructors or abstract static methods. The subclasses of the abstract class provide implementations for all abstract methods in their parent class, otherwise they are also abstract classes. Instead, implement the method in the subclass. Other classes that know their behavior can implement these methods in the class.
An interface (interface) is a variant of an abstract class. In an interface, all methods are abstract. Multiple inheritance can be obtained by implementing such an interface. All the methods in the interface are abstract, without a program body. An interface can only define static final member variables. The implementation of an interface is similar to a subclass, except that the implementation class cannot inherit the behavior from the interface definition. When a class implements a special interface, it defines the method (which is given by the program body) to all such interfaces. It can then invoke the interface's method on any object that implements the interface's class. Because of an abstract class, it allows you to use the interface name as the type of the reference variable. The usual dynamic binder will take effect. References can be converted to an interface type or from a
Port type conversion, the instanceof operator can be used to determine whether the class of an object implements an interface.
18. What is the difference between heap and stack?
A stack is a linear collection whose actions to add and delete elements should be completed in the same paragraph. The stack is processed in a last-in, first-out manner.
A heap is a constituent element of a stack.
19. The difference between forward and redirect
Forward is the server requests the resource, the server directly accesses the URL of the destination address, reads the response content of that URL, and then sends the content to the browser, the browser does not know where the server sends the content from, so its address bar is the original address.
Redirect is the server based on logic, send a status code, tell the browser to request the address again, in general, the browser will use all the parameters just requested again, so the session,request parameters can be obtained.
Java Basics-01