Win a copy of Spring Boot in Practice this week in the Spring forum!

Gopal Shah

Ranch Hand
+ Follow
since May 17, 2003
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 Gopal Shah

Thanks Frank & Ilja, makes sense. So small well tested static util methods are acceptable but not as Component interfaces or for methods with side effects.
Thanks James. Is this a proven fact ? Are there any articles on this topic and is it considered a best practice.

I thought/considered Sun's Java APIs (especially java.lang) were very well designed. I know Sun doesn't use Agile methodology but then does that mean Agile leads one to a design which is different from traditional OO design.

Could there be performance issues, I am working on embedded environment. Martin Fowler & team preach that you shouldn't worry about performance in the beginning, but then I am wondering why "static behavior was introduced in the first place". Static state is shared across all the instances of the Class, but static behavior is typically a util method which could belong to some or other object. If the language didn't support static methods, then lots of bad coding practices could have been avoided (Java code written in procedural lang style).
Hi All,

I have been following the XP practices of writing unit test cases, then refactoring the code, etc.

I just noticed that my design hardly has any place for static util methods, especially if the method belongs to a 3rd party library.

e.g. if I were to test the following method:



Observation:
Typically computeCos..() is just a plain utility method, but I am tempted to make it an instance method of some object like MyMathUtils.

This is becoz when I am testing client code, I wud like to make a mock object MyMathUtil object (When testing client code, MyMathUtil is a secondary object)

I have given a simple stupid example of computeCosFun.., but consider a really complex static util method which itself invokes static native library methods, it would be very difficult to write test cases for the clients of MyMathUtil.computeCos...()

Easiest thing is to make computeCos...() an instance method of MyMathUtils even though I realize it doesn't use any state of MyMathUtils.

Eventually I realize there is hardly any role for static util methods when following Agile methodology

Any thoughts ?

Regards,
Gopal
Hi,

There is recruitment going on for my team. Req is as follows -
Skillset: Core Java, strong analytical skills
Exp: 6 months to 3 years (Freshers with SCJP score > 85%) can also apply. SCJD will be an added advantage.

About the position/domain/company -> We work on Set-top boxes, using J2me framework -> plenty of onsite trips, cool work env & a good pay package.

If interested, you can send me your CV and I will refer it in my company.

My email: gopalsofficial@gmail.com

Gopal
17 years ago
Will invalidating the session work ?
18 years ago
Hi,

I am displaying a html page using servlet. I want to disable the forward button in the browser.

I think it is something to do with HTTP header. But didn't feel comfortable going thru ietf and understanding the protocol.

Thanks & Regards,
Gopal
18 years ago
I think u have posted in the wrong forum. It shud have been in the Servlets forum.

Servlets r not part of the core language and hence u got that exception. Typically to run a servlet program u have to have some kind of servlet container like Tomcat. When u install apache tomcat, Servlet and JSP jar files r included with it. U can use any other webserver that is available.
18 years ago
Thanks Jose for the explanation. I now have got the answer to my questions. For all AWTEvents, the general procedure to fire events is calling processEvent method, which is supported by all the AWT & Swing Components. I tried it in my code and it worked. The source is provided below.

18 years ago
I found an example of non-gui events.

JSSE (Java Secure Sockets Extension), uses the standard event model.

a) HandshakeCompletedListener extends java.util.EventListener
b) HandshakeCompletedEvent extends java.util.EventObject

The source i.e. a particular SSLSocket object will add the event handler using addHandshakeCompletedListener() and remove using removeHandshakeCompletedListener().

But I still don't have an idea as how the event will be fired and how the handler gets the notification ?

Does it mean all the event objects have some private methods to notify which when invoked notifies the corresponding event handler object ?

Regards,
Gopals.
18 years ago
Thanks Greg for the reply. But I think I was looking for a different answer.

I was trying to understand the meaning of an event.

I got the definition of an event as:


Events are objects or messages used when a software components wants to notify a state change to other components.



As per my understanding the classification can be of 3 types.

1. System generated GUI events (All the events which inherit from java.awt.AWTEvent class as of JDK1.1
2. System generated non-gui events. I am really not sure how this is possible or don't have an example for this. But from the design perspective this shud be possible.
Let me guess something like a task manager.
3. User generated events. This can be a Event Source implementing observer design pattern in which event handlers can register with the event source for notification.

If this classification is correct, then do we follow any standards for all the three categories of events.

I mean all exceptions have a common root, all threads have a common root, all objects have a common root. So why not a common root for all kinds of events ?

There should be a standard mechanism for creation as well as firing of events.

Secondly, if system generated GUI events r something which should have been generated only by System, then why do we have public constructors for all such events. :roll:

I was again thinking over the difference between creating an instance of event and firing of an event.
What can a user do by creating an instance of a system event, if he cannot fire it ? or is there any way to fire the event.

Thanks in advance,
Gopals.
18 years ago
Hi All,

Is it possible to fire system events like ActionEvent or MouseEvent ?

Most of the constructors of these events require the event source and id of the event.

So lets say in some simulation project, I need a particular button to be clicked n number of times at m intervals.
So can I create an ActionEvent object with that button as source and then somehow fire the event at regular intervals instead of manually having to press the button.

Gopals.
18 years ago
I got the answer.
exportObject() method's purpose is to create the remote object stub.
If a RMI server doesn't extend UnicastRemoteObject, then automatically stub object is not created. To create the stub, one needs to invoke this method.
Answer to my question is
1. If server is not exported, it can't bind to the rmi registry and simply not function as rmi server, becoz the server stub object is not created.
2. If a server is exported more than once ???
What could possibly happen if I create more than one stub objects for the same server ?
This looks like a problem. This is what I understand. Correct me if I am wrong.
When a server is exported, a unique ObjID is associated with a server.
On the server side, the RMI runtime uses the deserialized instance of ObjID to figure out for which stub the remote method invocation is intended.
If there is more than one stub associated with a RMI server, than how would RMI runtime determine which stub to use. Using either stub would work, but ...
This could be a problem if RMI servers and the stubs r expected to have one to one mapping.
If that is the case, the developers of RMI shud never let a server to be exported more than once. It shud ideally throw an exception -> Remote exception as export would fail.
Gopals
[ May 12, 2004: Message edited by: Gopal Shah ]
18 years ago
Hi,
What happens if a thread tries to invoke UnicastRemoteObject.exportObject(server), if the server is already exported.
Does it throw an exception ?
Basically I didn't get the concept of exporting a server correctly. Does it mean that unless a RMI server is exported, we can't invoke methods on it ?
or is there any way by which we can invoke remote methods without exporting the server ?
Any info. regarding this will be helpful.
Thanx & Regards,
Gopals
18 years ago
Hi Priya,
U have just 1 thread right now, which u r trying to use for all the connections. Since u try to start the same thread more than once, it gives the exception.
Solution is :
Create a new thread once u have established the connection with the client. U can do this by creating an inner class and move the ref "s" into this class instead of having it in the JavaServer class. This is becoz u can't share the same client instance between all the threads. The ref s can point to different client after each connection.
It can be something like this

Then in the JavaServer class u can do the following:

I hope this clears your doubt.
Regards,
Gopals.
Hi Priya,
Could u specify the code for read(). It is difficult to figure out the problem without the code.
It looks like u r updating a shared variable (something like counter) for the thread to read the next message. In that case synchronization is necessary.
Gopals