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

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(HttpS...

Example for Registration using hibernate integration with struts2 and spring

First create a Pojo class for the Registeration form:     1)User.java                     package com.gklife.pojo; import com.gklife.RegisterDao.RegisterDao; public class User { private int id; private String name; private String Email; private String mobilenumber; private String password; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEmail() { return Email; } public void setEmail(String email) { Email = email; } public String getMobilenumber() { return mobilenumber; } public void setMobilenumber(String mobilenumber) { this.mobilenumber = mobilenumber; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String execute(){ ...

Top java programs for fresher

1) Write a program to find a repeated word? package com.repeat; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.HashMap; import java.util.Set; public class RepeatedWords { public static void main(String[] args)  { //Creating wordCountMap which holds words as keys and their occurrences as values                  HashMap<String, Integer> wordCountMap = new HashMap<String, Integer>();               BufferedReader reader = null;                   try         {             //Creating BufferedReader object                           reader = new BufferedReader(new FileReader("C:\\sample.txt"));         ...