There are two ways to handle exceptions,
1. By wrapping the desired code in a try
block followed by a catch block to catch the
exceptions. and 2. List the desired
exceptions in the throws clause of the method
and let the caller of the method hadle those
exceptions.
Q:
Are the imports checked for validity at compile time? e.g. will the code containing an import such as java.lang.ABCD com compile sucessfully?
A:
Yes the imports are checked for the semantic validity at compile time. The code containing above line of import will not compile. It will throw an error saying,can not resolve symbol
symbol : class ABCD
location: package io
import java.io.ABCD;
Q:
What are checked exceptions?
A:
Checked exception are those which the Java compiler forces you to catch. e.g. IOException are checked Exceptions
Q:
How can container knows that JSP has been changed ? ex: I created one.jsp and the result has been displayed. Next i modified one.jsp and got the new result. but how can container know that one.jsp has got changed?
A:
By checking the "time stamp" of the jsp file
.
Q:
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.
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"
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();
To call a constructor of the superclass, just write super(); in the first line of the subclass's constructor
.
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 methods. .