Anda di halaman 1dari 35

Articles Category: Java programming one, Java Basics

1.Java What are the basic data types, String is not a basic data types, what their differences.
2. String operations:
Write a method to achieve reversal of the string, such as: input abc, the output cba
Write a method to achieve a string replacement, such as: input bbbwlirbbb, output bbbhhtccc.
3. Data type conversion between numeric characters How to convert to digital (Integer, Double)
How to convert a number to the decimal point character to get top two, and rounded.
4. Date and time of how to obtain the date, hours, minutes and seconds how to get from 1970 to the
present number of milliseconds how to get a date is the last day of the month how to format date
5. Arrays and collections
6. Files and directories (I / O) operations to list all the files to a directory to a directory listing of all
subdirectories to determine the existence of a file or directory how to read and write files
7.Java polymorphic implementation (inheritance, overloading, coverage)
8. Encoding conversion, how to achieve the GB2312 encoded string converted to ISO-8859-1 encoded
string.
9.Java the steps to access the database, Statement and PreparedStatement differences between them.
10. Locate the following code may be mistakes, and explain the reasons:

2, JSP & Servlet techniques


1. Describe the difference between JSP and Servlet, in common, their scope of application of
2. In the Web development to deal with HTML tags, should do what kind of treatment, to filter those
characters ( "" & "")
3. In JSP How to read the client's request, how to access CGI variables, how to determine the true path
of a Jsp document.
4. Describe the role of Cookie, and Session, the difference and their respective scope of application,
Session works.
5. Jsp contained in an external file lists the way What's the difference between the two.
6. Description Jsp role in the errorPage range of applications.
7. Jsp describes how to use JavaBeans.
8. A brief introduction JSP tag library
9.Jsp and Servlet requests forwarded separately in how to achieve.

3, J2EE related knowledge


1. Introduction J2EE, J2SE, J2SE difference.
2.J2EE is a technology or a platform, he provided those technologies.
3. What is the Application Server, it has what features and benefits.
4. A brief introduction and principles of the advantages of connection pooling.
The role of 5.Web.xml

4 Other
1.Web security considerations (form validation, browser Basic method validation, application security,
SSL, code consideration)
2. A brief introduction of your understanding of MVC.
3. A brief introduction by the understanding of XML.
4. Documentation and coding standards
5.Java the page, efficiency considerations.
6. A brief introduction you know structs.

-------------------------------------------------- ------------------------------

1.xml's role in the project


2.s-EJB and the difference between e-EJB
3. Conversation side effects
4.cmp the advantages and disadvantages with the bmp
5.j2me procedures necessary parts
6.c / s and b / s the difference between
7. To build a connect pool, and then call it,
8.j2ee the difference between platform and dotnet platform

9.ejb of the life cycle


10.session bean, and the difference between entity bean
11.ejb of the transaction mechanism
12.synchronized (producer and consumer)
13.String and StringBuffer
14.Serializable
15.MVC (Struts work flow)
16. What is the MDA

17.tcp with the difference between udp


18. Linked with the difference between hash and array
19. The difference between heap and stack
The classification and distinction 20.ejb
21. You are right now the software industry, as well as the domestic software industry's views
22. To talk about the java multi-threading
23. To talk about the file encryption technology
24. Software development life cycle
25. Routing protocol types and characteristics of
26.java components of the awt and swing the key to GUI design
27. For the current understanding of java

28. Briefly describe the difference between awt and swing.


29. Brief java programming event handling model.
30. Applet do you write off? applet security permissions to? Cite a java application or applet with
servlet / jsp communication can be used approach.
31. Description logic operation (such as &, |) and conditions of operation (such as &&,||) difference.
32. Brief Java Server Page and Servlet connection and distinction.
33. Java.util.concurrent.locks.Lock brief synchronized, and the similarities and differences?
EJB specification 34.EJB prohibiting the operation of what?
35.java In addition to eight kinds of basic types of things, there are still in a virtual machine which, what
role?
36. In addition to using new keyword to create an object accidents, cite more than the other three to
create an instance of the way?
37.classloader in, JDK's API, Classpath in the same web-inf in the class loading mode What is the
difference?
38. Cited more than three garbage collection algorithms, and compare their advantages and
disadvantages?
39. Write code to implement a thread pool

40. Describe the JVM loads class file of the principles of mechanism?
41. Trial illustrates a typical garbage collection algorithm?
42. Please write java binary tree algorithm, add the data to achieve the formation of binary functions,
and to print out the first-order approach.
43. Please write a java program to achieve thread pooling?
44. Given a C language function, required to achieve a call in the java class.

45. How to get the length of the array?


46. Access modifier "public / private / protected / default modifier" in the use of
47. Use keywords to final modification of a class or method, what is the significance?
48. Grasp the concept of classes and objects to grasp the essence of object-oriented programming
49. Static variables and static methods of the significance of how to refer to a class static variable or
static method?
50.JAVA how language exception handling, keywords: thorws, throw, try, catch, finally
51.Object class (or its subclasses) and finalize () method is called under what circumstances?
52. 1 ". Java" whether the original file can include multiple classes (not within the class)?
53. Grasp the concept of inner classes and interfaces
Use of 54.StringTokenizer class
55. Data structure, how to traverse the List in the elements?
If you want to save or access the data according to key values, using what data structure?
Collection related to master the use of interfaces and classes
56. Using the StringBuffer class and the String class to the string connection What's the difference?
57. Call the Thread class's destroy () method what are the consequences?
58. Multi-threading, what keyword modifier synchronized method? stop () and suspend () methods are
not recommended to use?
59. The use of socket client and server to establish the process of communication
60.JAVA language internationalization of applications, Locale class, Unicode
61. Describe the reflex mechanism
62. How to read and write a file?
63. In a graphical interface, a button how to handle mouse click events?
64. In a graphical interface, a table, how to edit the cell when the pop-up drop-down box?
65. How do I load pictures?
66. What is a modal dialog?
67. Expounded the concept of MVC
68.GUI use layout manager, FlowLayout, BorderLayout, GridBagLayout
69. How to construct a tree? Select a tree node, how to get this node?
70. To the edit box enter the characters, how to control only the input integer?
71. Describe the process of connecting to the database using JDBC
72.EJB is divided into several categories? What is a BMP, CMP?
73. What is JNDI?

