Why Java uses Classpath Parameter or Environment Variables?

In a Java class import statements are used to access other classes. You also do a wild card import like org.fromdev.* on your java file. In such cases, It will become very impractical/slow for the Java Virtual Machine to search for classes in every file/folder on a machine, therefore you can provide the Java Virtual … Read more

In Real Applications, how do you know that you have a Memory Leak

If you profile your application, you can notice a graph like a saw tooth. Here is how you can determine this with the help of jconsole for the above bad key class example. All you have to do is while your MemoryLeak is running, get the Java process id by typing. C:\>jps 5808 Jps 4568 … Read more

How will you Fix the Above Memory Leak

By providing proper implentation for the key class as shown below with the equals() and hashCode() methods.   ….. static class Key { private String key;   public Key(String key) { this.key = key; }     @Override public boolean equals(Object obj) {   if (obj instanceof Key) return key.equals(((Key) obj).key); else return false;   … Read more

How will you go About Creating a Memory Leak in Java

In Java, memory leaks are possible under a number of scenarios. Here is a typical example where hashCode( ) and equals( ) methods are not implemented for the Key class that is used to store key/value pairs in a HashMap. This will end up creating a large number of duplicate objects. All memory leaks in … Read more

What Happens when the index.jsp Page is Requested by the Client, if this page included instance variable and included in another jsp page. .

A JSP Page, Include.jsp, has a Instance Variable “int a”, now this Page is Statically Included in Another JSP Page, index.jsp, which has a Instance Variable “int a” Declared. What Happens when the index.jsp Page is Requested by the Client. Compilation error, as two variables with same name can’t be declared. This happens because, when … Read more