Monday, 31 August 2015

Java Questions & Answers : Set - II

19. Explain the benefits of packages.

By organizing the classes into packages, we achieve the following benefits :
The classes contained in the packages of other programs can be easily reused.
In packages, classes can be unique compared with classes in other packages. That is, two classes in two different packages can have the same name. They may be referred by their fully qualified name, comprising the package name and class name.
Packages provide a way to hide classes thus preventing other programs or packages from accessing classes that are meant for internal use only.
Packages also provide a way for separating design from coding. First, we can design classes and decide their relationships and then we can implement the Java code needed for the methods. It is possible to change the implementation of any method without affecting the rest of the design.

20. What is static import?

Static import is another language feature introduced with the J2SE 5.0 release. This feature eliminates the need of qualifying a static member with the class name.

21. What is multitasking?

In the modern operating systems such as Windows 7, several programs can be executed simultaneously. This ability is known as multitasking.

22. What is multithreading ?

Multithreading is a conceptual programming paradigm where a program (process) is divided into two or more subprograms (processes), which can be implemented/executed at the same time in parallel.
This is similar to dividing a task into sub-tasks and assigning them to different people for execution independently and simultaneously.

23. What is thread?

A thread is similar to a program that has a single flow of control. It has a beginning, a body and an end and executes commands sequentially.

24. What is concurrency?

The ability of a language to support multithreads is referred to as concurrency.

25. Why threads are known as lightweights processes?

Since threads in Java are subprograms of a main application program and share the same memory space, they are known as lightweight processes or lightweight threads.

26. In how many ways a thread an be created?

A new thread can be created in two ways :

By creating a thread class : Define a class that extends thread class and    override its run() method with the code required by the thread.
By converting a class to a thread : Define a class that implements    Runnable interface. The Runnable interface has only one method, run() that is to be defined in the method with the code to be executed by the thread.
27. Define the steps of extending the thread class.

Define the class as extending the Thread class.
Implement the run() method that is responsible for executing the sequence of code that the thread will execute.
Create a thread object and call the start() method to initialize the thread execution.

28. What are Local and Remote applets?

An applet developed locally and stored in a local system is known as a Local applet. When a web page is trying to find a local applet, it doesn’t need to use the Internet and therefore the local system doesn’t require the Internet connection. It simply searches the directories of the local system and locates and loads the specified applet.
Remote applet is that which is developed by someone else and stored on a remote computer connected to the Internet. If our system is connected to the Internet, we can download the remote applet onto our system via the Internet and run it.

29. Explain how applets differ from Applications.

Applets do not use the main() method for initializing the execution of the code. Applets, when loaded, automatically call certain methods of applet class to start and execute the applet code.
Unlike stand-alone applications, applets cannot be run independently. They are run from inside a web-page using a special feature known as HTML tag.
Applets cannot read from or write to the files in the local computer.
Applets cannot communicate with other services on the network.
Applets cannot run any program from the local computer.
Applets are restricted from using libraries from other languages such as C or C++.

30. What is event handling?

Event handling is a mechanism that is used to handle events generated by applets. An event could be the occurrence of any activity such as a mouse click or a key press. In Java, events are regarded as method calls with a certain task performed against the occurrence of each event.

31. Name some of the key events in Java.

Some of the key events in Java are:

Action event is triggered whenever a user interface element is activated,    such as selection of a menu item.
Item event is triggered at the selection or de-selection of an itemized or list  element, such as check box.
Text event is triggered when a text field is modified.
Window event is triggered whenever a window-related operation is  performed, such as closing or activating a window.
Key event is triggered whenever a key is pressed on the keyboard.

  

No comments:

Post a Comment