74.ADO What? ActiveX Data Objects, is an application-level programming interface.


75. Four kinds of JDBC methods? The current version?
76.EJB There? What is the difference?
77.JavaBean with EJB What is the difference?
78. What are the software development life cycle phases?
79. Software development What are the factors?
80. Software development, how to version control?
81.UML, the class how to represent the view class in the inheritance and aggregation?
82. Client-side cursors and the difference between server-side cursors?
83. Dynamic cursor with the difference between a static cursor?
84.dotnet the basic framework by which the composition of a few?
85.Oracle What is the SGA?
86.web servers What is this?
87.UNIX the QT What does it mean?
88. In the software development life cycle stage in which test?
89.dotnet Comparison with J2EE?
90. What is ActiveX?
91.Java in IDL What is this?
92.ISO9000 and CMM what? IS09000 and the CMM (Capability Maturity Model) certification is
internationally accepted software quality assessment methods. CMM's five maturity levels.

-------------------------------------------------- ------------------------------

First, to talk about the final, finally, finalize the difference.


final? modifier (keyword) if a class is declared as final, meaning that it can not send another gives rise to
new sub-class, can not serve as the parent class is inherited. Therefore, a class can not both be declared
as abstract, and was again declared to be final in. The variable or method declared as final, you can
ensure that they are in use are not being changed. The variable is declared as a final declaration must be
given initial value, while in later references can only read, can not be modified. Is declared as the final
approach is also only use can not be overloaded
finally? then finally blocks to provide exception handling to perform any cleanup. If you throw an
exception, then the matching catch clause will be executed and then control will enter the finally block
(if any).
finalize? method name. Java technology allows the use of finalize () method in the garbage collector will
remove the object from memory out to do the necessary clean-up work before. This method is by the
garbage collector determine when an object is not referenced in this object calls. It is defined in the
Object class, so all classes inherit it. Subclasses override finalize () method to tidy up the system
resources or perform other cleanup work. finalize () method is to remove the object before the garbage
collector calls on this object.

Second, Anonymous Inner Class (anonymous inner classes) it can be extends (inheritance) other classes,
can implements (implementation) interface (interface)?
Anonymous inner classes is not the name of the internal classes. Can not extends (inheritance) other
classes, but an inner class can be used as an interface, by another within the class implements.

Thirdly, Static Nested Class and Inner Class differences, to put the better (surface examination questions,
some very general).
Nested Class (typically C + +, say), Inner Class (usually JAVA view). Java inner class and the C + + nested
classes The biggest difference lies in whether there is a reference point on the outside. Concrete, visible
http://www.frontfree.net/articles/services/view.asp?id=704&page=1
Note: The static inner classes (Inner Class) means that an internal class to create a static object, does not
require an external class object, two from a static inner class can not be an object to access an external
class object

Fourth, the difference between & and & &.


& Is a bit operator. & & Is a Boolean logic operators.

Fifth, HashMap, and Hashtable difference.


Belong to the Map interface class, achieved the unique keys mapped to a specific value on.
HashMap class are not classified, or sorted. It allows one null key and multiple null values.
Hashtable is similar to HashMap, but does not allow null keys and null values. It is also slower than
HashMap because it is synchronized.

Sixth, Collection and Collections difference.


Collections is a class under java.util, which contains a variety of static methods related to collection
operations.
Collection is under java.util interface, it is the structure of the parent interface to a variety of collections.

Seventh, when using assert.


Assertion is a Boolean expression that contains the statement, in the implementation of this statement
assumes that the expression is true. If the expression evaluates to false, then the system will report an
AssertionError. It is used for debugging purposes:
assert (a> 0); / / throws an AssertionError if a <= 0
Assertion can have two forms:
assert Expression1;
assert Expression1: Expression2;
Expression1 should always produce a Boolean value.
Expression2 can arrive at a value of arbitrary expressions. This value is used to generate a String show
more debugging information in the message.
Asserted that by default is disabled. To enable assertions at compile time, need to use source 1.4 tags:
javac-source 1.4 Test.java
To enable assertions at run time, you can use-enableassertions or-ea tag.
To choose to disable assertions at runtime, you can use-da or-disableassertions tag.
To enable assertions in system classes, use-esa or-dsa tag. The package can also be enabled or disabled
on the basis of assertions.
Can be expected under normal circumstances would not arrive at any location to place assertions.
Assertions can be used to validate the parameters passed to the private methods. However, the
assertion should not be used to validate the parameters passed to public methods, because regardless
of whether the assertion is enabled, the public methods will have to check its parameters. However,
either in the public method, you can also use non-public method postcondition assertion test. In
addition, the assertion should not in any way to change the program state.

Eighth, GC What is this? Why should there be GC? (Base).


GC is a garbage collector. Java programmers need not worry about memory management, because the
garbage collector will automatically be managed. To request a garbage collection, you can call the
following methods:
System.gc ()
Runtime.getRuntime (). Gc ()

9th, String s = new String ( "xyz"); created a number of String Object?


Two objects, one is "xyx", one refers to "xyx" a reference to an object s.

10th, Math.round (11.5) equal to how many? Math.round (-11.5) is equal to how many?
Math.round (11.5) return (long) 12, Math.round (-11.5) return (long) -11;

11th, short s1 = 1; s1 = s1 + 1; there anything wrong? Short s1 = 1; s1 + = 1; there anything wrong?


short s1 = 1; s1 = s1 + 1; any mistakes, s1 is a short-type, s1 +1 is the int type, can not be explicitly
converted to type short. Could be modified as s1 = (short) (s1 + 1). short s1 = 1; s1 + = 1 correctly.

12th, sleep () and wait () What is the difference? Engage in favorite threads
sleep () method is to make a thread to stop a period of time. In the sleep time interval expires, the
thread is not necessarily an immediate resumption of the implementation. This is because at that time,
other threads may be running but has not been schedule to give up, unless (a) "wake up" the thread has
a higher priority
(b) is running because of other reasons, blocking the thread.
wait () is thread-interaction, if the thread on a synchronization object x issued by a wait () call, the
thread will suspend execution, be transferred to the object into the wait state until it is time to wake up
or wait.

