What is the difference between Exception & RuntimeException in Java? | ||
A: | RuntimeException is a child class of Exception class. You can see the details here. This is one of the many child classes of Exception class. RuntimeException is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtual Machine. A method is not required to declare in its throws clause any subclasses of RuntimeException that might be thrown during the execution of the method but not caught. The hierchy is java.lang.Object ---java.lang.Throwable -------java.lang.Exception -------------java.lang.RuntimeException http://java.sun.com/j2se/1.4.2/docs/api/java/lang/RuntimeException.html |
Q: | Is it possible to use try-catch in the finally block of java |
A: | Yes it is possible to use try catch inside the finally block of java. As a matter of fact it is a good practice to do so as the methods called in finally block may throw an exception. Importance: Highest |
Q: | What is the difference between ApplicationServer and webserver? |
A: | Web Server is limited to Web Technology and more over it can't deploy the entriprise applications. So inorder to deploy entriprise applications(EAR Files), we need Application Server. And More Over Web server supports all kinds of protocols not only http.It can support FTP and any, provided the concern jar files must be placed in the lib folder of the Web Server. |
Q: | Write a recursive programme to reverse a string i.e given an input "catch" the output should be "hctac" |
A: | public String reverse(String str) { if ((null == str) || (str.length() <= 1)) { return str; /*End */ } return reverse(str.substring(1)) + str.charAt(0); /* Recursion */ |
Q: | What's the difference between the methods sleep() and wait() |
A: | The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread. |
Q: | Can you call one constructor from another if a class has multiple constructors |
A: | Yes. Use this() syntax |
Q: | What would you use to compare two String variables - the operator == or the method equals()? |
A: | I'd use the method equals() to compare the values of the Strings and the == to check if two variables point at the same instance of a String object. |
Q: | How can a subclass call a method or a constructor defined in a superclass? |
A: | To call a method use the following syntax: super.myMethod(); |
Q: | What is the difference between an Interface and an Abstract class? |
A: | An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract metho |