Breakpoint hits Hashmap.put () a simple Hello World program

advertisements

Program is simple:

public class HelloWorld {
    public static void main(String args[]){
       System.out.println("Hello World");
    }
}

Now I set a breakpoint into function put(K key, V value) in HashMap.class

public V put(K key, V value) {
    if (table == EMPTY_TABLE) {
        inflateTable(threshold);
    }
    if (key == null)
        return putForNullKey(value);
    int hash = hash(key);

and then I start debugging the HelloWorld.class, it will run into the breakpoint in HashMap. It is strange to me that how it can run into put() in HashMap?
I tried HashMap, Hashtable and they are all the same.


Here is the stack trace I obtained when reproducing your scenario.

When the application is started by Eclipse, it does not simply enter the Main function. Your class needs to be loaded into the JVM, before creating an instance. For that, a Class Loader will be used.

In your case, URLClassLoader has a member of URLClassPath type that uses a HashMap object.