13th, Java has no goto?


Goto? Java reserved words in, there is no use in java.

14th, arrays have length () this method? String there any length () this method?
Arrays are not length () This method has length attribute.
String has a length () this method.

15th, Overload, and Override difference. Overloaded methods can change the return value type?
Method of rewriting Overriding and overloading Overloading is different from the performance of Java
polymorphism. Rewrite Overriding parent class and subclass is between a manifestation of
polymorphism, overloading Overloading is a manifestation of polymorphism in class. If the child class
defines a method with the parent class has the same name and parameters, we say that the method has
been rewritten (Overriding). Subclass of an object using this method, it will call the child class definition,
it is concerned, the parent class definition, as being "shielded" the. If a class defines a number of ways
the same name, they may have different number of arguments or parameters of different types, is
called method overloading (Overloading). Overloaded methods can change the return value type.

16th, Set where the elements are not repeated, then the method used to distinguish whether or not to
repeat it? Is to use == or equals ()? Them What's the difference?
Set inside the element is not repeated, then using iterator () method to distinguish whether or not to
repeat. equals () is the interpretation of 2 Set for equality.
equals () and == means to determine whether the point to the same object reference value equals () was
covered in the class, for the two separate objects when the content and type of match, then return true
value.

17th, give me one you most often see runtime exception.


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
18th, error and exception What is the difference?
error that is not impossible but very difficult to restore the case of a serious problem. For example, the
memory overflow. Procedure can not be expected to be able to handle such a situation.
exception that a design or implementation problem. In other words, it is said that if the program is
running normally, never happened.

19th, List, Set, Map it inherited from the Collection interface?


List, Set a

Map is not a

20th, abstract class and interface What is the difference?


The existence of the statement means to achieve it without the class is called abstract class (abstract
class), it is used to create a manifestation of some basic behavior classes, and methods for this kind of
statement, but not in the class to achieve such situation. Can not create an instance of abstract class.
However, you can create a variable whose type is an abstract class, and let it point to an instance of a
specific subclass. Constructor can not have an abstract or abstract static methods. Abstract subclass of
parent class for them in all the abstract methods provide implementation, otherwise, they are also an
abstract category. Instead, the child class to implement this method. Aware of his actions in the class of
other classes can implement these methods.
Interface (interface) is a variant of an abstract class. In the interface, all methods are abstract. Multiple
inheritance to achieve such an interface can be obtained. Interface, all methods are abstract, and there
is no body of a program. Interface can only define static final member variables. Implementation of the
interface and the sub-category is similar to addition to the implementation class can not inherit behavior
from the interface definition. When the class implements a special interface, which defines the
(forthcoming procedure body to give) all of this interface method. Then, it can implements this interface
on any object of class call interface methods. Because of the abstract class, which allows the use of
interface name as the reference variable type. The usual dynamic binding will take effect. Reference can
be converted to the interface type, or from the interface type conversion, instanceof operator can be
used to determine whether an object's class implements interface.

21st, abstract whether the method is also static, it may be the same native, will it also be synchronized?
Can

22nd, the interface is inheritable interface? Abstract class it can be realized (implements) interface?
Abstract class is inheritable entity class (concrete class)?
Interfaces can be inherited interface. Abstract class can be achieved (implements) interface, abstract
class is inheritable entity class, but only if an entity class must have an explicit constructor.

23rd, start a thread is run () or start ()?


Start a thread is to call start () method, so that the thread is represented by a virtual processor can run
the state, which means that it can schedule and execute by the JVM. This does not mean that the thread
will run immediately. run () method can produce a sign to be out to stop a thread.

24th, Constructor constructor can it be override?


Constructor constructor can not be inherited and can not rewrite Overriding, but can be overloaded
Overloading.

25th, can inherit String class?


String class is final class and therefore can not be inherited.

26th, when a thread into an object of a synchronized method, other threads can enter the object if the
other method?
No, an object of a synchronized method can only be visited by a thread.

27th, try () there is a return statement, then followed this try after finally () where the code will be
executed, when executed, the return before or after?
Will be implemented, and in return the former Executive.

28th, programming problem: The most efficient way to calculate the two multiplied by eight is equal to a
few?
C programmers are particularly fond of the background ask such questions.

2 "" 3

29th, the two objects the same value (x.equals (y) == true), but it may have a different hash code, this
statement is not it?
Does not have the same hash code.

30th, when an object is passed as a parameter to a method, this method can change the properties of
this object, and may return the results after the changes, then here, in the end is passed by value or
reference passed?
Is passed by value. Java programming language to pass parameters only by value. When an object
instance as a parameter is passed to the method, the value of the parameter is a reference to that
object. The contents of the object can be called the method of change, but the object reference will
never change.

31st, swtich whether the role of the byte, on whether the role of the long, on whether the role of the
String on?
switch (expr1) in, expr1 is an integer expression. Therefore, switch and case statements passed to the
parameter should be int, short, char, or byte. long, string can not act on the swtich.

32nd, programming problem: to write a Singleton out.


Singleton pattern main role is to ensure that the Java application, an instance of class Class is only one
exists.
Singleton pattern in general are usually a few different forms:
The first form: the definition of a class, its constructor is private, and it has a static type of the private
variable is initialized when an instance of the class, then through the getInstance method to get a public
reference to it, then Call these methods.
public class Singleton (
private Singleton () ()
/ / In an example of its own internal define their own, is not it strange?
/ / Note that this is a private for internal calls private static Singleton instance = new Singleton ();
/ / Here is a for external access to this class of static methods, you can directly access the public static
Singleton getInstance () (
return instance;
)
)
The second form:
public class Singleton (
private static Singleton instance = null;
public static synchronized Singleton getInstance () (
/ / This method is an improvement over the above, do not be generated each time an object, but for the
first time / / generate examples of use and increased efficiency!
if (instance == null)
instance = new Singleton ();
return instance;)
)
Otherwise:
Define a class, its constructor is private and all methods static.
The first form is generally believed to be more a bit more secure

