Thursday 7 July 2016

Basics Interview Questions Of Java For Beginners Part-3

Question 51:- Describe the different stages in the life cycle of an applet.

Answer:- The stages in the life cycle of an applet are-

1. Born or initialization state

2. Running state

3. Idle state

4. Dead or destroyed state

Born or initialization state: - Applet enters the initialization state when it is first loaded. This is achieved by calling the init () method of Applet class. The applet is born. At this stage, we may do the following if required

a) Create objects needed by the applet

b) Set up initial values

c) Load images or fonts

d) Set up colors

The initialization occurs only once in the applet’s life cycle. To provide any of the behaviours ,we must override the init() method.

Running state: - Applet enters the running state when the system calls the start( ) method of Applet Class. This occurs automatically after the applet is initialized. Starting can also occur if the Applet is already in ‘stopped” ( idle) state. For example, we may leave the web page containing the applet temporarily to another page and return back to the page. This again starts the applet running. Note that, unlike init( ) method, the start( ) method may be called more than once. We may override the start( ) method to create a thread to control the applet.

Idle or stopped state: - An applet becomes idle when it is stopped from running. Stopping occurs automatically when we leave the page containing the currently running applet. We can also do so by calling the stop( ) method explicitly. If we use a thread to run the applet, then we must use stop( ) method to terminate the thread. We can achieve this by overriding the stop( ) method;

Dead state: - An applet is said to be dead when it is removed from memory. This occurs automatically by invoking the destroy( ) method when we quit the browser. Like initialization, destroying stage occurs only once in the applet’s life cycle. If the applet has created any resources, like threads, we may override the destroy( ) method to clean up these resources.

Question 52 :- What is event handling?

Answer :- 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.

Question 53:- Name some of the key events?

Answer:- Some of the key events are:

1.ActionEvent is triggered whenever a user interface element is activated, such as selection of a menu item.

2. ItemEvent is triggered at the selection or deselection of an itemized or list element, such as checkbox.

3. TextEvent is triggered when a text field is modified.

4. WindowEvent is triggered whenever a window – related operation is performed, such as closing or activating a window.

Question 54:- Define Event Listeners.

Answer:- The event listener object contains methods for receiving and processing event notifications sent by the source object. These methods are implemented from the corresponding listener interface contained in the java.awt.event package.

Question 55 :-Define Event Classes.

Answer:- All the events in java have corresponding event classes associated with item. Each of these classes is derived from one single super class, i.e., EventObject. It is contained in the java.util package. The EventObject class contains the following two important methods for handling events:

1. getSource(): Returns the event source.

2. toString (): Returns a string containing information about the event source.

Question 56: How is java’s coordinate system organized?

Answer:- Java’s coordinate system has the origin (0, 0) in the upper–left corner. Positive x values are to the right, and positive y values are to the bottom. The values of coordinates x and y are in pixels.

Question 57:- Describe the arguments used in the method drawRoundRect( ).

Answer:- The drawRoundRect() method takes 6 arguments:-The first two represent the x and y coordinates of the top left corner of the rectangle,and the next two represent the width and the height of the rectangle and the remaining two represent the width and height of the angle of corners.

Question 58 :- What is AWT?

Answer:-The Abstract Windowing Toolkit ( AWT) IS AN APL that is responsible for building the Graphical User Interface ( GUI). It is a part of java Foundation Classes (JFC). AWT includes a rich set of user interface components, a powerful event handling model, graphics and image tools, layout managers and support for data transfer using cut and paste through clipboards. AWT also supports JavaBeans architecture. Every AWT component is a simple bean. The java.awt package contains all classes for creating user interfaces and for painting graphics and image.


Question 59 :- What is Component?

Answer:- Component class is the super class to all the class to all the other classes from which various GUI elements are realized. It is primary responsible for effecting the display of a graphic object on the screen. It also handles the various keyboard and mouse events of the GUI application.

Question 60:- What is Container?

Answer:- The Container object contains the other awt components. It manages the layout and placement of the various awt components within the container. A container object can contain other containers objects as well; thus allowing nesting of containers.

Question 61:- What is Window?

Answer:- The Window object realizes a top-level window but without any border or menu bar. It just specifies the layout of the window. A typical window that you would want to create in your application is not normally derived from the Window class but from its subclass, i.e., Frame.

Question 62:- What is Panel?

Answer:- The super class of applet, Panel represents a window space on which the application’s output is displayed. It is just like a normal window having no border, title bar, menu bar, etc. A panel can contain within itself other panels as.

Question 63 :-What is Frame?

Answer:- The Frame object realizes a top-level window complete with border and menu bar. It supports common window- related events such as close, open, activate, deactivate, etc. Almost all the programs that we created while discussing applets and graphics programming used one or more classes of the awt packaged.

Question 64:- Describe the arguments used in the method drawRoundRect ().

Answer:- The arguments used are the first two represent the x and y coordinates of the top left corner of the rectangle and the next two represent the width and height of the rectangle and the remaining two represent the width and height of the angle of the corners.

Question 65:- What is an Error?

