why objects are declared as both private and static at the same time

Static means global and private means access within that class only. Then how come they both be applied in one method.

following line describes the method which is declared both as static and final. Somebody please give me solution.

private static Object lookupHome(java.util.Hashtable environment, String jndiName, Class narrowTo) throws javax.naming.NamingException {

[388 byte] By [nusaira] at [2007-10-2 2:37:36]
# 1
Stuff can be declared both private and static (and also final).No problem. It can happen because they're different things which are not mutually exclusive at all.It's not clear to me what solution you need.
paulcwa at 2007-7-15 20:29:39 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2
Thank u so much for ur reply. But my doubt is not whether can i declare methods as static and private or not but why should i declare like that. I.e., why will i need to declare my method to be both private and static?Please give me the answer for WHY?
nusaira at 2007-7-15 20:29:39 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3

Because you want the method to be accessible only within the class.

When I've done it, it's just to keep things encapsulated. If you don't need the method or field accessible from outside the class, make it private, otherwise it might be used in ways you didn't anticipate. If it doesn't need instance state, make it static.

Some texts say to declare constants as "public static final", but I say to make them "private static final" if you don't have a specific reason why the constants need to be accessible outside the class.

paulcwa at 2007-7-15 20:29:39 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 4

Thank u Paul. I got it. So if a method is declared as both private and static then within that class without instantiating object one can access that method but not outside of it.

Paul if u could help me with another error "Cannot allocate servlet instance for the path" while deploying servlet in Eclipse, i will be much more pleased.

nusaira at 2007-7-15 20:29:39 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 5

If you have a private static method, it can be invoked by other static methods in that class, or it can be invoked by non-static methods inside that class.

A static method can only call other static methods, but a non-static method can call static methods.

I've never tried to deploy a servlet from inside Eclipse, so I can't help you with that.

paulcwa at 2007-7-15 20:29:39 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 6

> Paul if u could help me with another error "Cannot

> allocate servlet instance for the path" while

> deploying servlet in Eclipse, i will be much more

> pleased.

When people have errors using eclipse, I usually sugget they try one of the eclipse support forums.

Peter-Lawreya at 2007-7-15 20:29:39 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 7
Thank u so much for ur guidance.
nusaira at 2007-7-15 20:29:39 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...