-------------------------------------------------- ------------------------------

---- Java side and the questions and answers (http://www.bioon.net/dispbbs.asp?


boardid=169&id=108010)

-------------------------------------------------- ------------------------------

<! - printpage. asp # # ($ bbslist) loop part of the - "- Author: jiajia1983
- Release Time :2005-3-9 17:29:00

- Java side and the questions and answers


Relevant basic knowledge of JAVA
1, object-oriented features are what
1. Abstraction:
Abstraction is to overlook a topic has nothing to do with the current target those aspects in order to
more fully attention-related aspects of the current target. The abstract did not intend to understand all
the problems, but only select some of them, temporarily do not have some details. Abstract includes
two aspects, first, the process of abstraction, the second is the data abstraction.
2. Inheritance:
Inheritance is a link class hierarchy model, and to allow and encourage the reuse of classes, it provides a
clearly stated common methods. The object of a new class can be derived from existing classes, this
process is called class inheritance. The new class inherits the characteristics of the original class, the new
class known as the original class derived class (subclass), while the original class is called a new class of
base class (parent class). Derived class from its base class can inherit methods and instance variables,
and the class can modify or add new ways to make it more suited to particular needs.
3. Package:
The package is surrounded by the process and data, access to data only through the defined interface.
Object-oriented computing begins with the basic concept, that is the real world can be described as a
series of full self-government, encapsulated objects, these objects through a protected interface to
access other objects.
4. Polymorphisms:
Polymorphism is one that allows different types of objects of the same message to respond.
Polymorphisms, including parametric polymorphism and contains the polymorphism. Polymorphic
language with a flexible, abstract, behavior sharing, code-sharing advantages of a good solution to the
problem of the application functions with the same name.
2, String is the most basic data type?
The basic data types include byte, int, char, long, float, double, boolean, and short.
java.lang.String class is final type, and therefore can not inherit this class, can not modify this class. In
order to improve efficiency to save space, and we should use the StringBuffer class
3, int and Integer What is the difference
Java offers two different types: reference types and primitive types (or built-in types). Int is a java
primitive data types, Integer is a java wrapper classes provided for the int. Java primitive type for each of
the wrapper classes.
Primitive type wrapper classes
boolean Boolean
char Character
byte Byte
short Short
int Integer
long Long
float Float
double Double
Reference types and primitive types of acts completely different, and they have different semantics.
Reference types and primitive types have different characteristics and usage, including: size and speed,
this type of data structure to which type of storage, while reference types and primitive types as an
instance of a class specified in the data default values. Object reference instance variable default value is
null, while the primitive type instance variables to their default value and type.
4, String and StringBuffer difference between
JAVA platform provides two classes: String and StringBuffer, which can be stored and operation of the
string, that is, character data that contains multiple characters. The String class provides a numerical
immutable string. And this StringBuffer class provides string to be modified. When you know the
character data to be changed when you can use StringBuffer. Typically, you can use to dynamically
construct StringBuffers character data.
5, run-time exceptions and the general exception of the similarities and differences?
Exceptions that may arise during the program is running a non-normal, run-time exception that the
normal operation of the virtual machine may encounter an exception, is a common runtime error. java
compiler requirements method must throw statement may occur in the non-run-time exception, but
does not require a statement throw run-time exceptions are not caught.
6, say Servlet life cycle, and tell the difference between Servlet and CGI.
Servlet is a server instantiated, the container is running its init method, the request arrives, running its
service method, service method of automatically sending the request to run with the corresponding
doXXX methods (doGet, doPost) and so on, when the server decided to destroy an instance when the
call to the destroy method.
The difference is that with cgi server servlet is in the process, multiple threads run through its service
method, an instance can serve multiple requests, and its examples are generally not destroyed while the
CGI request is generated for each new process, services after the completion of the destruction, so
efficiency than servlet.
7, to say ArrayList, Vector, LinkedList storage performance and features
ArrayList and Vector are stored using an array of data, the number of elements in this array is greater
than the actual stored data in order to increase and insert elements, which are indexed by serial number
to allow the direct elements, but the inserted element to the array elements involved in mobile and
other memory operations, so index data into the data fast and slow, Vector methods due to the use
synchronized (thread-safe), usually worse performance than the ArrayList, and LinkedList using two-way
linked list for storage, by serial number index data required prior to or after the traverse, but the
insertion only need to record data before and after the entry of this item can be, so insert faster.
8, EJB is based on what technology to achieve it?
EJB including SessionBean, EntityBean, MessageDrivenBean, based on JNDI, RMI, JAT and other
technology.
SessionBean in the J2EE application server is used to complete some business operations, such as access
to the database, call other EJB components. EntityBean be used to represent the application systems
used in the data.
For the client, SessionBean is a non-persistent object, which implements some running on the server
business logic.
For the client, EntityBean is a persistent object, which represents a memory is stored in the persistent
object view of the entity, or an enterprise application implementation by the existing entity.
SessionBean can also be further subdivided into StatefulSessionBean and StatelessSessionBean, both of
SessionBean system logic can be put into implementation of the method, The difference is that
StatefulSessionBean can record the caller's state, so generally speaking, a user will have a corresponding
StatefulSessionBean entity. StatelessSessionBean Although he is the logical components, but he is not
responsible for recording the user status, meaning that when a user calls StatelessSessionBean time,
EJBContainer will not find a specific StatelessSessionBean entity to implement this method. In other
words, it is likely that user in the implementation of a StatelessSessionBean of the methods when the
same Bean's Instance in the implementation of. From memory point of view, StatefulSessionBean with
StatelessSessionBean comparison, StatefulSessionBean consume J2EEServer more memory, but
StatefulSessionBean advantage lies in that he can maintain the user state.
9, Collection and Collections difference.
Collection is a collection of superior class, interface, interface inheritance and his main Set and List.
Collections is a collection of classes for a helper class, he offers a collection of static methods for a wide
range of search, sorting, and so on thread-safe operation.
10, & and & & difference.
& Is a bitwise operator, said the bitwise and operator, & & is a logical operator, said the logic (and).
11, HashMap, and Hashtable difference.
HashMap is a lightweight implementation Hashtable (non-thread-safe implementation), they have
completed the Map interface, the main difference is that HashMap allows null (null) key (key), due to
non-thread-safety, efficiency may be higher than Hashtable.
HashMap allows null as an entry of the key or value, while Hashtable does not allow.
The contains method of HashMap to get rid of Hashtable, and replaced containsvalue and containsKey.
Method is easy because it contains people misunderstanding.
Dictionary class inherited from Hashtable, while HashMap is Java1.2 introduced Mapinterface an
implementation.
The biggest difference is that, Hashtable method is to Synchronize, rather than HashMap, Hashtable,
when multiple threads to access without the need for its own approach to achieve synchronization,
while the HashMap must furnish external synchronization.
Hashtable and HashMap used hash / rehash algorithms are probably the same, so there will not be
much difference in performance.
12, final, finally, finalize the difference.
final statement for the properties, methods and classes, respectively, said the property can not be
changed, methods can not be covered, the class can not be inherited.
finally exception handling statement is part of the structure that is always the implementation.
Object class is a finalize method, executed when the garbage collector calls this method, the object has
been recovered, you can override this method to collect waste recovery when other resources, such as
the closing documents.
13, sleep () and wait () What is the difference?
sleep is a thread class (Thread) method, cause this thread to suspend the specified time, to the
Executive the opportunity to the other thread, but the monitoring of the state is still maintained after
that time will be automatically reinstated. Call sleep will not release the object lock.
wait is the Object class methods, call the wait method on this object cause the thread to give up the
object lock, waiting to enter the wait for this object's lock pool, and only issued a notify method for this
object (or notifyAll) and after locking the thread object before entering the pool of ready access to the
object lock into the running state.
14, Overload, and Override difference. Overloaded methods can change the return value type?
Method of rewriting Overriding and overloading Overloading is different from the performance of Java
polymorphism. Rewrite Overriding parent class and subclass is between a manifestation of
polymorphism, overloading Overloading is a manifestation of polymorphism in class. If the child class
defines a method with the parent class has the same name and parameters, we say that the method has
been rewritten (Overriding). Subclass of an object using this method, it will call the child class definition,
it is concerned, the parent class definition, as being "shielded" the. If a class defines a number of ways
the same name, they may have different number of arguments or parameters of different types, is
called method overloading (Overloading). Overloaded methods can change the return value type.
15, error and exception What is the difference?
error that is not impossible but very difficult to restore the case of a serious problem. For example, the
memory overflow. Procedure can not be expected to be able to handle such a situation.
exception that a design or implementation problem. In other words, it is said that if the program is
running normally, never happened.
16, similarities and differences between synchronous and asynchronous, respectively, in what
circumstances to use them? Example.
If the data will be shared between threads. For example, the data is being written by another thread
may later read or are reading the data may have been written by another thread, and then the data is
shared data, you must synchronize access.
When the application object called a need to take a long time to execute the method, and do not want
the program to wait method returns, you should use asynchronous programming, in many cases is often
more efficient use of asynchronous channels.
17, abstractclass and interface What is the difference?
The existence of the statement means to achieve it without the class is called abstract class
(abstractclass), which is used to create a manifestation of some basic behavior classes, and methods for
this kind of statement, but not in the class to achieve such a situation. Can not create an instance of
abstract class. However, you can create a variable whose type is an abstract class, and let it point to an
instance of a specific subclass. Constructor can not have an abstract or abstract static methods. Abstract
subclass of parent class for them in all the abstract methods provide implementation, otherwise, they
are also an abstract category. Instead, the child class to implement this method. Aware of his actions in
the class of other classes can implement these methods.
Interface (interface) is a variant of an abstract class. In the interface, all methods are abstract. Multiple
inheritance to achieve such an interface can be obtained. Interface, all methods are abstract, and there
is no body of a program. Interface can only define staticfinal member variables. Implementation of the
interface and the sub-category is similar to addition to the implementation class can not inherit behavior
from the interface definition. When the class implements a special interface, which defines the
(forthcoming procedure body to give) all of this interface method. Then, it can implements this interface
on any object of class call interface methods. Because of the abstract class, which allows the use of
interface name as the reference variable type. The usual dynamic binding will take effect. Reference can
be converted to the interface type, or from the interface type conversion, instanceof operator can be
used to determine whether an object's class implements interface.
18, heap and stack What is the difference.
Stack is a linear set, add and remove elements of its operation should be completed in the same
paragraph. LIFO stack in accordance with the manner for processing.
Heap is an integral element of the stack
19, forward and redirect the difference between
forward the request resource is the server, the server direct access to the target address of the URL, the
URL that the response content to read over, and then the content and then sent to the browser, the
browser simply does not know the contents of the server to send Where did they come from, so the It is
in the address bar or the old address.
According to the logic server-side redirect is sending a status code that tells the browser to re going to
ask the address, in general, the browser will use all the parameters have a request to re-request, so
session, request parameters are able to access.
20, EJB and JAVABEAN the difference?
JavaBean is a reusable component of the JavaBean is not strictly regulated, in theory, any Java class can
be a Bean. But usually, because of JavaBean is created by the container (eg Tomcat), so the JavaBean
should have a no-argument constructor and another, usually JavaBean but also to achieve Serializable
interface is used for Bean's durability. JavaBean in fact equivalent to Microsoft's COM model, the local
in-process COM component, it can not be accessed across processes. EnterpriseJavaBean the equivalent
of DCOM, the distributed components. It is based on Java's Remote Method Invocation (RMI)
technology, so EJB can be a remote access (cross-process, inter-computer). But the EJB must be
deployed in areas such as Webspere, WebLogic container such as, EJB clients never directly access the
real EJB components, but by access to its container. EJB containers EJB component agent, EJB
components are created and managed by the container. Customers to access real EJB container
components.
21, StaticNestedClass and InnerClass different.
StaticNestedClass is declared as a static (static) inner class, it can not rely on an external instance of a
class is instantiated. Internal classes are usually required before an external class to instantiate an
instance of.
22, JSP dynamic INCLUDE the difference between static INCLUDE?
Dynamic INCLUDE with jsp: include action to achieve <jsp:includepage="included.jsp"flush="true"/> it
always checks the changes contained in the document, suitable for containing dynamic pages, and can
take parameters.
Include pseudo-code with a static INCLUDE to achieve, will be contained in the file changes does not
check for static pages with <% @ includefile = "included.htm"%>
23, and when to use assert.
assertion (assert) in the software development is a common debugging methods, many development
languages support such a mechanism. In the implementation, assertion is a statement in the program, it
checks a boolean expression, proper procedures must ensure that a boolean expression evaluates to
true; if the value is false, incorrect description of the procedure is already in the state of Next, the
system will give a warning or exit. Generally speaking, assertion assurance procedures for the most
basic, the key is correct. assertion checks are usually open in the development and testing. In order to
improve performance, the software release, assertion checking is usually turned off.
24, GC What is this? Why should there be GC?
GC is a garbage collection means (GabageCollection), memory handling is easy for programmers to the
perceived problem areas, to forget, or an error of memory recovery process or system will lead to
instability and even collapse, Java provides automatic monitoring of GC function can be greater than the
role of the object domain so as to achieve the purpose of automatic recovery of memory, Java language
does not provide the release of allocated memory, the display method of operation.
25, shorts1 = 1; s1 = s1 +1; there anything wrong? Shorts1 = 1; s1 + = 1; there anything wrong?
shorts1 = 1; s1 = s1 +1; (s1 +1 operation result is int type, need to cast type)
shorts1 = 1; s1 + = 1; (correctly compile)
26, Math.round (11.5) equal to how many? Math.round (-11.5) is equal to how many?
Math.round (11.5) == 12
Math.round (-11.5) ==- 11
round method returns the nearest long integer and parameters, the parameter plus 1 / 2, after seeking
the floor.
27, Strings = newString ( "xyz"); created several StringObject?
2
28, designed four threads, two threads for each of the j increase by 1, the other two threads on j for
each decrease of 1. Written procedures.
The following procedure uses an internal class implements the thread, right j change the order of the
time without considering the issue.
publicclassThreadTest1 (
privateintj;
publicstaticvoidmain (Stringargs []) (
ThreadTest1tt = newThreadTest1 ();
Incinc = tt.newInc ();
Decdec = tt.newDec ();
for (inti = 0; i <2; i + +) (
Threadt = newThread (inc);
t.start ();
t = newThread (dec);
t.start ();
)
)
privatesynchronizedvoidinc () (
j + +;
System.out.println (Thread.currentThread (). GetName ()+"- inc: "+ j);
)
privatesynchronizedvoiddec () (
j -;
System.out.println (Thread.currentThread (). GetName ()+"- dec: "+ j);
)
classIncimplementsRunnable (
publicvoidrun () (
for (inti = 0; i <100; i + +) (
inc ();
)
)
)
classDecimplementsRunnable (
publicvoidrun () (
for (inti = 0; i <100; i + +) (
dec ();
)
)
)
)
29, Java has no goto?
java in the reserved words, there is no use in java.
30, start a thread is run () or start ()?
Start a thread is to call start () method, so that the thread is represented by a virtual processor can run
the state, which means that it can schedule and execute by the JVM. This does not mean that the thread
will run immediately. run () method can produce a sign to be out to stop a thread.
31, EJB, including (SessionBean, EntityBean) tell their life cycle, and how to manage affairs?
SessionBean: StatelessSessionBean's life cycle is determined by the container when the client makes a
request to establish an instance of Bean's, EJB container does not have to create a new instance of the
Bean for the client call, but casual look for an existing examples provided to the client. When a client
calls a StatefulSessionBean the first time, the container must immediately on the server to create a new
Bean instance, and related to the client on the client after the method call StatefulSessionBean assigned
to the container will call the client is associated with this The Bean instance.
EntityBean: EntityBeans can survive a relatively long time, and the state is sustainable. As long as there is
data in the database, Entitybeans has been alive. Instead of following the process of the application or
service for the. Even if the EJB container crashes, Entitybeans also survive. EntityBeans life cycle can be
container or Beans self-management.
EJB technology management practices through the following: Object Management Group (OMG) object
substantive services (OTS), SunMicrosystems's TransactionService (JTS), JavaTransactionAPI (JTA),
Development Group (X / Open) of the XA interface.
32, application server, have those?
BEAWebLogicServer, IBMWebSphereApplicationServer, Oracle9iApplicationServer, jBoss, Tomcat
33, give me one you most often see runtimeexception.
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
34, the interface is inheritable interface? Abstract class it can be realized (implements) interface?
Abstract class is inheritable entity class (concreteclass)?
Interfaces can be inherited interface. Abstract class can be achieved (implements) interface, abstract
class is inheritable entity class, but only if an entity class must have an explicit constructor.
35, List, Set, Map it inherited from the Collection interface?
List, Set Shi, Map is not a

