Books Related to Java Technology

Sunday, January 25, 2009

Core JAVA Interview Questions & Answers-3

  1. What is constant variable in Java?
    The constant variable should be declared as static and final. So only one copy of the variable exists for all instances of the class and the value can't be changed.
  2. Should a main method be mandatory declared in all java classes?
    No it is not required. main method should be defined only if the source class is a java application.
  3. What is the return type of the main method?
    Main method doesn't return anything therefore it declared void.
  4. Why is the main method declared static?
    main method is called by the JVM yet before the instantiation of the class hence it is declared as static.
  5. What is the argument of main method?
    The main method accepts an array type of String object as an argument.
  6. Can main method be overloaded?
    Yes. You can have any number of main methods with different method signature and implementation in the class.
  7. Can a main method be declared final?
    Yes. Any inheriting class will not be able to have it's own default main method.
  8. Why isn’t there operator overloading? - Because C++ has proven by example that operator overloading makes code almost impossible to maintain. In fact there very nearly wasn’t even method overloading in Java, but it was thought that this was too useful for some very basic methods like print(). Note that some of the classes like DataOutputStream have unoverloaded methods like writeInt() and writeByte().
  9. How do I convert a numeric IP address like 192.168.10.204 into a hostname like javasks.blogspot.com?
     String hostname = InetAddress.getByName("192.168.10.204").getHostName();
  10. Why do threads block on I/O? - Threads block on I/O (that is enters in the waiting state) so that other threads may execute while the I/O operation is performed.
For More: http://worldinfosoft.com/interviewquestions/corejavainterview.html

No comments:

Post a Comment