Beruflich Dokumente
Kultur Dokumente
Answer :
ii)It makes it easier to write programs that gracefully handle the failure of file system operations.
Answer :
Checked Exception:
i)Every class that is a subclass of Exception except RuntimeException and its subclasses falls into the
category of checked exceptions.
ii)You must ?handle or declare? these exceptions with a try or throws statement.
Unchecked Exception:
ii)You may use a try-catch statement to help discover the source of these exceptions, but when an
application is ready for production use, there should be little code remaining that deals with
RuntimeException and its subclasses.
Answer :
i)public: The public keyword indicates that the method can be accessed from anyobject in a Java
program.
ii)static: The static keyword is used with the main() method that associates the method with its class. You
need not create an object of the class to call the main() method.
iii)void: The void keyword signifies that the main() method returns no value.
Answer :
i)Many methods did not throw exceptions when they failed, so it was impossible to obtain useful error
messages.
v)More support for metadata was desired, such as file permissions, file owner, and other security
attributes.
vi)Accessing file metadata was inefficient?every call for metadata resulted in a system call, which made
the operations very inefficient.
vii)Many of the File methods did not scale. Requesting a large directory listing on a server could result in
a hang.
viii)It was not possible to write reliable code that could recursively walk a file tree and respond
appropriately if there were circular symbolic links.
5.Identify the five classes of the java.util.concurrent package and explain any two classes.
Answer :
ii)CountDownLatch: A very simple yet very common utility for blocking until a given number of signals,
events, or conditions hold.
iv)Phaser: Provides a more flexible form of barrier that may be used to control phased computation
among multiple threads.
v)Exchanger: Allows two threads to exchange objects at a rendezvous point, and is useful in several
pipeline designs.
6.Steve has been asked to automate the Library Management System either in C++ or Java. Steve has
chosen to develop the project in Java. Identify the reason.
Answer :
One of the major problem areas in most of the object-oriented languages, such as C++, is to handle
memory allocation. Programmers need to explicitly handle memory in the program for its optimum
utilization. To handle memory allocation, they use pointers that enable a program to refer to memory
location of the computer. However, Java does not support pointers and consists of the built-in
functionality to manage memory.
7.You have created a class with two instance variables.You need to initialize the variables automatically
when a class is initialized. Identify the method that you will use you to achieve this. In addition, describe
the characteristics of this method.
Answer :
You can initialize the variable by using the constructor. The characteristics of a constructor are:
- There is no return type for a constructor. A constructor returns the instance of the class instead of a
value.
- A constructor is used to assign values to the data members of each objectcreated from a class
Answer :
1.The methods of a Java interface are implicitly abstract and cannot have implementations. A Java
abstract class can have instance methods that implements a default behavior.
2.Variables declared in a Java interface are by default final. An abstract class may contain non-final
variables.
3.Members of a Java interface are public by default. A Java abstract class can have the usual flavors of
class members like private, protected, etc..
4.Java interface should be implemented using keyword, implements; A Java abstract class should be
extended using keyword, extends.
5.An interface can extend another Java interface only, an abstract class can extend another Java class and
implement multiple Java interfaces.
6.A Java class can implement multiple interfaces but it can extend only one abstract class.
7.Interface is absolutely abstract and cannot be instantiated; A Java abstract class also cannot be
instantiated, but can be invoked if a main() exists.
8.In comparison with Java abstract classes, Java interfaces are slow as it requires extra indirection.