-------------------------------------------------- ------------------------------

Java Frequently Asked Questions Surface collection - --

Java-based areas:
1, scope public, private, protected, and not write the difference between A: The difference is as follows:
Scope of the current class package descendants of the same class of other package
public √ √ √ √
protected √ √ √ ×
friendly √ √ × ×
private √ × × ×
The default is friendly when you do not write

2, ArrayList and Vector difference, HashMap, and Hashtable difference Answer: ArrayList and Vector,
mainly from two aspects.
1. Synchrony: Vector is thread-safe, meaning that is synchronized, but ArrayList is the line of unsafe
procedures, not synchronized
2. Data growth: When you need to grow, Vector defaults growth of the original one-pei, but ArrayList is
half of the original on the HashMap and HashTable is mainly on three fronts.
1. For historical reasons: Hashtable is based on the old Dictionary class, HashMap is a Java 1.2
introduced an implementation of the Map interface 2. Synchrony: Hashtable is thread-safe, meaning
that is synchronized, while the HashMap is a line of unsafe procedures is not synchronized 3. Value: Only
HashMap allows null values as you would a table entry key or value

3, char-type variable can store a Chinese character? Why?


A: Yes, the ability to define as a Chinese, because the java in order to unicode encoding, a total of 16
bytes of char, so put a Chinese is no problem

