Consider the following Java source:
if( agents != null ) {
for( Iterator iter = agents.keySet().iterator(); iter.hasNext(); ) {
// Code that uses iter.next() ...
//
}
}
The agents is a HashMap.
Why does the for statement sometimes throw a NullPointerException?
Thank you.
I was reading that JavaDoc for Threadlocal here
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ThreadLocal.html
and it says
"ThreadLocal instances are typically private static fields in classes that wish to associate state with a thread (e.g., a user ID or Transaction ID). "
But my question is why did they choose to make it static (typically) - it makes it a bit confusing to have "per thread" state but its static?
if we supposed that "A.B." is a value for an xml element called given-names
the following code converts this value to "A.tempspacetempspaceB." instead of "A. B."
foreach (XElement initial in doc.XPathSelectElements("//given-names"))
{
string v = initial.Value.Replace(".", ". ").TrimEnd(' ');
initial.SetValue(v);
}
So why tempspace comes here instead of literal space??
thank you for any help.
I have found myself doing a lot of work to get nHibernate setup and am left wondering: Why use a framework like Hibernate/NHibernate? I am sure that quite a few people love the framework but I am unclear on the advantages and disadvantages. What are the advantages and disadvantages of lazy loading, and are there other features to Hibernate? Is there anything that makes a framework like this easier to use (best practices, other frameworks, etc)?
Hi guys.
Dose anyone knows why I have to use -use-network=false in my Flex Builder?!?!?!
This is set inside the Project Properties and is Additional compiler argument.
This is only when I want to read in a external file like XML.
Others in my team doesn't have to have -use-network=false ????
In Java, to create and show a new JFrame, I simply do this:
public static void main(String[] args)
{
new JFrame().setVisible(true);
}
However, I have seen many people doing it like this:
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
new JFrame().setVisible(true);
}
});
}
Why? Are there any advantages?
I believe the expression T() creates an rvalue (by the Standard)
However the following code compiles (at least on gcc4.0)
class T {... };
int main()
{
T() = T();
}
I know technically this is possible because member functions can be invoked on temporaries and the above is just invoking the operator= on the r-value temporary created from T().
But conceptually this is like assigning a new value to an r-value.
Is there a good reason why this is allowed?
I have a homework assignment with a number of questions. One is asking why the strcpy() function doesn't need the call by reference operator for CStrings. I've looked through the book numerous times and I can't, for the life of me, find the answer. Can anyone help explain this to me?
It is an array of sorts so I would think you would need the call by reference.
Why public InputStream getResourceAsStream(String name) is in Class class? It just give inputstream of file which is in jar file and there is no relation with Class class. so it can be static method and it can be in any class.
The following code prints randomly 634, 635, 636, each time I run it. Why its not constant?
public static void main(String[] args) throws Exception {
KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA", "BC");
keyPairGen.initialize(1024);
RsaKeyPair keyPair = new RsaKeyPair(keyPairGen.generateKeyPair());
System.out.println(keyPair.getPrivate().getEncoded().length);
}
I noticed that in Linux kernel 2.4 setscheduler doesn't force need_resched. Why is that? is it just some convention, or does that happens somewhere else?
I know there is the perl regex that is sort of a minor de facto standard, but why hasn't anyone come up with a universal set of standard symbols, syntax and behaviors?
Hi Experts,
I am clueless to find out why should we use static method with JSON. Is it possible that I click a button and I load a gridview with JSON ??
Thanks in advance
Why doesn't the compiler automatically put break statements after each code block in the switch? Is it for historical reasons? When would you want multiple code blocks to execute?
1.What is the point of creating a class that can't be instantiated?
Most commonly to serve as a base-class or interface (some languages have a separate interface construct, some don't) - it doesn't know the implementation (that is to be provided by the subclasses / implementing classes)
2.Why would anybody want such a class?
For abstraction and re-use
3.What is the situation in which abstract classes become NECESSARY?can anyone brief it with an example?
I have used Microsoft.SqlServer.Smo.dll and Microsoft.SqlServer.ConnectionInfo.dll in a number of VS2008 projects but they don't appear in the VS2010 Add Reference dialog. Why did they disappear and how can I add them to my VS2010 project?
Hello,
I am just wondering why programmers who program in C++ for windows always use Visual Studio 6 instead of Visual Studio 2008?
Isn't the compiler in 2008 much better than the one in VS6?
The reason I ask as I have used many sdk's that are always written in VS6?
Many thanks,
Steve
Why is CompareAndSwap instruction considered expensive?
I read in a book:
"Memory barriers are expensive, about as
expensive as an atomic compareAndSet()
instruction."
Thanks!
This question goes out to those who have used Tapestry as a web framework and then either gave it up or switched to something else, or even ported their application from Tapestry to something else.
The question is why? What led you to make this change?
EDIT: Also, what framework (if any) did you change to?