Basic knowledge:
1. Simple principle and application of exception handling mechanism in C or 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
Java.lang.Thow Subclass.
2. The same and different sages of Java interfaces and C virtual classes.
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.
3. 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.
4. Please tell 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.
5. Please talk about the usage and function of the system and virtual functions.
6. What is the difference between ERROR and EXCEPTION?
Error indicates that the system level error and the exception do not have to be processed.
Exception indicates an exception that needs to be captured or needed.
7. A class in Java is declared as a final type, what does it mean?
It is said that the class cannot be inherited, it is a top class.
8. Describe your most common programming style.
9. 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
10. If the system wants to use a large integer (more than the long range), you design a data structure to store this supermoder number and design a algorithm to implement a large integer addition operation).
Public class bigint ()
{
int [] arrone = new arrone [1000];
String IntString = ""; public int [] Arr (String S)
{
INTSTRING = S;
For (int i = 0; i { 11. If you want to design a graphics system, you can design a simple implementation of basic graphics components (Point, Line, Rectangle, Triangle). 12. Talk about the difference between Final, Finally, Finalize. Final-modifier (keyword) If a class is declared as Final, it means that it is no longer a new subclass and cannot be inherited as a parent class. Therefore, a class cannot be declared as Abstract, and it is declared as final. Declaring variables or methods to Final, ensuring that they are not changed in use. Variables that are declared for final must give initial values at the time of declaration, and only read in future references, cannot be modified. The method that is declared for Final is also available, and it is not overloaded. Finally- provides a Finally block when processed. If you throw an exception, then the matching catch clause will execute, and then the control will enter the Finally block (if any). Finalize-method name. Java technology allows the use of the Finalize () method to make the object to clear the object from the memory before making the necessary cleanup work. This method is called by the garbage collector when it is determined that this object is not referenced. It is defined in the Object class, so all classes have inherited it. Subclasses override the Finalize () method to organize system resources or perform other cleanup work. The Finalize () method is called by this object before the garbage collector deletes the object. 13, anonymous inner class (anonymous internal class) can be extends other classes, can IMPLEMENTS INTERFACE (interface)? The anonymous internal class is an internal class without a name. You cannot extends other classes, but an internal class can be implemented as an interface, and is implemented by another internal class. 14. Static Nested Class and Inner Class are different, the more you say, the better (the interview is very general). NESTED CLASS (generally C statement), Inner Class (typically Java said). The maximum difference between Java internal classes and C nested classes is whether there is a reference to the outside. Specific visible http://www.frontfree.net/articles/services/view.asp?id=704&page=1 Note: Static Inner Class means 1 creation of an object of a Static internal class, does not require an external class object, 2 cannot access an external class object from an object of a Static internal class The difference between fourth, & and &&. & Is a bit operator. && is the Boolean logic operator. 15, the difference between HashMap and HashTable. Both of the MAP interface, implement the unique key to a specific value. The HashMap class is not classified or sorted. It allows a NULL key and multiple NULL values. Hashtable is similar to HashMap, but NULL keys and NULL values are not allowed. It is also slower than HashMap because it is synchronized. 16, the difference between Collection and Collectes. Collections is a class under java.util that contains a variety of static methods related to the collection. Collection is an interface under java.util, which is a parent interface of a variety of collections. 17. When did you use Assert. As an assertion, a statement containing Boolean expression, assuming that the expression is TRUE when this statement is executed. If the expression is calculated as false, then the system will report an AssertionError. It is used to debug purposes: Assert (a> 0); // throws an assertionerror if a <= 0 There are two forms of assertions: Assert Expression1; Assert Expression1: Expression2; Expression1 should always produce a Boolean value. Expression2 can be any expression that draws a value. This value is used to generate a String message displaying more debugging information. As default, it is disabled by default. To enable assertions while compiling, you need to use Source 1.4 tags: Javac -Source 1.4 Test.java To enable assertion at runtime, you can use the -enableassertions or the -ea tag. To disable assertion at runtime, you can use the -DA or the -disableAssertions tag. To enable assertion in the system class, you can use the -esa or -dsa tag. You can also enable or disable assertions on the basis of the package. An assertion can be placed at any position that is not reached in normal conditions. As an assertation can be used to verify the parameters passing to the private method. However, assertions should not be used to verify parameters passing to the public method, as there is no matter whether it is enabled, the public method must check its parameters. However, it can be used in public methods or in a non-public method to use asserts to test the post condition. In addition, the assertion should not change the status of the program in any way. 18. What is GC? Why do you have a GC? (Foundation). GC is a garbage collector. Java programmers don't have to worry about memory management because the garbage collector will automatically manage. To request garbage collection, you can call one of the following methods: SYSTEM.GC () Runtime.getRuntime (). GC () 19, string s = new string ("xyz"); created a few String Object? Two objects, one is "XYX", one is a reference object S pointing to "XYX". 20, Math.Round (11.5) Is it equal to Math.Round (-11.5)? Math.Round (11.5) Returns (long) 12, Math.Round (-11.5) Returns (long) -11; 21, Short S1 = 1; S1 = S1 1; What is wrong? SHORT S1 = 1; S1 = 1; What is wrong? Short S1 = 1; S1 = S1 1; error, S1 is the short type, S1 1 is INT type, cannot explicitly convert to a SHORT type. Can be modified to S1 = (Short) (S1 1). Short S1 = 1; S1 = 1 is correct. 22. What is the difference between SLEEP () and WAIT ()? The SLEEP () method is to stop the thread to stop a period of time. After the SLEEP time interval is full, the thread does not necessarily resume it immediately. This is because at that moment, other threads may be running and are not scheduled to give up execution, unless (a) "wake up" thread has higher priority (b) that is running because of other reasons. Wait () is a thread interaction if the thread issues a wait () call, the thread is suspended, the object is adjusted to the waiting state until it is awake or waiting time. 23, have java goto? The reserved word in Goto-Java is not used in Java. 24. Is there a length () method for arrays? String has a length () method? The array does not have Length () method, with the properties of the length. String has a length () method. 25, 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. 26, the elements in the set cannot be repeated. 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. 27, 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, UnmodifiableSetException, UnsupportedOperationException 28. 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. 29, List, SET, MAP inherits from a Collection interface? List, SET is MAP is not 30. 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. 31. Is Abstract's Method can be static at the same time, whether it is native at the same time, is it SYNCHRONIZED? both are not 32. Is the interface to inherit the interface? Does the abstract class 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. 33. 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. 34. Is the constructor CONSTRUCTOR can be Override? The constructor constructor cannot be inherited, so Overriding cannot be overridden, but Overloading can be overloaded. 35, can you inherit the String class? The String class is that the final class cannot be inherited. 36. After a thread enters an SYNCHRONIZED method of an object, can other threads can enter this object? No, a Synchronized method of an object can only be accessed by one thread. 37, Try {} has a return statement, then the code in finally {} after this try will not be executed, when is executed, before returnome or after? Will be executed, execute before return. 38. Program: 2 multiplied 8 equal to a few with the most efficient method? Programmers with C background especially like to ask this question. 2 << 3 39, the same value is the same (x.equals (y) == true, but there can be different haveh codes, this sentence is wrong? Is wrong, have the same havehing. 40. 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. The Java programming language is only passed by the value. 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. 41, whether 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. 42. Program: Write a Singleton. 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. Hashtable and havehmap HashTable inherits from the Dictionary class, and HashMap is an implementation of Map Interface introduced by Java1.2. Hashmap allows null as a key or value of Entry, and hashtable is not allowed Also, Hashmap removes the HashTable's Contains method, changed to ContainsValue and Containskey. Because the Contains method is easy to cause misunderstandings. The biggest difference is that the HashTable method is SYNCHRONIZE, and Hashmap is not, when accessing the HashTable in multiple threads, does not need to be synchronized for its method, and hashmap It is necessary to provide external synchronization. Hash / rehash algorithms used by HashTable and Hashmap are probably, so performance will not have a big difference. 43. Describe the principle mechanism of JVM loading Class files? 44. Test example illustrates a typical garbage collection algorithm? 45. Use the Java to write the binary algorithm to achieve the addition of data to form a binary tree, and print it in a preface. 46. Please write a Java program to implement the thread connection pool function? 47. Given a C language function, require implementation to call in the Java class. 48, editing a code, realizing after the console input a set of numbers, then exported after the console is output; 49, list all files under a folder; 50. The call system command implements the operation of deleting files; 51. Implementation of a character's operation from a file; 52, list some methods of controlling the process; 53, what are the states of multi-thread? 54. Writing a server-side program implementation is displayed on the client input character and displays on the console until "end" is entered, let you write the client's program; 55, scope public, private, protected, as well as when you write A: The difference is as follows: Scope current class with the same package children, other packages PUBLIC √ √ √ √ Protected √ √ × × Friendly √ √ × × PRIVATE × × × × Do not write, default is Friendly 56, the difference between ArrayList and Vector, the difference between HashMap and HashTable A: ARRAYLIST and VECTOR are mainly from two aspects. I. Synchronization: Vector is a thread safe, that is to say is synchronized, and ArrayList is unsafe line programs, not synchronous. II. Data growth: When you need to grow, Vector default growth is the original one, but ArrayList is half. It is mainly from three aspects on Hashmap and HashTable. I. Historical reasons: HashTable is an implementation of the MAP interface introduced by the Java 1.2 based on the old Dictionary class. II. Synchronization: Hashtable is a thread safe, that is, HashMap is unsafe, not synchronous Three. Values: Only HashMap allows you to take null values as a key or value of a table 57. Can a Chinese Chinese character can be stored in the char type variable? Why? A: It is possible to define a Chinese, because Java is encoded in Unicode, a char accounts for 16 bytes, so a Chinese is no problem. 58. There are several implementation methods. What is it? Synchronize several implementation methods, what is it? A: Multi-thread has two implementation methods, which are inheriting the Thread class and implementing Runnable interface. There are two implementations in synchronization, Synchronized, Wait and Notify, respectively. 59. How to optimize the garbage recovery mechanism? I hope everyone will make up, thank you. 60, FLOAT FLOAT F = 3.4 is it correct? A: Not correct. The accuracy is not accurate, and it should be converted with a mandatory type, as shown below: float f = (float) 3.4 61. Describe the Collection Framework in Java, including how to write your own data structure)? A: The Collection Framework is as follows: COLLECTION ├List │├LINKEDLIST │├ARRAYLIST │ └Vector │ └stack └SET Map ├Hashtable ├Hashmap └weakhashmap Collection is the most basic set interface, a collection represents a set of object, ie the elements of Collection (Elements) Map provides mapping of Key to Value 62. Abnormal processing mechanism in Java, event mechanism? 11. Proffles and inheritance in Java? I hope everyone will make up, thank you. 63, abstract class and interface? A: Abstract class and interface are used for abstraction, but the abstract class (Java) can have its own partial implementation, and the interface is completely an identifier (both multiple inheritance functions). Program: 1. Now enter n numbers, comma, separate; You can then select liter or descending order; Press the submit button to display on another page What is sorted, the result is, RESET Answer (1) Public static string [] splitstringBycomma (string source) { IF (source == null || Source.trim (). Equals ("")) Return NULL; StringTokenizer Commatoker = New StringTokenizer (SOURCE, ","); String [] result = new string [commatoker.countToKens ()]; INT i = 0; While (Commatoker.hasmoreToKens ()) { Result = commatoker.nextToken (); i ; } Return Result; } Cycle traversal String array Integer.Parseint (String S) becomes int type Composition INT array Arrays.sort (int [] a), A array ascending Descending order can start output from the tail 2. The amount conversion, the amount of the Arab figures are converted into Chinese traditional forms such as: (¥ 1011) -> (1 thousand and 1 yuan) output. 3. Inheriting the order of execution of the class is generally a choice question, ask you how to print out? A: Parent class: Package test; Public Class FatherClass { Public FatherClass () { System.out.println ("FatherClass Create"); } } Subclass: Package test; Import Test.fatherClass; Public Class ChildClass Extends FatherClass { Public ChildClass () { System.out.println ("ChildClass Create"); } Public static void main (string [] args) { Fatherclass fc = new fatherclass (); Childclass cc = new childclass (); } } Output results: C:> Java Test.childclass FatherClass Create FatherClass Create CHILDCLASS CREATE4, the implementation of internal classes? A: The sample code is as follows: Package test; Public Class OuterClass { Private class interclass, PRIVATE CLASS Interclass { Public interclass () { System.out.println ("Interclass Create"); } } Public outerclass () { Interclass IC = New Interclass (); System.out.println ("Outerclass Create"); } Public static void main (string [] args) { Outerclass oc = new outerclass (); } } Output result: C:> Java Test / OuterClass Interclass Create OuterClass Create Agather: Public class outerclass { Private Double D1 = 1.0; // INSERT CODE Here } You NEED TO INSERT An Inner Class Declaration At Line 3. Which Two Inner Class Declarations Are Valid? (choose two.) A. Class innerone { Public Static Double Methoda () {Return D1;} } B. Public class innerone { Static Double Methoda () {Return D1; } C. private class innerone { Double methoda () {Return D1;} } D. static class innerone { protected double methoda () {return d1;} } E. Abstract class innerone { Public Abstract Double Methoda (); } described as follows: I. Static internal classes can have static members, not static internal classes, no static members. Therefore, A, b fault II. Non-static members of static internal classes can access the external class of static variables, not accessible non-static variables; RETURN D1 error. Dimension III. Non-static members of non-static internal classes can access unstatic variables of external classes. Therefore, C is correct IV. The answer is C, E 5, Java communication program, programming questions (or question and answer), programming, read servers, and write to local display with Java Socket A: Server end program: Package test; Import Java.net. *; Import Java.io. *; Public Class Server { Private serversocket ss; PRIVATE SOCKET Socket; PRIVATE BUFFEREDREADER IN Private PrintWriter Out; Public server () { Try { SS = New Serversocket (10000); While (True) { Socket = ss.accept (); String remoteip = socket.getinetaddress (); gethostaddress (); String remoteport = ":" Socket.getlocalPort (); System.out.println ("A Client Come In! IP:" Remoteip Remoteport); IN = New BufferedReader (New InputStreamReader (socket.getinputstream ())); String line = in.readline (); System.out.println ("CLEINT Send IS:" line); OUT = New PrintWriter (socket.getOutputStream (), true); Out.println ("Your Message Received!"); Out.close (); In.Close (); Socket.close (); } } catch (ioException e) { Out.println ("WRONG"); } } Public static void main (string [] args) { New server (); } } Client End Program: Package test; Import Java.io. *; Import Java.net. *; Public Class Client { Socket socket; Bufferedreader in; Printwriter out; Public client () { Try { System.out.println ("Try to Connect To 127.0.0.1:10000"); Socket = New Socket ("127.0.0.1", 10000); System.out.println ("The Server Connected!"); System.out.Println ("please enter some character:"); BufferedReader line = new bufferedreader (New InputStreamReader (System.in); OUT = New PrintWriter (socket.getOutputStream (), true); Out.println (line.readline ()); IN = New BufferedReader (socket.getinputStream ()); System.out.println (in.readline ()); Out.close (); In.Close (); Socket.close (); } catch (ioException e) { Out.println ("WRONG"); } } Public static void main (string [] args) { NEW client (); } } 6. Use Java to achieve a method of ordering, Java classes to realize serialization (two)? As in the Collection framework, what kind of interface is to be achieved? A: Sort by the insert method is as follows Package test; Import Java.util. *; Class insertsort { ArrayList Al; Public InsertSort (int Num, int MOD) { Al = New ArrayList (NUM); Random Rand = new random (); System.out.println ("The arraylist sort before:"); For (int i = 0; i Al.Add (new integer (math.abs (rand.nextint ())% mod 1)); System.out.println ("Al [" i "] =" Al.Get (i)); } } Public void sortit () { Integer Tempint; INT maxSize = 1; For (INT I = 1; I { Tempint = (Integer) Al.Remove (i); IF (Tempint.intValue ()> = (Integer) Al.Get (MaxSize-1)). INTVALUE ()) { Al.Add (MaxSize, Tempint); MaxSize ; System.out.println (al.toString ()); } else { For (int J = 0; j { IF ((Integer) Al.Get (j)). INTVALUE ()> = Tempint.intValue ()) { Al.Add (j, tempint); MaxSize ; System.out.println (al.toString ()); Break; } } } } System.out.println ("The ArrayList Sort After:"); For (int i = 0; i { System.out.println ("Al [" i "] =" Al.Get (i)); } } Public static void main (string [] args) { INSERTSORT IS = New Insertsort (10,100); Is.sortit (); } } The Java class realizes the methodification method is to implement java.io.serializable interface Compare Compare Comparison in the Collection Framework To implement the Comparable interface and Comparator interface 7. Programming: Write a function that intercept strings, input as a string and byte, and outputs a string that is intercepted by byte. But to ensure that the Chinese characters are not taken, such as "I abc" 4, should be "I abc", enter "I am ABC Han DEF", 6, should output "I ABC" instead of "I am ABC Han ". A: The code is as follows: Package test; Class splitstring { String splitstr; Int splitbyte; Public splitstring (String str, int Bytes) { Splitstr = STR; Splitbyte = bytes; System.out.println ("THE STRING IS: '" SPLITSTER "; splitbytes =" splitbyte); } Public void splitit () { Int loopcount; LoopCount = (splitstr.length ()% splitbyte == 0)? (splitstr.length () / splitbyte) :( splitstr.length () / split BYTE 1); System.out.println ("Will Split INTO" LoopCount; for (int i = 1; i <= loopcount; i ) { IF (i == loopcount) { System.out.println (Splitstr.Substring ((i-1) * splitbyte, splitstr.length ())); } else { System.out.println (Splitstr.Substring ((i-1) * splitbyte, (i * splitbyte)))))) } } } Public static void main (string [] args) { Splitstring ss = new splitstring ("TEST DD Wen DSAF in Male Big 3443N China 43 Chinese 0EWLDFLS = 103 ", 4); ss.splitit (); } } 8, Java multi-threaded programming. Write a multi-thread program with Java, such as writing four threads, two plus 1, two to one variable minus one, output. I hope everyone will make up, thank you. 9, the difference between String and StringBuffer. A: The length of String is invisible, and the length of StringBuffer is variable. If you use the content in the string, especially when you want to modify, use StringBuffer, if you finally need String, use StringBuffer's toString () method JSP 1. What built-in objects have jsp? What is the role? A: JSP has 9 basic built-in components (can correspond to six internal components of the ASP): Request user request, this request will contain parameters from Get / POST request Response web page back to the user's response The properties of the PageContext page are managed here Session and request related session Application Servlet is being executed OUT is used to transfer the output of the response Config servlet architecture components Page JSP page itself Exception For error web, unconcerned exceptions 2, what actions are there? What is the role? A: JSP has the following six basic actions JSP: incrude: Introduces a file when the page is requested. JSP: Usebean: Find or instantiate a JavaBean. JSP: setProperty: Sets the properties of JavaBean. JSP: getProperty: Outputs the properties of a JavaBean. JSP: Forward: Turn the request to a new page. JSP: Plugin: Generate Object or Embed tags based on the browser type to the Java plugin 3, Dynamic INCLUDE and Static Include in JSP? Answer: Dynamic include use JSP: Include action implementation Static Include is implemented with the include false code, which does not check the changes of the file included, suitable for the static page <% at include file = "incruded Dot HTM"%> 4, what is the difference between the two jump methods? What is the difference? A: There are two kinds, respectively: The frontier page does not turn to the page referred to in INCLUDE, just display the result of the page, the main page is still the original page. It will come back later, which is equivalent to the function call. And can be used with parameters. The latter is completely turned to a new page and will not come back. Equivalent to the GO TO statement. Servlet 1, talk about the life cycle of servlet? A: Servlet has a good definition of survival, including loading and instantiation, initialization, processing request, and service end. This survival period is expressed by the init, service, and destroy method of the javax.servlet.servlet interface. 2, the SERVLET version (forgot what two versions are asked)? I hope everyone will make up, thank you. 3, the difference between forward () and redirect () in the Java Servlet API? A: The former is only the steering of the control of control in the container. It does not show the turn-behind address in the client browser address bar; the latter is completely jump, the browser will get the address of the jump, and re-re- Send a request link. Thus, the link address after the jump is seen from the address bar of the browser. Therefore, the former is more efficient, and when the former can meet the needs, try to use the forward () method, and this also helps to hide the actual link. In some cases, for example, you need to jump into a resource on a further server, you must use the sendRedirect () method. 4, the basic architecture of servlet Public class servletname extends httpservlet { Public Void Dopost (httpservletRequest Request, HttpservletResponse Response) THROWS ServletException, IOException { } Public void doget (httpservletRequest Request, HttpservletResponse Response) THROWS ServletException, IOException { } } JDBC, JDO 1, you may let you write a JDBC even Oracle program and implement data queries. A: The program is as follows: Package hello.ant; Import Java.sql. *; Public Class JDBC { String dburl = "JDBC: Oracle: Thin: AT 127 Dot 0.0.1: 1521: ORCL"; String theuser = "admin"; String thepw = "manager"; Connection C = NULL; STATEMENT CONN; ResultSet RS = NULL; Public JDBC () { Try { Class.Forname ("Oracle.jdbc.driver.OracleDriver"). NewInstance (); C = DriverManager.getConnection (dburl, theuser, thepw); CONN = C.CREATESTATEMENT (); } catch (exception e) { E.PrintStackTrace (); } } Public Boolean ExecuteUpdate (STRING SQL) { Try { CONN.EXECUTEUPDATE (SQL); Return True; } Catch (SQLException E) { E.PrintStackTrace (); Return False; } } Public ResultSet ExecuteQuery (String SQL) { RS = NULL; Try { Rs = conn.executeQuery (SQL); } Catch (SQLException E) { E.PrintStackTrace (); } Return RS; } Public void close () { Try { CONN.CLOSE (); C. close (); } Catch (Exception E) { E.PrintStackTrace (); } } Public static void main (string [] args) { ResultSet RS; JDBC conn = new JDBC (); RS = conn.executeQuery ("Select * from test"); Try { While (rs.next ()) { System.out.println (rs.getstring ("id")); System.out.println (rs.getstring ("name"); } } catch (Exception E) { E.PrintStackTrace (); } } } 2, Class.Forname role? Why is it used? A: Call this access to return an object that is specified by a string specified class name. 3, what is JDO? A: JDO is a new specification for Java object persistence, which is a referred to as Java Data Object, and is also a standardized API for accessing objects in a data warehouse. JDO provides transparent object storage, so that the developer does not require additional code (such as the JDBC API). These cumbersome routines have been transferred to the JDO product provider, so that developers are freed out to concentrate on time and energy logically. In addition, JDO is flexible because it can run on any data underlayer. JDBC is just more common to relational database (RDBMS) JDO, providing storage capabilities of any data underlying, such as relational database, file, xml, and object database (ODBMS), etc., make it stronger to apply portability. 4. Subject solution in Oracle's large amount of data. Generally, the ID method is used, and there is a three-layer nested method. A: A paging method <% INT i = 1; INT NUMPAGES = 14; String pages = Request.getParameter ("Page"); INT CurrentPage = 1; CurrentPage = (Pages == NULL)? (1): {Integer.Parseint (PAGES)} SQL = "SELECT Count (*) from Tables"; ResultSet RS = DBLINK.EXECUTEQUERY (SQL); While (rs.next ()) i = rs.getinT (1); INT INTPAGECUNT = 1; INTPAGECOUNT = (I% Numpages == 0)? (i / numpages): (I / Numpages 1); Int nextpage; INT. NextPage = CURRENTPAGE 1; IF (Next> = INTPAGECOUNT) NextPage = INTPAGECOUNT; UPPAGE = CURRENTPAGE-1; IF (UPPAGE <= 1) UPPAGE = 1; Rs.close (); SQL = "SELECT * from Tables"; Rs = dblink.executequery (SQL); i = 0; While ((i %> // Output content / / Output page connection Total: <% = currentpage%> / <% = INTPAGECOUNT%> first page
HREF = "list.jsp? Page = <% = UPPAGE%>"> Previous <% For (int J = 1; j <= INTPAGECOUNT; J ) { IF (CurrentPage! = J) { %> XML aspect 1, what parsing technology is there? Is there anything? A: There are DOM, SAX, Stax, etc. DOM: It is very powerful when processing large files. This problem is caused by the tree structure of the DOM. This structure is more memory, and the DOM must load the entire document into memory before parsing the file, suitable for the random access of XML SAX: not now in Dom, SAX is Event drive type XML parsing method. It sequentially reads the XML file, and does not need to load all files all. When encountered at the beginning of the file, the end of the document, or the label is ended, it triggers an event, and the user handles the XML file by writing processing code in its callback event, suitable for the order of XML. Stax: streaming API for XML (stax) 2. What are your aspects of XML technology in the project? How to implement it? A: Data storage, information configuration is two aspects. When doing a data exchange platform, the data that cannot be data sources cannot be assembled into an XML file, and then the XML file is compressed and encrypted, and then transmitted to the recipient through the network, and the decryption is decryled and decompressed and the related information is reduced in the XML file. When doing software configuration, it is easy to use XML, and the various configuration parameters of the software are stored in the XML file. 3. How to solve Chinese problems when using JDOM to resolve the Chinese problem? How to resolve? A: Look at the following code, solve the encoding method Package test; Import Java.io. *; Public Class Domtest { Private string infile = "c: /people.xml"; Private string Outfile = "c: /people.xml"; Public static void main (string args []) { New domtest (); } Public domtest () { Try { Javax.xml.parsers.documentbuilder builder = Javax.xml.Parsers.DocumentBuilderFactory.newInstance (). NewDocumentBuilder (); Org.w3c.dom.document doc = builder.newdocument (); Org.w3c.dom.Element root = doc.createElement ("teacher"); Org.w3c.dom.Element Wang = Doc.createElement ("King"); Org.w3c.dom.Element Liu = Doc.createElement ("Liu"); Wang.Appendchild (Doc.createTextNode ("I am Teacher")) Root.appendchild (wang); Doc.Appendchild (root); Javax.xml.transform.transformer Transformer = Javax.xml.transform.transformerfactory.newinstance (). NewTransformer (); TRANSFORMER.SETOUTPUTPROPERTY (javax.xml.transform.outputkeys.encoding, "gb2312"); Transformer.setputProperty (javax.xml.transform.outputkeys.indent, "yes"); Transformer.Transform (New Javax.xml.Transform.dom.Domsource (DOC), New Javax.xml.transform.Stream.StreamResult (outfile)); } Catch (Exception E) { System.out.println (E.getMessage ()); } } } 4. Programming Way to parse XML in Java. A: The XML file is analyzed by SAX, the XML file is as follows: XML Version = "1.0" encoding = "GB2312"?> persons> Event callback class saxhandler.java Import Java.io. *; Import Java.util.hashtable; Import org.xml.sax. *; Public Class SaxHandler Extends Handlerbase { Private hashtable table = new hashtable (); Private string currentelement = null; PRIVATE STRING CURRENTVALUE = NULL; Public void settable (HashTable Table) { THIS.TABLE = TABLE; } Public hashtable gettable () { Return Table; } Public void StartElement (String Tag, AttributeList Attrs) Throws SAXEXCEPTION { Currentelement = tag; } Public void characters (char [] ch, int start, int ingth) Throws SAXEXCEPTION { CurrentValue = New String (CH, Start, Length); } Public void endelement (String name) THROWS SAXEXCEPTION { Currentelement.equals (name)) Table.Put (Currentelement, CurrentValue); } } JSP content displays source code, SAXXML.JSP: HEAD> <% at page errorpage = "Errpage Dot JSP" ContentType = "text / html; charSet = GB2312"%> <% at page import = "java dot io. *"%> <% at page import = "java dot util.hashtable"%> <% at page import = "ORG DOT W3C.DOM. *"%> <% at page import = "org Dot Xml.sax. *"%> <% at page import = "javax dot xml.parsers.saxparserfactory"%> <% at page import = "javax dot xml.parsers.saxparser"%> <% at page import = "saxhandler"%> <% File File = New File ("C: / People Dot XML"); FileReader Reader = New FileReader (file); Parser Parser; SAXPARSERFACTORY SPF = saxparserfactory.newinstance (); SAXPARSER SP = SPF.NEWSAXPARSER (); SAXHANDLER HANDLER = New SAXHANDLER (); Sp.Pars (New InputSource (Reader), Handler; Hashtable hashtable = handler.gettable (); Out.println ("