Wednesday, October 2, 2013

Java Quiz - 1


1. How many classes a class can extend?
 A java class can explicitly extend one class, but  implicitly it always extends object Class.

2.What is the Super class of a class?
 Object

3. Can we sort an arraylist?
  yes you can , using Collections.Sort(list);

4. Can we sort a Hashmap?
   yes you can.
   Map<String, String> mymap = new HashMap<String, String>();
   mymap.put("1" , "one" );
   mymap.put("2" , "Two" );
   mymap.put("3" , Three);
  Map<String , String> sortedMap = new TreeMap(String, String ) (myMap);

5. Where can we place a large integer ? short , byte or long int ?
   long

6. What is oop in java ?
 Object Oriented Programming

7. What value will be stored if i do not initialize an int?
 They contain garbage values. The last memory referenced value which is garbage collected.
 if you do not initialize, u will get a compiler error, variable not initialized.

8.Where to store a decimal value ? Double or float?
 usually when u deal with decimal value ,you prefer to use java.math.BigDecimal
 otherwise double (64-bit) can be used but float should not be used.

9. What is MVC?
 Model - view - Controller
have u worked on any MVC ?
yes  Struts2.0

10. What is Garbage Collection? Can it be forced?
System.gc() is used to force the garbage Collection . It cannot be guaranteed that Garbage Collection occurs once you issue System.gc() command, but when the garbage collector which is a daemon thread having priority 1 gets its CPU time it will execute the Garbage collection.

11. can a protected member  be accessed from a subclass outside the package?
 yes

12. Is String mutable?
 no string is immutable.

No comments:

Post a Comment