Define Hashtable,HashMap and HashSet »



Hashtable Hashtable is basically a datastructure to retain values of key-value pair. It didn’t allow null for both key and value. You will get NullPointerException if you add null value. It is synchronized. So it come with its cost. Only one thread can access in one time Hashtable<Interger,String>; cityTable=new Hashtable<Interger,String>(); cityTable.put(1,”Lahore”); cityTable.put(2,”Karachi”); cityTable.put(3,null); // NullPointerException [...]

Exception Handling and their uses »



Q)  What is the difference between ‘throw’ and ‘throws’ ?And it’s application? Rep) Exceptions that are thrown by java runtime systems can be handled by Try and catch blocks. With throw exception we can handle the exceptions thrown by the program itself. If a method is capable of causing an exception that it does not [...]

How to get a Leap Year »



import java.util.Calendar.*; import java.lang.*;  //its’ a default package which will import class LeapYear { public static void main(String args[])throws Exception { Calendar cal=Calendar.getInstance(); int year=cal.get(Calendar.YEAR); if(year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) {   System.out.println(“Leap Year”);          }else  { System.out.println(“Not a Leap Year);      } } }  // [...]

Define Jar,War,Ear file »



Q) What is EAR file Rep) Enterprise Archive file. A JAR archive that contains a J2EE application. Q) What is JAR file Rep) Java Archive file it contains a J2EE application. You can create a JAR file using the command jar cf XYZ.jar *.class *.gif if will compress all the .class files and the related [...]