4, there are several multi-threaded implementations, What are they? Synchronization There are several
implementations, What are they?
A: There are two multi-threaded implementations, namely, inheritance and implementation of Thread
class Runnable interface, Synchronization, there are two aspects, namely, synchronized, wait and notify
5, when the class inherits the implementation of the order of questions are generally multiple-choice
questions, ask what you will print out?
A: The parent class:
package test;
public class FatherClass
(
public FatherClass ()
(
System.out.println ( "FatherClass Create");
)
)
Sub-categories:
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 Create

6, inner classes are implemented?


A: The sample code is as follows:
package test;
public class OuterClass
(
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 Results:
C:> java test / OuterClass
InterClass Create
OuterClass Create
Another Example:
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:
1. Static inner classes can have static members, rather than a static inner classes can not have static
members. Therefore, A, B wrong 2. Static inner class can access non-static members of outer class's
static variables, and can not access to external class non-static variables; return d1 error.

Therefore, D wrong 3. Non-static inner class non-static members can access non-static variables outside
the class. Therefore, the correct C 4. Answer is C, E

7, garbage collection mechanism, how to optimize the process?


Hope that we make up, thank you

8, float-type float f = 3.4 correct?


Answer: not correct. Precision is not accurate, should be cast as follows: float f = (float) 3.4

9, introduced JAVA in the Collection FrameWork (including how to write your own data structure)?
Answer: Collection FrameWork is as follows:
Collection
├ List
│ ├ LinkedList
│ ├ ArrayList
│ └ Vector
│ └ Stack
└ Set
Map
├ Hashtable
├ HashMap
└ WeakHashMap
Collection is the most basic set of interfaces, a Collection on behalf of a group of Object, the Collection
element (Elements)
Map provides a mapping key to value

10, Java exception-handling mechanisms, the event mechanism?

11, JAVA Multi-shape and inheritance?


Hope that we make up, thank you

12, abstract classes and interfaces?


A: Abstract classes and interfaces are used for the abstract, but abstract class (JAVA Chinese) can have
their own part of the implementation, while the interface is totally a logo (and have multiple inheritance
functionality).

13, Java's communication programming, programming questions (or question and answer), with JAVA
SOCKET programming, read a few characters in the server, and then written to the local show?
A: Server-side programs:
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-side 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 (new InputStreamReader (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 ();
)
);

14, using JAVA to achieve a sort, JAVA class implements serialization methods (two kinds)? If
COLLECTION framework, to achieve more to realize what kind of interface?
Answer: The insertion sort code 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 <num; 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 <al.size (); 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 <MaxSize; 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 <al.size (); i + +)
(
System.out.println ( "al [" + i +"]="+ al.get (i));
)
)
public static void main (String [] args)
(
InsertSort is = new InsertSort (10,100);
is.SortIt ();
)
)
JAVA class implements ordered cases of the method is to achieve java.io.Serializable interface
Collection framework to achieve more to achieve the Comparable interface and Comparator interfaces

15, programming: write an interception of a string function, input a string and the number of bytes, the
output for the interception by-byte string. However, to ensure that characters are not cut by half, such
as "I ABC" 4, should be cut for the "I AB", enter "I ABC Han DEF", 6, should be output as "I ABC" instead
of "I am half-ABC + Han month. "
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: '" + SplitStr + "'; 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 in the dd text dsaf in men and 43 Chinese people in China 3443n

0ewldfls = 103 ", 4);


ss.SplitIt ();
)
)

16, JAVA multi-threaded programming. Use JAVA to write a multi-threaded programs, such as writing
four threads, two plus one, two pairs of a variable by one, the output.
Hope that we make up, thank you

17, STRING and STRINGBUFFER difference.


Answer: STRING the length of immutable, STRINGBUFFER length is variable. If you string the contents of
the regular operation, especially when you want to modify the content, then the use of StringBuffer, if
the last required String, then use the StringBuffer the toString () method

Jsp connection

1, jsp What are the built-in objects? What is the role of each?
Answer: JSP total of the following nine kinds of basic built-in components (ASP-6 with the corresponding
internal components):
request the client request, this request will be included from the GET / POST request parameters
response page returned to the client's response
pageContext page is here to manage property
session session associated with the request period of
application servlet is running the contents of the
used to send out the output response
config servlet framework components
page JSP page itself,
exception for the error page, does not capture the exception
2, jsp What are the actions? What is the role of each?
Answer: JSP total of the following six kinds of basic movements
jsp: include: when the page is requested the introduction of a file.
jsp: useBean: Find or instantiate a JavaBean.
jsp: setProperty: Set JavaBean properties.
jsp: getProperty: Output to a JavaBean property.
jsp: forward: the request to a new page.
jsp: plugin: according to the type of browser plug-ins for the Java generated OBJECT or EMBED tag

3, JSP dynamic INCLUDE the difference between static INCLUDE?


A: Dynamic INCLUDE with jsp: include action to achieve
<jsp:include page="included.jsp" flush="true" /> it always checks the changes contained in the
document, suitable for containing dynamic pages, and can be used with parameters include a static
INCLUDE pseudo-code implementation, scheduled for the changes contained in the file does not check
for static pages containing
<% @ Include file = "included.htm"%>

4, two kinds of jump, respectively, for what? What is the difference?


A: There are two kinds, namely:
<jsp:include page="included.jsp" flush="true">
<jsp:forward page= "nextpage.jsp"/>
Shift include the former page is not referring to the page will display the results page, home page or the
original face page. The implementation would come back exhausted, equivalent to function call. And can
take parameters. Which is completely turned a new page and will not come back. The equivalent of go
to statements.

Servlet context

1, talk about Servlet life cycle?


Answer: servlet has a good definition of the survival period, including the loading and instantiating,
initializing, processing requests and service end. The survival period from javax.servlet.Servlet interface,
init, service, and destroy methods to express.

2, Servlet version of the rooms (forgot to ask is which of two versions of) the same?
Hope that we make up, thank you

3, JAVA SERVLET API in the forward () and redirect () the difference?


