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
Boolean Boolean
Char Character
Byte Byte
Short short
Int Integer
Long Long
Float float
Double Double
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.
Redirect is the server according to the logic, send a status code, telling the browser to re-request that address, generally saying that the browser re-requests all the parameters just requested, so session, the request parameter can be obtained. 20. The difference between EJB and Java Bean?
Java bean is a reused component that does not have a strict specification for Java Bean. In theory, any Java class can be a bean. In general, since the Java bean is created (such as Tomcat) by the container, the Java Bean should have a 11-free constructor, in addition, the Java Bean also implements the Serializable interface to implement the persistence of beans. Java Bean is actually equivalent to the COM component in the local process in the Microsoft COM model, which cannot be accessed across the process. Enterprise Java Bean is equivalent to DCOM, ie distributed components. It is based on Java-based remote method call (RMI) technology, so EJB can be remotely accessed (cross processes, cross-computers). But EJB must be deployed in a container such as WebSpere, WebLogic, and EJB customers never access true EJB components, but access them through their container. The EJB container is an agent of EJB components, and the EJB component is created and managed by the container. The client accesses the real EJB component through the container.
21, Static Nested Class and Inner Class are different.
Static NESTED CLASS is an internal class that is declared as static (STATIC), which can not depend on external class instances being instantiated. The usual internal classes need to be instantiated after instantification of external classes.
22. Different Dynamic Include and Static Include in JSP?
Dynamic include uses JSP: Include action to implement
Static include uses the incrude pseudo code, which does not check the change of the file included, suitable for containing the static page <% @ include file = "incruded.htm"%>
23, when is it using Assert.
Assertion is a commonly used commissioning in software development, and this mechanism is supported in many development languages. In the implementation, Assertion is a statement in the program that checks a Boolean expression. A correct program must ensure that this Boolean expression is true; if the value is false, the program is already in an incorrect state. Next, the system will give a warning or exit. In general, Assertion is used to ensure the most basic and key correctness of the program. Assertion checks are usually opened when developed and tested. In order to improve performance, the assertion check is usually closed after the software is released.
24, what is GC? Why do you have GC?
GC is the meaning of garbage collection. Memory processing is where programmers are prone to problems, forget or erroneous memory recovery causes the unstable or even crash of the program or system, and the GC function provided by Java can automatically monitor the object. The purpose domain thus reaches the purpose of automatic recovery memory, and the Java language does not provide a display operation method that releases the allocated memory.
25, short s1 = 1; S1 = S1 1; What is wrong? SHORT S1 = 1; S1 = 1; What is wrong?
Short S1 = 1; S1 = S1 1; (S1 1 calculation result is an INT type, requires forced conversion type) Short S1 = 1; S1 = 1; (can correctly compile)
26, Math.Round (11.5) Is it equal to Math.Round (-11.5)?
Math.Round (11.5) == 12
Math.Round (-11.5) == - 11
The Round method returns a long integer that is closest to the parameters, and the parameter plus 1/2 is followed by its floor.
27, string s = new string ("xyz"); created a few String Object?
Two
28, design 4 threads, two threads increase 1 each time, and two threads are reduced each time. Write the program.
The following procedure uses internal classes to implement threads, and no order issues are not considered when J is reduced.
Public class threadtest1 {
Private int J;
Public static void main (string args []) {
Threadtest1 TT = New Threadtest1 ();
INC = TT.NEW INC ();
Dec dec = tt.new dec ();
For (int i = 0; i <2; i ) {
Thread T = New Thread (INC);
T.Start ();
T = New Thread (DEC);
T.Start ();
}
}
Private synchronized void inc () {
J ;
System.out.println (thread.currentthread (). GetName () "- inc:" J);
}
Private synchronized void dec () {
J -;
System.out.println (thread.currentthread (). GetName () "- DEC:" J);
}
Class incblements runnable {
Public void run () {
For (int i = 0; i <100; i ) {
INC ();
}
}
}
Class Dec Implements Runnable {
Public void run () {
For (int i = 0; i <100; i ) {
DEC ();
}
}
}
}
29, have Java goto?
The reserved word in Java is now not used in Java.
30. Start a thread is Run () or start ()?
Starting a thread is to call the start () method so that the virtual process representing the thread is in operation, which means it can be scheduled and executed by the JVM. This doesn't mean that the thread will run immediately. The Run () method can generate a flag that must be exited to stop a thread.
31, EJB includes (sessionbean, entitybean) says their life cycle, and how to manage transactions?
The lifecycle of the STASSIONBEAN: STATELESS session bean is determined by the container. When the client issues a request to establish a bean instance, the EJB container does not have to create a new bean instance for client call, but a place to find a present Some instances are provided to the client. When the client calls a stateful session bean for the first time, the container must immediately create a new bean instance in the server, and related to the client, after this client calls the Stateful session bean method, the container will assign the call to This client is associated with a bean instance. EntityBean: Entity Beans can survive relatively long time, and status is continuous. Entity Beans has always survive as long as the data in the database exists. Not in accordance with the application or service process. Even if the EJB container crashes, Entity Beans is also survived. The Entity Beans life cycle can be managed by the container or Beans.
EJB is implemented by the following technical management practices: Object Management (OMG) Object Service (OTS), Sun Microsystems Transaction Service (JTS), Java Transaction API (JTA), Development Group (X / Open) XA interface.
32. What are the application servers?
BEA WebLogic Server, IBM WebSphere Application Server, Oracle9i Application Server, Jboss, Tomcat
33. Give me a Runtime Exception you most often.
ArithmeticException, ArrayStoreException, BufferOverflowException, BufferUnderflowException, CannotRedoException, CannotUndoException, ClassCastException, CMMException, ConcurrentModificationException, DOMException, EmptyStackException, IllegalArgumentException, IllegalMonitorStateException, IllegalPathStateException, IllegalStateException, ImagingOpException, IndexOutOfBoundsException, MissingResourceException, NegativeArraySizeException, NoSuchElementException, NullPointerException, ProfileDataException, ProviderException, RasterFormatException, SecurityException, SystemException, undeclaredthrowableException, unmodifiableseteexception, unsupportedopertyException
34. Can an interface be inherited? Is the abstract class to implement (IMPLEMENTS) interface? Does the abstract class can inherit the physical classes (Concrete Class)?
The interface can inherit the interface. Abstract classes can be implemented, whether abstract classes can inherit physical classes, but provided that the entity class must have a clear constructor.
35, LIST, SET, MAP inherit from a Collection interface?
List, set is, MAP is not 36, what is the working mechanism of the data connection pool?
The J2EE server is started to establish a certain number of pool connections and maintaining no less than this number of pool connections. When the client program needs to be connected, the pool driver returns an unused pool connection and exposes its expression as busy. If there is currently no idle connection, the pool driver has created a certain number of connections, and the number of new connections has configured parameters. When the pool connection call is used, the pool driver is idle, and this connection can be used in other calls.
37. Is Abstract's method can be static, whether it can be native at the same time, is it SYNCHRONIZED?
both are not
38. Is there a length () method? String has a length () method?
The array does not have Length () method, with the properties of the length. String has a length () method.
39, the elements in the set cannot be repeated, then what method is used to distinguish whether it is repeated? Is it == or equals ()? What is the difference?
The elements in the set cannot be repeated, then use the iterator () method to distinguish whether you are repeated. Equals () is the judgment of whether two SETs are equal.
Equals () and == Method Decide whether the reference value points to the same object Equals () override in the class, which is the true value of the content and type of two separate objects.
40. Is the constructor CONSTRUCTOR can be Override?
The constructor constructor cannot be inherited, so Overriding cannot be overridden, but Overloading can be overloaded.
41, can you inherit the String class?
The String class is that the final class cannot be inherited.
42. If SWTICH can act on Byte, whether it can act on long, can it work on String?
Switch (expr1), expr1 is an integer expression. Therefore, the parameters passing to the Switch and the CASE statement should be int, short, char or byte. Long, String can not work on SWTICH.
43, Try {} has a return statement, then the code in finally {} after this try is not executed, when is executed, before returnome or after?
Will be executed, execute before return.
44. Programming: 2 multiplied 8 equal to a few with the most efficient method?
2 << 3
45, the two object values are the same (x.equals (y) == true, but there can be different haveh codes, this sentence is wrong?
No, there is the same Hash Code.
46. After an object is passed as a parameter to a method, this method can change the properties of this object and return the resulting result, then here is the value delivery or reference delivery?
It is a value transfer. Java programming languages only value pass parameters. When an object instance is transmitted to the method as a parameter, the value of the parameter is a reference to the object. The content of the object can be changed in the called method, but the reference to the object will never change.
47. After a thread enters an SYNCHRONIZED method of an object, can other threads can enter other methods of this object?
No, a Synchronized method of an object can only be accessed by one thread.
48. Program: Write a Singleton out.
The main role of the Singleton mode is to ensure that only one example exists in a Java application.
General Singleton mode usually has several forms:
The first form: Define a class, its constructor is private, it has a type of PRIVATE for a Static, an instantimeter of the class initialization, get a reference to it through a public GetInstance method, then call it Methods. Public class singleton {
Private kindleton () {}
// Is it very strange to define an instance inside yourself?
// Note this is Private only for internal calls
Private static singleleton instance = new singleleton ();
/ / Here is a static method for accessing this Class, you can directly access
Public static singleleton getinstance () {
Return Instance;
}
}
The second form:
Public class singleton {
Private static singleton instance = null;
Public static synchronized singleton getInstance () {
// This method has been improved above, and it is only the first time.
// Generate an instance when using it, improve efficiency!
IF (instance == null)
Instance = new singleleton ();
Return Instance;}
}
Other forms:
Define a class, its constructor is private, all methods are static.
It is generally considered that the first form is more secure.
49, Java interface and the same and different placements of C .
Since Java does not support multi-inheritance, it is possible to use a class or object to use a method or attribute in several classes or objects, and existing single inheritance mechanisms cannot meet the requirements. Compared to inheritance, the interface has higher flexibility because there is no implementation code in the interface. When a class implements an interface, this class is to implement all methods and properties in the interface, and the properties in the interface are all public static below, all methods are public. Public. A class can implement multiple interfaces.
50. Simple principle and application of exception handling mechanism in Java.
When the Java program violates the semantic rules of Java, the Java virtual machine will represent an error as an exception. Violation of semantic rules include 2 cases. One is a semantic check in the Java class library. For example, the array subscript can trigger indexoutofboundsexception; nullpointerException will be triggered when accessing null objects. Another situation is that Java allows programmers to extend this semantic check, and programmers can create their own exceptions and freely choose to trigger exceptions with throw keywords. All exceptions are subclasses of java.lang.thowable.
51, the advantages and principles of garbage collection. And consider 2 recycling mechanisms.
A significant feature in the Java language is to introduce the garbage collection mechanism, which makes the problem of the most headache of C programmers, making the Java programmers no longer need to consider memory management when writing programs. Since there is a garbage collection mechanism, the object in Java no longer has the concept of "scope", and only the reference to the object has a "scope". Garbage recycling can effectively prevent memory leaks, effective use of memory that can be used. The garbage collector is usually operated as a separate low-level thread. In the case of unpredictable objects that have been died or have not used for a long time for a long time for a long time, the programmer cannot call the garbage collector in real time. Object or all objects are garbage collection. The recycling mechanism has a replica collection of garbage collection and marking garbage recovery, incremental garbage recovery.
52. Please tell us how the thread synchronization you know.
Wait (): Make a thread in the waiting state and release the LOCK of the object held. Sleep (): Make a running thread in sleep state, is a static method, call this method to capture InterruptedException exceptions.
NOTIFY (): Wake up a thread in a waiting state, note that when this method is called, it is not exactly the thread that is awakened, but is determined by the JVM which thread is awake, and is not pressed.
AllNotity (): Wake all threads in the waiting state, not to give all the locks of all awakening threads, but let them compete.
53, what are your collection? Main method?
The most commonly used collections are LIST and MAP. The specific implementation of List includes ArrayList and Vector, which are variable-sized lists, which are more suitable for build, store, and operate any type of objects for any type object. List is suitable for use in value to access elements.
Map provides a more versatile element storage method. The MAP set class is used to store element pairs (called "keys" and "value"), where each key is mapped to a value.
54, describe the principle mechanism of JVM loading Class files?
The loading of the JVM is implemented by ClassLoader and its subclass, and Java ClassLoader is an important Java runtime system component. It is responsible for finding and putting a class file at runtime.
55. Can a Chinese Chinese character can be stored in the char type variable? Why?
It can be defined as a Chinese, because Java is encoded in Unicode, a char accounts for 16 bytes, so putting a Chinese is no problem.
56. There are several implementation methods for multi-threading. What are you doing? How many implementation methods are there?
Multi-thread has two implementation methods, which are inherited the Thread class and implementing the Runnable interface.
There are two implementations in synchronization, Synchronized, Wait and Notify, respectively.
57, the built-in object and method of JSP.
Request represents the HTTPSERVLETREQUEST object. It contains information about the browser request and provides a number of methods for obtaining cookie, header, and session data.
Response represents the HTTPSERVLETRESPONSE object and provides several methods for setting the response to the browser (such as cookies, header information, etc.)
The OUT object is an instance of Javax.jsp.jspwriter, and provides several ways to make you use to return the output results to your browser.
PageContext represents a javax.servlet.jsp.pageContext object. It is an API for convenient access to various range spaces, servlet-related objects, and wraps a generic Servlet related feature.
Session represents a request Javax.Servlet.http.httpSession object. SESSION can store the status information of the user
Applicat represents a Javax.serve.ServletContext object. This helps find information about the Servlet engine and the servlet environment
Config represents a javax.servlet.ServletConfig object. This object is used to access the initialization parameters of the servlet instance.
Page Represents a servlet instance generated from this page
58. The basic concept of thread, the basic state of the thread and the relationship between state
Thread refers to an execution unit that can execute program code during execution, and each program has at least one thread, which is the program itself.
There are four states in Java, respectively, running, ready, hang, and end.
59, common instructions for JSP
<
% @ Page language = "java" contenType = "text / html; charset = gb2312" session = "true" buffer = "64kb" autoFlush = "true" isThreadSafe = "true" info = "text" errorPage = "error.jsp "ISerrorPage =" true "iSelignored =" true "pageEncoding =" gb2312 "import =" java.sql. * "%> ISERRORPAGE (Can I use Exception object), iSelignored (ignore the expression)
<
% @ include file = "filename"%>
<
% @ taglib prefix = "c" uri = "http: // ..."%>
60. What is calling doget () and dopost ()?
The Method property in the FORM tag in the JSP page is called DOGET (), and dopost () is called for POST.