Cached connections are kept in a runtime object pool and can be used and reused as needed by the application. One way to implement the object pool is to make a simple hashtable of connection objects. However, a more flexible way to do it is to write a wrapper JDBC Driver that is an intermediary between the client application and database.
.....
13. What's a reasonable limit on connection pool size for an average single application server?
I don't know.... 20?
....
14. Can that many connections cause problems for a database?
Yes(?) If the connection is persistent...?
(http://blog.powercam.cc/xms/doc/724)
(http://www.coderanch.com/t/216774/ORM/java/Too-many-Connections-Exception)
15. Is there a maximun number of connections limit defined in the database?
How do you change it?
( I don't know )
16. What is the Connections API and what are the advantange of using it?
The Connections framework provides a well-designed set for sorting and manipulating a group of data (a collection).
(http://www.allapplabs.com/java/java_collection_framework.htm)
a. The collection interface is a group of objects, which duplicates allowed.
b. Set extends Collection but NOT allow duplicates.
c. List extends Collection also, it allows duplicates and introduces positioning indexing.
d. Map extends neither Set nor Collection.
Interface | Implementation | Historical |
Set | HashSet |
| TreeSet |
|
|
List |
| ArrayList |
| LinkedList | Vector Stack |
Map | HashMap |
| Treemap |
| Hashtable Properties |
ArrayList是List(列表),数据是有序的,可以有重复元素 HashSet是Set(集合),数据没有顺序,没有重复元素,元素搜索速度快
17. Is Iterator inthe Collections API a class or an interface?
interface
18. What's the difference between a HashSet and an ArrayList?
HashSet can't have duplicate key/value, ArrayList can.
19. What's the difference between a HashSet and a HashMap?
a. HashSet doesn't allow duplcate, it maintains a unique list.
b. HashMap allows null for both keys and value, it's unsynchronized.
A HashMap provides fast access to a mapping from a unique key to a value. Keys are unordered which makes it faster than the TreeMap where the keys are ordered.
A HashSet is fast access to unique value only (there are no keys because it is not a mapping it's just the values). HashSet values are unordered which makes it faster than the TreeSet where the values are ordered.
20. Give an example of when you would use a HashMap?
If you may have null value in the collection, and the keys are unique but not in order...
21. What object do you use to determine if a user posesses a J2EE Role?
HttpRequest
22. What's the difference between an Integer and an int?
Object/Primitive
Object is using memory in Heap, Primitive is using memory in Stack.
(Check out Heap/Stack http://619lucky.blogspot.com/2010/09/java-stack-and-heap.html)
23. What methods are available on an int?
none.
23. What class do you use to convert between Integers, ints and Strings?
Integer
24. Are the methods you use to convert between Integers and ints class methods or instance methods?
Class method.
25. What does it mean for a method to be static?
Static methods use no instance variables of any object of the class. if you define a method to be static, you will be given a rude message by the compiler if you try to access any instance variables. You can access static variables, but except for constants.
Static methods typically take all the data from parameters and compute something from those parameters (with no reference to variables).
Static method is typical of methods which do some kind of generic calculation. A good example of this are the many uility methods in the predefined Math class.
宣告 method 時,如果前面加上 static 的修飾字,就會使得此 method 變成是 class method。對 class method 而言,永遠只佔用一塊記憶體,而且此記憶體空間是在此 class 一被載入進記憶體之後就立刻配置的,就如同此 method 是與該 class 本身相關,而不是與該 class 的 instance 相關。
26. What class do you use to manipulate Date objects in Java?
Calendar
27. What class do you use to format Date objects in Java?
DateFormat(abstract class) or SimpleDateFormat -subclass of DateFormat.
28. What is the difference between SAX based and DOM based XML parsing?
SAX is event based. DOM is tree navigation based.
29. When would you use one over the other?
SAX for XML based event processing. Large documents or memory constrained System.
DOM for XML document editing.
30. Tell about any XML binding tools you've used, or any other parsing techniques.
JAXB (Marschalling and UnMarshalling, Factory)....(?)
31. Schema and DTD
?????
32. What must a class do to implement an interface?
It must provide all of the methods in the interface and identify the interface in its implements clause.
33. What is an interface and what are they used for?
a. Capturing similarities among unrelated classes without arficially forcing a class relationship.
b. Declaring methods that one or more classes are expected to implement.
c. Revealing an object's programming interface without revealing its class.
34. Let's make up a system where we need to track electricity usage in a building. We have some objects that consume electricity (Monitor and Printer). We want to add an interface to the system that will define a method for determining the monitor or printer's electrical consumption.
Question: What should be a good name for this interface?
Answer: (通常是形容詞)something like Powerable, PluggedIn, ElectricityConsumer
Question: What would be a good name for a method in this interface and what would the method do?
Answer: (通常是動詞)getConsumption() returns the amount of power consumed.
Question: Let's create an Exception that will be thrown by the getConsumption method when the object is not plugged in. What's good name for that exception?
Answer: NotPluggedInException. PlugInFailException.
35.