What are the different types of inner classes?
A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses.
Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown. eg, IOException thrown by java.io.FileInputStream’s read() method
Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also.
Can I import the same package/class twice? Will the JVM load the package twice at runtime?
One can import the same package or same class multiple times. Neither compiler nor JVM complains abt it. And the JVM will internally load the class only once no matter how many times you import the same class.
Can I have multiple main methods in the same class?
No the program fails to compile. The compiler says that the main method is already defined in the class.
Can an application having multiple classes have a main method?
Yes it is possible. While starting the application we mention the class name to be run. The JVM will look for the Main method only in the class whose name you have mentioned. Hence there is not conflict amongst the multiple classes having main method.
What environment variables do I need to set on my machine in order to be able to run Java apps?
CLASSPATH and PATH are the two variables.
How can one prove that the array is not null but empty?
Print args.length. It will print 0. That means it is empty. But if it would have been null then it would have thrown a NullPointerException on attempting to print args.length.
What is the first argument of the string array in main method?
The String array is empty. It does not have any element. This is unlike C/C++ where the first element by default is the program name.
Java Interview Questions and Answers
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment