Gitahi Ng'ang'a

Greenhorn
+ Follow
since Oct 30, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Gitahi Ng'ang'a

You use an Abstract class when you want to define a set of common (high level) behavior for a group of things. Think about a computer game in which a player walks though a forest full of wild animals. As he walks through the forest, he may encounter many different kinds of animals. The animals may attack him. Thus we want all animals to be able to attack the player. However, while a snake may attack by biting the player, an elephant may attack by trampling on him. This program can be expressed as follows.



Notice that in the beAttacked() method, we need not specify the specific kind of animal doing the attacking. Our abstract method attack() already guarantees that every animal can attack. What attack means is left to the specific animal to implement. Does that make it clearer?
13 years ago
Hi good people,

I am writing a prototype health information integration engine which is supposed to facilitate data sharing between clinics and other sources of health data such as research organizations. Data will be exchanged in HL7v3 format, which is based on XML and will be sent via HTTP. The problem is that this is happening across a unstable network necessitating a store and forward mechanism. As such a HTTP request sent from Computer A (the client) to Computer B (the server) cannot be satisfied by returning an immediate response because the network may not be up at that time. Once the store and forward mechanism does its thing at various routing points between Computer A and Computer B, the response to the original request comes back as a separate request originating from Computer B. How can I tell, without adding some extra metadata into the messages, which response is associated with which original request? I have seen something like using Java IDL to facilitate a kind of callback routine for Computer B (the server) to use when it has something for Compute A (the client), but I'm finding all this quite a hard to digest. Could anyone in the know point me in a promising direction? Links to candid tutorials and examples of this or any other technology I could use will be highly appreciated. Let me know if there is something you would like me to clarify.
13 years ago
Thank you Paul and Greg for your answers. I actually found a more straight forward way to send the content of my XML document as part of a HTTP request for my purposes. I just write out the string representation of my document into a URLConnection's OutputStream and voila! I was actually disliking having to use third party libraries so I am happy with this solution.
13 years ago
Hi everyone,

I am writing a packing and unpacking routine that converts an object to and from XML for the purpose of sending data (XML) over http. I am using the org.apache.commons.httpclient API. Specifically, I intend to call the setRequestEntity(RequestEntity) method of the PostMethod class. In creating a RequestEntity, I am required to pass an InputStream to the constructor. What I have, however, is only the Document (org.w3c.dom.Document) I get after packing my software object into XML. How can I create an InputStream on the basis of my document object?

Thanks.
13 years ago
Hi,

I want to create a container, say a JFRame, that is dockable on the desktop. It should be able to displace desktop icons and dock on any of the four edges of the desktop as happens with the Windows taskbar. My research so far has pointed me to the JDIC project but the only existing implementation is for linux. I want something that can work on Windows too.

Thanks.
14 years ago
I will assume you are asking that question with respect to Java EE 6. In that case, JSF implements the presentation. It uses Facelets as its View Definition Language.
The business layer is implemented in EJB's, which may be stateless or stateful session beans. The Java Persistence Api handles the data layer by allowing interaction with Entities (Data Classes) analogous to database tables. Let me know if you find this answer helpful or need further clarification.
14 years ago
Think about the following small program with the following Classes. Father, Mother and Son. Father has method provideBread(double money), mother has method buyBread(double money, Son son)and Son has method goToShop(double money). In order for the family to obtain bread, provideBread() is invoked on Father by passing his money, say 10.0. In turn, provideBread() invokes buyBread() on mother, passing the money and the specific son to send to the shop. The mother, as you would imagine, delegates the business of going to the shop to her Son by calling his goToShop() method. Now, on reaching the shop, several things (Exceptions) may happen. For instance, here may be no bread at the shop or the money passed by Father may not be enough. If the exception is that there is no bread at the shop, the son might very well handle it by checking in the next shop without requiring to inform any of his parents of that decision. In this case, Son Handles the exception, say BreadOutOfStockException. If however the money is not enough, the son will need to inform his mother of that fact (in other words, catch the say, MoneyNotEnoughException and instead of handling it, throw it to his mother). Of course the mother may handle the exception herself (if she is not broke, say broke) or "throw" it higherup to the father for him to worry about where to get more money (How to handle the exception).

Good luck!
14 years ago
The compiler is merely aware that 'a' is an object reference of type Animal. It does not know that indeed 'a' is specifically an object of type Dog. Consequently, it enforces the arrest of the potential exception it knows the method eat() of type Animal can potentially throw. For 'd', the compiler is fully aware that not only is 'd', an Animal it is indeed specifically a Dog. Thus the call to eat() will invariably be the overriding one declared in class Dog, and the compiler is smart enough understand that no excetion has been specified as potentially capable of being thrown by eat() defined thus.
14 years ago