Skip to main content

Important question in java with answers for Experienced and freshers


1)Why main method is static? Can we execute a program without main() method? If yes, how?

          Yes u can run java without main method , but make sure that your JDK is below 1.7. and   above 1.7 it will not be supported.

        *Static means it shared all the instance from the class and belong to the object type and not actual objects. 

2)How Weak hashmap Works?

     Weak hasmap operates like a normal hashmap but use weak reference for key. suppose if the key object doesn't device any reference then both key/value mapping will become appropriate for a garbage value.

3) how a.hascode() used for? how it is related to a.equals(b)?


          
           hashcode() methods returns an int hash value corresponding to an object. It is used in hash based based collection classes. eg Hashtable, Hashmap.
        According to the java specification, two objects which are identical to each other using equals() method needs to have same hashcode.

4)what is compile constant in java?


   public static final variable are known as compile time constant.

5)How do you print array in java?


    you can print an array by using the Arrays.toString() and Arrays.deeptoString() method. since Array does not implemented to String() by itself, just passing an array to the System.out .println() will not print its content but Array.to.String will print each element.

Comments

Popular posts from this blog

Commonly asked Top 26 Java Interview Questions

1.what is a transient variable? A transient variable is a variable that may not be serialized. If you don't want to serialize any objects then we have to use Transient Keyword. 2. Why do threads block on I/O? Threads block on i/o (that enters the waiting state) so that other threads may execute while the i/o Operation is performed. So your blocked thread of execution blocks only that: the thread of execution. 3. How are Observer and Observable used? Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects(refer 1.4). 4. What is synchronization and why is it important?                      With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Withou

All difference Question in java(common difference) (Collections)

1)Difference Between Interfaces And Abstract class? All the methods declared in the Interface are Abstract,where as abstract class must have atleast one abstract method and others may be concrete. In abstract class keyword abstract must be used for method, where as in Interface we need not use the keyword for methods. Abstract class must have Sub class, where as Interface can’t have sub classes.  An abstract class can extend only one class, where as an Interface can extend more than one. 2)Difference between Arrays and Vectors?             Because Vectors are dynamically-allocated, they offer a relatively memory-efficient way of handling lists whose size could change drastically. Arrays are fixed in size and it's wastage of memory problem. A Vector might be a good choice for such an arrangement. Moreover, Vectors have some useful member functions that make coding simpler. While in array is the bad choice of the arrangement and the code become more complex. Vecto

Decode of the image file from hibernate and struts

Create a java file for the decoding the image Image.java package com.img.action; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import javax.imageio.ImageIO; import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext; import com.img.dao.ConnectionDAO; import com.img.pojo.Film_TablePojo; import com.img.pojo.imagePojo; import com.opensymphony.xwork2.ActionSupport; public class Show extends ActionSupport { List<Object> values = new ArrayList<Object>();  public List<Object> getValues() { return values; } public void setValues(List<Object> values) { this.values = values; } /*HttpServletRequest request;     public void setServletRequest(HttpServletRequest