Wednesday, June 23, 2004

To except(ion) or not to accept
The usage of checked exceptions in Java has been one of the debatable concepts recently and IMHO it makes sense . seeing the misuse of the exception handling , i can understand the issue about it.

For those who came in late, the big debate is the misuse of the checked exceptions in that the programmers can circumvent the exceptions by either swallowing it or still worse throw an RuntimeException or a subclass of it.
Both the approaches violate the principle of checked exceptions that the user needs to know that there is a risk of something going wrong in the program and hence declare it "throws". The errors (RuntimeException ) on the other hand signify that these are not to be handled and are a result of abnormal conditions and for errors it is not required that the user declare "throws" clause

Also the checked exceptions should be caught and re-thrown at different levels to avoid the coupling of the tiers . Assuming that the EJBTier throws an exception indicating that one of the subsystem failure, this exception has to be caught in the Web tier and an different exception needs to thrown wrapping in it the other exception .The J2SE 1.4 provides an way to wrap the reason in it by providing an constructor which takes in a Throwable object and also an method initcause which takes Throwable as an argument. Using either of the above , one can wrap an exception and throw it doing so will require minimal changes only to the web tier in case the ejb tier changes and no changes to the classes which call the web tier.

On the flip side the code for exception handling becomes more bulkier in that u have a nested of catch blocks trying to catch the exception.

One more way to do this might be to have some constants within the checked exception describing about the errorcodes majorCode and minorCode, major code indicating the severity of the exception as business error or system error ,the minor code would indicate the nature of the exception say "Login failure " or "Dup primary key exists" this approach is for u if u dont mind writing catch block and doing a li'l bit of parsing ... By using this approach the users of this program mainly have to just check the code and act accordingly and a single exception could suffice

see Bruce Eckel's suggestions here

Tuesday, June 08, 2004

Some Java trivia
Here are some of the questions posed to me
Unfortunately i"m not including answers for them

Happy solving ....

1. Static method overriding concepts
2. Pass-by-value concepts read my blog
3. Collections Usage of HashMap ,ArrayList
4.static methods and variables
5.Thread concepts
6.Internationalization and Locales
7. J2EE container Diff components
8.equals() and ==
9. Case scenario coding
10. JMS RemoteQueue PUB/SUB message properties, PTP,
11. JDBC diff types of drivers
12 Diff between AWT and Swing
13. What are the various stages in JVM while loading of the classes
14. Exception handling How do you write your own custom exception class
15.diff kinds of operations provided by HTTP protocol
16. a get request is sent to the servlet which has only doPOSt() defined what will happen
17. How do we load the same connection object twice
18. Difference between POST and Get
19.MessageDrivenBeans concepts and case scenario
20.HOw does MDB differ from session Bean
21.RMI HttpTunneling concepts, stub and skeleton
22. Clustering concepts
23.Diff between String and StringBuffer
24.Diff between ArrayList and Vector
25 Concepts of requestDispatcher.fwd and response.sendRedirect
26.Design Patterns COmmand, Singleton, Mediator, Factory
27.Session replication and Session caching
28. SAX DOM parser JAXP and JAXB
29. Thread program
30. How do we send multiple responses to the client indicating the server is processing the request
THe request is a single request and the user needs to know how the progress o
31.What are the properties of the MessageBody in JMS
32. Diff types of Paradigms in Messaging
33.App server security concepts
34.In what location do u put the classes in a web application
35.In 2 interfaces you declare a variable with the same name what happens when in a class if u extend these
2 interfaces
36. What would happen if u have the same method declaration in both of these interfaces
37.What is Aggregation, Composition, Association and Inheritance
38. What is meant by synchronization