Answer:- An error may produce an incorrect output or may terminate the execution of the program abruptly or even may cause in the program will not terminate or crash during execution.

Question 66 :- What are the types of Errors?

Answer:- Errors may broadly be classified into two categories:

1. Compile-time errors:- All syntax errors will be detected and displayed by the java compiler and therefore these errors are known as compile-time errors. Whenever the Compiler displays an error, it will not create the class file. It is therefore necessary that we fix all the errors before we can successfully compile and run the program.

2. Run-time errors:- Sometimes, a program may compile successfully creating the .class file but may not run properly. Such programs may produce wrong results due to wrong logic or may terminate due to errors such as stack overflow. This is called Run-time errors.

Question 67 :- Define exception.

Answer :- An exception is a condition that is caused by a run-time error in the program. When the java interpreter encounters an error such as dividing an integer by zero, it creates an exception object and throws it (i.e. informs us that an error has occurred. The purpose of exception handling mechanism is to provide a means to detect and report an “exceptional circumstance” so that appropriate action can be taken.

Question 68 :- How is Exceptions in java categorized?

Answer :- Exceptions in java can be categorised into two types:

1.Checked exceptions: These exceptions are exceptions are explicitly handled in the code itself with the help of try- catch blocks. Checked exceptions are extended from the java.lang.Eception class.

2. Unchecked exceptions: These exceptions are not essentially handed in the program code; instead the JVM handles such exceptions. Unchecked exceptions are extended from the java.lang.RuntimeException class.

Question 69 :- What is Persistent data?

Answer :- Data stored in files is often called Persistent data.

' Question 70 :- What is Object serialization?

Answer :- The process of reading and writing objects is called object serialization.

Question 71 :- What is a file?

Answer :- A file is a collection of related records placed in a particular area on disk.

Question 72 :- What is a record?

Answer :- A record is composed of several fields and a field is a group of characters.

Question 73 :- What is file processing?

Answer :- Storing and managing data using files is known as file processing which includes tasks such as creating files, updating files and manipulation of data.

Question 74:-What is a stream?

Answer:- A stream in java is a path along which data flows (like a river or a pipe along which water flows). It has a source (of data) and a destination (for that data).

Question 75 :- How is the concept of steams used in java?

Answer:- The concept of sending data from one stream to another (like one pipe feeding into another pipe) has made streams in java a powerful tool for file processing.

Question 76 :- What are input and output streams?

Answer:- Java streams are classified into two basic types, namely, input stream and output stream. An input stream extracts (i.e. reads) data from the source (file) and sends it to the program. Similarly, an output stream takes data from the program and sends (i.e. writes) it to the destination (file).

Question 77:- What is stream class? How are the stream class classified?

Answer:- The java.io package contains a large number of stream classes that provide capabilities for processing all types of data. These classes may be categorized into two groups based on the data type on which they operate.

1.Byte stream classes that provide support for handling I/O operations on bytes.

2. Character stream classes that provide support for managing I/O operations on characters.

Question 78:- Describe the major tasks of input and output stream classes.

Answer :- The super class InputStream is an abstract class, and, therefore, we cannot create instances of this class. Rather, we must use the subclasses that inherit from this class.

The InputStream class defines methods for performing input functions such as

1 Reading bytes

2 Closing streams

3 Marking Positions in streams

4 Skipping ahead in a stream

5 Finding the number of bytes in a stream

Outputstream is an abstract class and therefore we cannot instantiate it. The several subclasses of the OutputStream can be used for performing the output operations.

The Ouptputstream includes methods that are designed to perform the following tasks:

1 Writing bytes

2 Closing streams

3 Flushing streams

Question 79:- What is reader stream class?

Answer:- Reader stream classes are designed to read character from the files. The Reader class contains methods that are identical to those available in the Inputstream class, except reader is designed to handle characters.

Question 80 :- What is writer stream classes?

Answer:- The writer class is an abstract class which acts as a base class for all the other writer stream classes.

Question 81:- What is RandomAccessFile?

Answer:- The RandomAccessFile enables us to read and write bytes, text and java data types to any location in a file (when used with appropriate access permissions). This class extends object class and implements DataInput and Dataoutput interfaces. This forces the RandomAccessFile to implement the methpods described in both these interfaces.


Question 82:- What is Stream Tokenizer?

Answer:- The class Stream Tokenizer, a subclass of object can be used for breaking up a stream of text from an input text file into meaningful pieces called tokens. The behaviour of the Stream Tokenizer class is similar to that of the String Tokenizer class (of java.util Package) that breaks a string into its component tokens.

Question 83:-What is file class?

Answer:- The java.io package includes a class known as the File class that provides support for creating files and directories.

The class includes several constructors for maintaining the file objects. This class also contains several methods for  supporting the operations such as

1 Creating a file

2 Opening a file

3 Closing a file

4 Deleting a file

5 Getting a name of a file

6 Getting the size of a file

7 Checking the existence of a file

8 Renaming of a file

9 Checking whether the file is writable

1o Checking whether the file is readable

No comments:

Post a Comment