Answer: the former is only the steering control of the container, the client browser's address bar does
not show the address after the shift; the latter is completely jump, the browser will be jump address,
and re - send requests link. In this way, from the browser's address bar you can see the link after the
jump. Therefore, the former is more efficient, in the former satisfy the need, to make use of forward ()
method, and so also help to hide the actual link. In some cases, for example, need to jump to an other
resources on the server, you must use sendRedirect () method.

4, Servlet's basic structure


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 aspects

1, it may let you write a Jdbc with Oracle procedures and data queries.
A: The procedure is as follows:
package hello.ant;
import java.sql .*;
public class jdbc
(
String dbUrl = "jdbc: oracle: thin: @ 127.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 use?


A: The call of the visit to return a string that specifies the class name of the class object.

3, Jdo What is this?


Answer: JDO is a Java object persistence of the new norms for the short java data object is a data
warehouse for access to certain objects in the standardization of API. JDO provides a transparent object
storage, so developers, the stored data objects no additional code (such as the JDBC API in use). These
tedious routine work has been transferred to the JDO products provider body, so that developers freed
to focus time and energy on the business logic. In addition, JDO is flexible because it can run on the
bottom of any data. JDBC is oriented relational database (RDBMS) JDO more general, provide any data
to the underlying storage capabilities, such as relational databases, files, XML and object databases
(ODBMS), etc., making applications more portable.

4, large amounts of data in the ORACLE page under the solution. A general way with the interception of
ID, there is a three-nested approach.
Answer: 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 intPageCount = 1;
intPageCount = (i% numPages == 0)? (i / numPages): (i / numPages +1);
int nextPage;
int upPage;
nextPage = currentPage +1;
if (nextPage> = 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 <numPages * (currentPage-1)) & & rs.next ()) (i + +;)
%"
/ / Output
/ / Output to connect next page Total: <% = currentPage %>/<%= intPageCount%> <a href="List.jsp?
page=1"> first page </ a> <a

href = "List.jsp? page = <% = upPage%>"> Previous </ a>


"%
for (int j = 1; j <= intPageCount; j + +) (
if (currentPage! = j) (
%"
<a href = "list.jsp? page = <% = j %>">[<%= j %>]</ a>
"%
) else (
out.println (j);
)
)
%"
<a href = "List.jsp? page = <% = nextPage%>"> page </ a> <a href = "List.jsp? page = <% = intPageCount
%>"> Last Page

</ a>

Xml in

1, xml parsing what technology? What is the difference?


A: DOM, SAX, STAX, etc.
DOM: the performance when dealing with large files down a lot. This problem is caused by DOM tree
structure, this structure occupy more memory, and the DOM have to parse the file before the entire
document into memory, suitable for XML, random access SAX: not currently in the DOM, SAX is event-
driven XML parsing methods. It is in order to read XML documents, do not need to load the entire file all
at once. When confronted with such as beginning of the document, the document ended with the tag or
label at the beginning of the end, it will trigger an event, users write in their callback event handling
code to handle XML files, suitable for XML-sequential access
STAX: Streaming API for XML (StAX)

2, in your project, use the xml technology, what aspects? How to achieve it?
A: The use of data storage, information, configured in two ways. Doing data exchange platform, the data
will not be assembled into a data source XML file, and then encrypted XML file compression package
sent to the recipient through the network, receive decryption and decompression with the XML file and
then restore the relevant information for processing. Do the software configuration, the use of XML can
be easily carried out, the software of various configuration parameters are stored in XML files.

3, using jdom parse xml file how to solve the Chinese problem? How to parse?
A: See the following code, with the encoding to be resolved
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 a king 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.setOutputProperty (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 using JAVA parse XML approach.


A: The way to use SAX parsing XML, XML documents are as follows:
<? xml version = "1.0" encoding = "gb2312"?>
<person>
<name> Xiao-Ming Wang </ name>
<college> School of Information </ college>
<telephone> 6258113 </ telephone>
<notes> male, 1955, Health, Ph.D., 95 years, transferred to Hainan University </ notes>
</ person>
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 length)
throws SAXException
(
currentValue = new String (ch, start, length);
)
public void endElement (String name) throws SAXException
(
if (currentElement.equals (name))
table.put (currentElement, currentValue);
)
)
JSP content display source code, SaxXml.jsp:
<HTML>
<HEAD>
<TITLE> Parsing XML documents people.xml </ TITLE>
</ HEAD>
<BODY>
<% @ Page errorPage = "ErrPage.jsp"
contentType = "text / html; charset = GB2312"%>
<% @ Page import = "java.io. *"%>
<% @ Page import = "java.util.Hashtable"%>
<% @ Page import = "org.w3c.dom .*"%>
<% @ Page import = "org.xml.sax .*"%>
<% @ Page import = "javax.xml.parsers.SAXParserFactory"%>
<% @ Page import = "javax.xml.parsers.SAXParser"%>
<% @ Page import = "SAXHandler"%>
"%
File file = new File ( "c: \ people.xml");
FileReader reader = new FileReader (file);
Parser parser;
SAXParserFactory spf = SAXParserFactory.newInstance ();
SAXParser sp = spf.newSAXParser ();
SAXHandler handler = new SAXHandler ();
sp.parse (new InputSource (reader), handler);
Hashtable hashTable = handler.getTable ();
out.println ( "<TABLE BORDER=2> <CAPTION> Teacher Information Form </ CAPTION>");
out.println ( "<TR> <TD> Name </ TD>" + "<TD>" +
(String) hashTable.get (new String ( "name")) + "</ TD> </ TR>");
out.println ( "<TR> <TD> College </ TD>" + "<TD>" +
(String) hashTable.get (new String ( "college "))+"</ TD> </ TR>");
out.println ( "<TR> <TD> Phone </ TD>" + "<TD>" +
(String) hashTable.get (new String ( "telephone")) + "</ TD> </ TR>");
out.println ( "<TR> <TD> Notes </ TD>" + "<TD>" +
(String) hashTable.get (new String ( "notes")) + "</ TD> </ TR>");
out.println ( "</ TABLE>");
%"
</ BODY>
</ HTML>

Anda mungkin juga menyukai