Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

51.

What Are Parsers? Dom Vs Sax Parser.

Answer»

Parsers are FUNDAMENTAL xml components, a bridge between XML documents and APPLICATIONS that process that XML. The parser is responsible for HANDLING xml syntax, checking the CONTENTS of the document against CONSTRAINTS established in a DTD or Schema.

Parsers are fundamental xml components, a bridge between XML documents and applications that process that XML. The parser is responsible for handling xml syntax, checking the contents of the document against constraints established in a DTD or Schema.

52.

Why Java Does Not Support Pointers?

Answer»

Because POINTERS are unsafe. JAVA uses reference types to HIDE pointers and programmers FEEL easier to deal with reference types without pointers. 

Because pointers are unsafe. Java uses reference types to hide pointers and programmers feel easier to deal with reference types without pointers. 

53.

What Is The Difference Between Swing And Awt Components?

Answer»

AWT components are heavy-weight, WHEREAS Swing components are lightweight. Heavy weight components DEPEND on the local windowing toolkit. For example, java.awt. Button is a heavy weight COMPONENT, when it is running on the Java platform for Unix platform, it MAPS to a REAL Motif button.

AWT components are heavy-weight, whereas Swing components are lightweight. Heavy weight components depend on the local windowing toolkit. For example, java.awt. Button is a heavy weight component, when it is running on the Java platform for Unix platform, it maps to a real Motif button.

54.

What Is Meant By "abstract Interface"?

Answer»

FIRST, an INTERFACE is abstract. That MEANS you cannot have any implementation in an interface. All the methods declared in an interface are abstract methods or signatures of the methods.

First, an interface is abstract. That means you cannot have any implementation in an interface. All the methods declared in an interface are abstract methods or signatures of the methods.

55.

In System.out.println( ), What Is System, Out And Println?

Answer»

SYSTEM is a PREDEFINED final CLASS, out is a PrintStream object and println is a built-in overloaded METHOD in the out object.

System is a predefined final class, out is a PrintStream object and println is a built-in overloaded method in the out object.

56.

What Is The Difference Between Final, Finally And Finalize?

Answer»

57.

What Is Quick Sort?

Answer»

For large arrays, you need an efficient sorting technique. One of the most efficient techniques is the QUICK SORT. The quick sort technique takes the middle element of an array and sub-divides the array into two smaller arrays. One array will contain elements greater than the middle value of the ORIGINAL array. Conversely, the other array will contain elements that are less than the middle value. The quick sort will repeat this process for each new array until the FINAL arrays contain only a single element. At this point, the single element arrays are in the proper ORDER, as shown below

For large arrays, you need an efficient sorting technique. One of the most efficient techniques is the quick sort. The quick sort technique takes the middle element of an array and sub-divides the array into two smaller arrays. One array will contain elements greater than the middle value of the original array. Conversely, the other array will contain elements that are less than the middle value. The quick sort will repeat this process for each new array until the final arrays contain only a single element. At this point, the single element arrays are in the proper order, as shown below

58.

Can A Private Method Of A Superclass Be Declared Within A Subclass?

Answer»

Sure. A private field or method or INNER class belongs to its DECLARED class and hides from its SUBCLASSES. There is no way for private stuff to have a runtime overloading or overriding (POLYMORPHISM) features.

Sure. A private field or method or inner class belongs to its declared class and hides from its subclasses. There is no way for private stuff to have a runtime overloading or overriding (polymorphism) features.

59.

What Is An Arrays?

Answer»

Sometimes you will need to manipulate a SERIES of related objects within an array object. Arrays let your programs work conveniently with a group of related objects. In short, an array simply lets you store and access a set of objects of the same type within the same variable. For example, you can use an array to keep TRACK of grades for fifty students or to store a series of file names.

Even though JAVA arrays are similar in syntax to C/C++ arrays, they have subtle differences. In Java, an array is basically an object that POINTS to a set of other objects or primitive data types. The only visible DIFFERENCE between arrays and objects is that arrays have a special syntax to make them behave like the arrays found in other languages. Unlike C and C++, however, Java arrays cannot change in size, nor can a program use an out-of-bound index with a Java array. Also, you declare and create arrays in Java very differently than in C/C++.

Sometimes you will need to manipulate a series of related objects within an array object. Arrays let your programs work conveniently with a group of related objects. In short, an array simply lets you store and access a set of objects of the same type within the same variable. For example, you can use an array to keep track of grades for fifty students or to store a series of file names.

Even though Java arrays are similar in syntax to C/C++ arrays, they have subtle differences. In Java, an array is basically an object that points to a set of other objects or primitive data types. The only visible difference between arrays and objects is that arrays have a special syntax to make them behave like the arrays found in other languages. Unlike C and C++, however, Java arrays cannot change in size, nor can a program use an out-of-bound index with a Java array. Also, you declare and create arrays in Java very differently than in C/C++.

60.

What Is The Epoch Date?

Answer»

Within a Java program, you can create a Date object by specifying a year, month, date and optionally, the hour, minute and SECOND as PARAMETERS to the constructor function. You can also create a Date object with no arguments to the constructor, in which case the Date object will contain the current date and TIME. Finally, you can create a Date object by specifying the number of milliseconds since the EPOCH date, which is midnight GMT, January 1st, 1970. The Date class USES the epoch date as a reference point which lets your programs refer to subsequent dates in terms of a single long integer. You cannot set a year before 1970.

Within a Java program, you can create a Date object by specifying a year, month, date and optionally, the hour, minute and second as parameters to the constructor function. You can also create a Date object with no arguments to the constructor, in which case the Date object will contain the current date and time. Finally, you can create a Date object by specifying the number of milliseconds since the epoch date, which is midnight GMT, January 1st, 1970. The Date class uses the epoch date as a reference point which lets your programs refer to subsequent dates in terms of a single long integer. You cannot set a year before 1970.

61.

How Java Uses The String And Stringbuffer Classes?

Answer»

Java strings are immutable, which means after you create a String OBJECT, you cannot change that object's contents. The Java designers found that most of the time, programmers do not need to change a string after it is created. By making String objects immutable, Java can provide better error protection and more efficient handling of strings. However, in CASE you do need to change the String, you can use a class called StringBuffer as a temporary "scratchpad" which you use to make changes. In short, your programs can change the String objects you store within a Stringbuffer and later copy the buffer's contents back to the String object after your alterations are complete.

In short, you should use String objects for "frozen" character strings whose contents you don't expect to change. In contrast, you should use the StringBuffer class for strings you expect to change in content or SIZE. Within your programs, you can take advantage of features from both classes because both provide methods to easily CONVERT between the two.

Java strings are immutable, which means after you create a String object, you cannot change that object's contents. The Java designers found that most of the time, programmers do not need to change a string after it is created. By making String objects immutable, Java can provide better error protection and more efficient handling of strings. However, in case you do need to change the String, you can use a class called StringBuffer as a temporary "scratchpad" which you use to make changes. In short, your programs can change the String objects you store within a Stringbuffer and later copy the buffer's contents back to the String object after your alterations are complete.

In short, you should use String objects for "frozen" character strings whose contents you don't expect to change. In contrast, you should use the StringBuffer class for strings you expect to change in content or size. Within your programs, you can take advantage of features from both classes because both provide methods to easily convert between the two.

62.

What Is The Destroy Method?

Answer»

Each time your applet ends, Java automatically calls the DESTROY method to free up memory the applet was using. The destroy method is the compliment of the init method. However, you normally do not need to override, the destroy method unless you have specific resources that you need to remove, such as large GRAPHICAL files or special threads that your applet has created. In short, the destroy method PROVIDES a convenient way to group your applet's "clean up" processing into ONE location, as shown:

PUBLIC void destroy() { // Statements here }

Each time your applet ends, Java automatically calls the destroy method to free up memory the applet was using. The destroy method is the compliment of the init method. However, you normally do not need to override, the destroy method unless you have specific resources that you need to remove, such as large graphical files or special threads that your applet has created. In short, the destroy method provides a convenient way to group your applet's "clean up" processing into one location, as shown:

63.

Explain The Init Method?

Answer»

When a Web browser (or an appletviewer) runs a Java applet, the applet's execution starts with the init method. Think of the Java init method as SIMILAR to the main function in C/C++, at which the program's execution starts. HOWEVER, UNLIKE the C/C++ main function, when the Java init method ends, the applet does not end. Most applets use init to initialize key variables (hence, the name init). If you do not supply an init method within your applet, Java will run its own default init method which is defined in the Applet class LIBRARY. The following statements illustrate the format of an init method:

public void init() { //statements }

The public keyword tells the Java compiler that another object (in this CASE, the browser) can call the init method from outside of the Applet class. The void keyword tells the Java compiler that the init method does not return a value to the browser. As you can see from the empty parentheses following the method name, init does not use any parameters.

When a Web browser (or an appletviewer) runs a Java applet, the applet's execution starts with the init method. Think of the Java init method as similar to the main function in C/C++, at which the program's execution starts. However, unlike the C/C++ main function, when the Java init method ends, the applet does not end. Most applets use init to initialize key variables (hence, the name init). If you do not supply an init method within your applet, Java will run its own default init method which is defined in the Applet class library. The following statements illustrate the format of an init method:

The public keyword tells the Java compiler that another object (in this case, the browser) can call the init method from outside of the Applet class. The void keyword tells the Java compiler that the init method does not return a value to the browser. As you can see from the empty parentheses following the method name, init does not use any parameters.

64.

What Is The Synchronized Method Modifier?

Answer»

JAVA supports multiple threads of execution which appear to execute simultaneously WITHIN your program. Depending on your program's processing, there may be times when you must guarantee that two or more threads cannot access method at the same time. To control the number of threads that can access a method at any one time, you USE the synchronized keyword. When the Java compiler encounters the synchronized keyword, the compiler will include special code that locks the method as one thread starts executing the method's instruction and later unlocks the method as the thread exits. Normally, programs synchronize methods that access shared data. The FOLLOWING statement illustrates the use of the synchronized keyword:

synchronized void refreshData( )

Java supports multiple threads of execution which appear to execute simultaneously within your program. Depending on your program's processing, there may be times when you must guarantee that two or more threads cannot access method at the same time. To control the number of threads that can access a method at any one time, you use the synchronized keyword. When the Java compiler encounters the synchronized keyword, the compiler will include special code that locks the method as one thread starts executing the method's instruction and later unlocks the method as the thread exits. Normally, programs synchronize methods that access shared data. The following statement illustrates the use of the synchronized keyword:

synchronized void refreshData( )

65.

What Is The Abstract Method Modifier?

Answer»

When the abstract keyword precedes a class method, you cannot create an instance of the class CONTAINING the method. Abstract METHODS do not provide an IMPLEMENTATION. Instead, your abstract method DEFINITION only indicates the arguments return type. When a subclass extends the class containing the abstract method, the subclass is required to supply the implementation for the abstract method. To declare a method abstract, simply provides the abstract keyword , as follows:
public abstract void implementMeLater(int x) ;

When the abstract keyword precedes a class method, you cannot create an instance of the class containing the method. Abstract methods do not provide an implementation. Instead, your abstract method definition only indicates the arguments return type. When a subclass extends the class containing the abstract method, the subclass is required to supply the implementation for the abstract method. To declare a method abstract, simply provides the abstract keyword , as follows:
public abstract void implementMeLater(int x) ;

66.

Can You Explain The Final Method Modifier?

Answer»

Java lets you extend ONE CLASS (the SUPERCLASS) with another (the subclass). When a subclass extends a class, the subclass can override the superclass methods. In some CASES depending on a method's , purpose, you may want to prevent a subclass from overriding a specific method. When you declare a class method as FINAL, another class cannot override the methods. Methods which you declare static or private are implicitly final. To declare a method as final, simply precede the method header with the final keyword, as shown:

public final CannotOverrideThisMethod();

Java lets you extend one class (the superclass) with another (the subclass). When a subclass extends a class, the subclass can override the superclass methods. In some cases depending on a method's , purpose, you may want to prevent a subclass from overriding a specific method. When you declare a class method as final, another class cannot override the methods. Methods which you declare static or private are implicitly final. To declare a method as final, simply precede the method header with the final keyword, as shown:

public final CannotOverrideThisMethod();

67.

Explain The Private Protected Method Modifier?

Answer»

Using the public, private and PROTECTED keywords, you can control a variable's scope. In a similar way, JAVA lets you use these attributes with class methods as well. A private protected METHOD is only visible WITHIN its class and within subclasses of the class. The difference between a protected method and a private protected method is that a private protected method is not accessible throughout the class package. To declare method as private protected, SIMPLY precede the method header with the private protected keyword, as shown:

private protected int myPrivateProtectedMethod();

Using the public, private and protected keywords, you can control a variable's scope. In a similar way, Java lets you use these attributes with class methods as well. A private protected method is only visible within its class and within subclasses of the class. The difference between a protected method and a private protected method is that a private protected method is not accessible throughout the class package. To declare method as private protected, simply precede the method header with the private protected keyword, as shown:

private protected int myPrivateProtectedMethod();

68.

What Is The Protected Method Modifier?

Answer»

Using the public, private and protected keywords, you can control a variable's scope. In a similar WAY, Java lets you USE these attributes with class methods as well. A protected method is only visible within its class, within subclasses or within the class package. To DECLARE a method as protected, simply precede the method header with the protected KEYWORD, as SHOWN:

protected int myProtectedMethod();

Using the public, private and protected keywords, you can control a variable's scope. In a similar way, Java lets you use these attributes with class methods as well. A protected method is only visible within its class, within subclasses or within the class package. To declare a method as protected, simply precede the method header with the protected keyword, as shown:

protected int myProtectedMethod();

69.

What Is The Private Method Modifier?

Answer»

Using the public, private and protected keywords, you can CONTROL a variable's scope. In a similar way, Java lets you use these attributes with CLASS methods as WELL. A private method is only visible within its class. Subclasses cannot access private methods. To declare a method as private, simply precede the method header with the private keyword, as shown:

private INT myPrivateMethod();

Using the public, private and protected keywords, you can control a variable's scope. In a similar way, Java lets you use these attributes with class methods as well. A private method is only visible within its class. Subclasses cannot access private methods. To declare a method as private, simply precede the method header with the private keyword, as shown:

private int myPrivateMethod();

70.

What Is The Public Method Modifier?

Answer»

Using the public, private and protected keywords, you can control a VARIABLE's scope. In a similar way, Java lets you use these ATTRIBUTES with class methods as well. A public method is visible everywhere that the class is visible. To declare a method as public, SIMPLY PRECEDE the method header with the public KEYWORD, as shown:

public float myPublicMethod();

Using the public, private and protected keywords, you can control a variable's scope. In a similar way, Java lets you use these attributes with class methods as well. A public method is visible everywhere that the class is visible. To declare a method as public, simply precede the method header with the public keyword, as shown:

public float myPublicMethod();

71.

What Is Default Constructors?

Answer»

When you CREATE your classes, you should always provide one or more CONSTRUCTOR methods. However, if you do not specify constructor, Java will provide a default constructor for you. Java's default constructor will ALLOCATE MEMORY to hold the object and will then initialize all instance variables to their DEFAULTS. Java will not provide a default constructor, however, if your class specifies one or more constructor for the class.

When you create your classes, you should always provide one or more constructor methods. However, if you do not specify constructor, Java will provide a default constructor for you. Java's default constructor will allocate memory to hold the object and will then initialize all instance variables to their defaults. Java will not provide a default constructor, however, if your class specifies one or more constructor for the class.

72.

Explain The Use Of Volatile Field Modifier?

Answer»

When you COMPILE a program, the COMPILER will examine your code and perform some "tricks" behind the scenes that optimize your program's PERFORMANCE. Under certain circumstances, you MAY want to force the compiler not to optimize a variable. Optimization can make certain assumptions about where and how memory is handled. If, for example, you are building an interface to memory-mapped device, you may need to suppress optimization. To protect a variable from being optimized, you should use the volatile keyword, as SHOWN:

volatile double system_bit_flags;

When you compile a program, the compiler will examine your code and perform some "tricks" behind the scenes that optimize your program's performance. Under certain circumstances, you may want to force the compiler not to optimize a variable. Optimization can make certain assumptions about where and how memory is handled. If, for example, you are building an interface to memory-mapped device, you may need to suppress optimization. To protect a variable from being optimized, you should use the volatile keyword, as shown:

volatile double system_bit_flags;

73.

Explain The Transient Field Modifier?

Answer»

When you declare a VARIABLE in a class TRANSIENT, you tell Java that the variable is not a part of the OBJECT's persistent state. Currently, Java does not use the transient keyword. However, future (persistent) versions of Java may use the transient keyword to tell the COMPILER that the program is using the variable for "scratch pad" purposes and that the compiler does not need to save the variable to disk. The following statement illustrates the use of the transient keyword:

transient float temp__swap__value;

When you declare a variable in a class transient, you tell Java that the variable is not a part of the object's persistent state. Currently, Java does not use the transient keyword. However, future (persistent) versions of Java may use the transient keyword to tell the compiler that the program is using the variable for "scratch pad" purposes and that the compiler does not need to save the variable to disk. The following statement illustrates the use of the transient keyword:

transient float temp__swap__value;

74.

What Is The Final Field Modifier?

Answer»

When you declare variable in a CLASS FINAL, you tell the compiler that the -variable has a constant value that program should not change. To DEFINE a final variable, you must also include an INITIALIZER that assigns a value to the constant. For example, the following statement creates a constant value NAMED MAXJCEYS, to which the program assigns the value 256:

protected static final int MAX_KEYS = 256;

When you declare variable in a class final, you tell the compiler that the -variable has a constant value that program should not change. To define a final variable, you must also include an initializer that assigns a value to the constant. For example, the following statement creates a constant value named MAXJCEYS, to which the program assigns the value 256:

protected static final int MAX_KEYS = 256;

75.

What Is The Static Field Modifier?

Answer»

Class member VARIABLES are OFTEN called INSTANCE variables because each instance of the class, each object, gets its own copy of each variables. Depending on your program's purpose, there may be times when the class objects NEED to share information. In such cases, you can specify one or more class variables as shared among the objects. To share a variable among class objects, you declare the variable as static, as shown:

PUBLIC static int ShareThisValue;

In this case, if object changes the value of the ShareThisValue variables, each object will see the updated value.

Class member variables are often called instance variables because each instance of the class, each object, gets its own copy of each variables. Depending on your program's purpose, there may be times when the class objects need to share information. In such cases, you can specify one or more class variables as shared among the objects. To share a variable among class objects, you declare the variable as static, as shown:

public static int ShareThisValue;

In this case, if object changes the value of the ShareThisValue variables, each object will see the updated value.

76.

Can You Explain The Private Protected Field Modifier?

Answer»

To control a class member VARIABLE's scope, you can precede the variable's DECLARATION with the PUBLIC, private or protected keywords. A private protected variable is only VISIBLE within its class and within subclasses of the class. The difference between a protected class member and a private protected variable is that a private protected variable is not ACCESSIBLE within its package. To declare a variable private protected, simply use the private protected keyword at the start of variable declaration, as shown:

private protected int ImPrivateProtected;

To control a class member variable's scope, you can precede the variable's declaration with the public, private or protected keywords. A private protected variable is only visible within its class and within subclasses of the class. The difference between a protected class member and a private protected variable is that a private protected variable is not accessible within its package. To declare a variable private protected, simply use the private protected keyword at the start of variable declaration, as shown:

private protected int ImPrivateProtected;

77.

Explain The Protected Field Modifier?

Answer»

To control a CLASS MEMBER variable's scope, you can precede the variable's declaration with the public, private ox protected keywords. A protected variable is one that is only visible within its class, within subclasses or within the package that the class is PART of. The different between a private class member and a protected class member is that & private class member is not accessible within a SUBCLASS. To declare a variable protected, simply use the protected keyword at the start of the variable declaration, as SHOWN:

protected int ImProtected;

To control a class member variable's scope, you can precede the variable's declaration with the public, private ox protected keywords. A protected variable is one that is only visible within its class, within subclasses or within the package that the class is part of. The different between a private class member and a protected class member is that & private class member is not accessible within a subclass. To declare a variable protected, simply use the protected keyword at the start of the variable declaration, as shown:

protected int ImProtected;

78.

Explain The Private Field Modifier?

Answer»

To control a class member variable's SCOPE, you can precede the variable's declaration with the public, private or protected key words. A private variable is only visible within its class. SUBCLASSES cannot access private variables. To declare a variable private, SIMPLY use the private KEYWORD at the START of the variable declaration, as shown:
private int InvisibleOutside;

To control a class member variable's scope, you can precede the variable's declaration with the public, private or protected key words. A private variable is only visible within its class. Subclasses cannot access private variables. To declare a variable private, simply use the private keyword at the start of the variable declaration, as shown:
private int InvisibleOutside;

79.

What Is The Public Field Modifier?

Answer»

A variable's scope defines the locations within a program where the variable is known. Within a class definition, you can control a class MEMBER variable's scope by preceding a variable's declaration with the public, PRIVATE or protected KEYWORDS. A public variable is visible (accessible) everywhere in the program where the class itself is visible (accessible). To declare a variable public, SIMPLY USE the public keyword at the start of the variable declaration, as shown:
public int seeMeEveryWhere;

A variable's scope defines the locations within a program where the variable is known. Within a class definition, you can control a class member variable's scope by preceding a variable's declaration with the public, private or protected keywords. A public variable is visible (accessible) everywhere in the program where the class itself is visible (accessible). To declare a variable public, simply use the public keyword at the start of the variable declaration, as shown:
public int seeMeEveryWhere;

80.

Explain The Public Class Modifier.

Answer»

As you DEVELOP Java programs, there may be times when you create classes that you don't WANT the code outside of the class package (the class file) to access or even to have the knowledge of.
When you USE the public keyword WITHIN a class DECLARATION, you make that class visible (and accessible) everywhere. A non-public class, on the other hand, is visible only to the package within which it is defined. To control access to a class, do not include the public keyword within the class declaration. Java only lets you place one public class within a source-code file. For example, the following statement illustrates the use of the public keyword within a class:

public class ImEverywhereYouWantMeToBe { }

As you develop Java programs, there may be times when you create classes that you don't want the code outside of the class package (the class file) to access or even to have the knowledge of.
When you use the public keyword within a class declaration, you make that class visible (and accessible) everywhere. A non-public class, on the other hand, is visible only to the package within which it is defined. To control access to a class, do not include the public keyword within the class declaration. Java only lets you place one public class within a source-code file. For example, the following statement illustrates the use of the public keyword within a class:

81.

What Is The Final Class Modifier?

Answer»

As you have learned, Java LETS one CLASS extend ANOTHER. When you design a class, there may be times when you don't want another programmer to extend the class. In such cases, by INCLUDING the final keyword within a class definition, you prevent the class from being subclassed. The following statement ILLUSTRATES the use of the final keyword within a class definition:

public final class TheBuckStopsHere { }

As you have learned, Java lets one class extend another. When you design a class, there may be times when you don't want another programmer to extend the class. In such cases, by including the final keyword within a class definition, you prevent the class from being subclassed. The following statement illustrates the use of the final keyword within a class definition:

82.

Explain The Abstract Class Modifier?

Answer»

As you have learned, Java lets you extend an existing CLASS with a subclass. Over TIME, you may start to develop your own class libraries whose classes you anticipate other programmers will extend. For some classes, there may be times when it does not make sense to implement a method until you KNOW how a programmer will extend the class. In such CASES, you can define the method as abstract, which forces a programmer who is extending the class to implement the method.

When you use the abstract keyword within a class, a program cannot create an instance of that class. As briefly discussed, abstract classes usually have abstract methods which the class did not implement. INSTEAD, a subclass extends the abstract class and the subclass must supply the abstract method's implementation. To declare a class abstract, simply include the abstract keyword within the class definition, as shown:

public abstract class Some abstract Class { }

As you have learned, Java lets you extend an existing class with a subclass. Over time, you may start to develop your own class libraries whose classes you anticipate other programmers will extend. For some classes, there may be times when it does not make sense to implement a method until you know how a programmer will extend the class. In such cases, you can define the method as abstract, which forces a programmer who is extending the class to implement the method.

When you use the abstract keyword within a class, a program cannot create an instance of that class. As briefly discussed, abstract classes usually have abstract methods which the class did not implement. Instead, a subclass extends the abstract class and the subclass must supply the abstract method's implementation. To declare a class abstract, simply include the abstract keyword within the class definition, as shown:

83.

What Is A Superclass?

Answer»

When you derive one class from another in Java, you establish relationships between the VARIOUS classes. The parent class (or the class it is being derived from) is OFTEN called the SUPERCLASS or BASE class. The superclass is really an ordinary class which is being extended by another class. In other words, you do not need to do anything special to the class in order for it to become a superclass. Any of the classes you write may some day become a superclass if someone decides to create a new subclass derived from your class.

Of course, you can prevent a class from BECOMING a superclass (that is, do not allow it to be extended). If you use the final keyword at the start of the class declaration, the class cannot be extended.

When you derive one class from another in Java, you establish relationships between the various classes. The parent class (or the class it is being derived from) is often called the superclass or base class. The superclass is really an ordinary class which is being extended by another class. In other words, you do not need to do anything special to the class in order for it to become a superclass. Any of the classes you write may some day become a superclass if someone decides to create a new subclass derived from your class.

Of course, you can prevent a class from becoming a superclass (that is, do not allow it to be extended). If you use the final keyword at the start of the class declaration, the class cannot be extended.

84.

How Does The Application Server Handle The Jms Connection?

Answer»
  1. App server creates the server session and stores them in a pool.
  2. Connection consumer USES the server session to put messages in the session of the JMS.
  3. Server session is the one that SPAWNS the JMS session.
  4. Applications written by the APPLICATION programmers creates the message listener.

85.

What Is Encapsulation?

Answer»

As you read articles and books about object-oriented programming and Java, you might ENCOUNTER the term encapsulation. In the simplest sense, encapsulation is the COMBINATION of data and methods into a single data structure. Encapsulation groups together all the components of an object. In the "object-oriented" sense, encapsulation also defines how your programs can reference an object's data. Because you can divide a Java class into public and private sections; you can control the degree to which class users can modify or access the class data. For example, programs can only access an object's private data USING public methods DEFINED within the class. Encapsulating an object's data in this way protects the data from program misuses. In Java, the class is the fundamental TOOL for encapsulation.

As you read articles and books about object-oriented programming and Java, you might encounter the term encapsulation. In the simplest sense, encapsulation is the combination of data and methods into a single data structure. Encapsulation groups together all the components of an object. In the "object-oriented" sense, encapsulation also defines how your programs can reference an object's data. Because you can divide a Java class into public and private sections; you can control the degree to which class users can modify or access the class data. For example, programs can only access an object's private data using public methods defined within the class. Encapsulating an object's data in this way protects the data from program misuses. In Java, the class is the fundamental tool for encapsulation.

86.

What Is Abstraction?

Answer»

Abstraction is the process of LOOKING at an object in terms of its methods (the operations), while temporarily ignoring the underlying details of the object's implementation. PROGRAMMERS use abstraction to simplify the design and implementation of complex programs. For example, if you are told to write a word processor, the task MIGHT at first seem insurmountable. However, using abstraction, you BEGIN to realize that a word processor actually consists of objects such as a document object that users will create, save, spell-check and print. By viewing programs in abstract terms, you can better understand the required programming. In Java, the class is the PRIMARY tool for supporting abstraction.

Abstraction is the process of looking at an object in terms of its methods (the operations), while temporarily ignoring the underlying details of the object's implementation. Programmers use abstraction to simplify the design and implementation of complex programs. For example, if you are told to write a word processor, the task might at first seem insurmountable. However, using abstraction, you begin to realize that a word processor actually consists of objects such as a document object that users will create, save, spell-check and print. By viewing programs in abstract terms, you can better understand the required programming. In Java, the class is the primary tool for supporting abstraction.

87.

What Is Object-oriented Programming?

Answer»

To programmers, an object is a collection of data and methods are a set of operations that MANIPULATE the data. Object-oriented programming provides a way of looking at programs in terms of the objects (things) that make up a system. After you have identified your system's objects, you can determine the operations normally performed on the object. If you have a DOCUMENT object, for example, common operations might include printing, spell-checking, faxing or even discarding.

Object-oriented programming does not REQUIRE a special programming LANGUAGE such as Java.You can write object-oriented programs in such languages as C++ or Java or C#. However, as you will learn, languages described as "object-oriented" normally provide class-based data structures that let your programs group the data and methods into one variable. Objects-oriented programming has many advantages, primarily object reuse and ease of understanding. As it turns out, you can often use the object that you write for one program in another program. Rather than building a collection of function libraries, object-oriented programmers build class libraries. Likewise, by grouping an object's data and methods, object-oriented programs are often more readily understood than their non-object- based COUNTERPARTS.

To programmers, an object is a collection of data and methods are a set of operations that manipulate the data. Object-oriented programming provides a way of looking at programs in terms of the objects (things) that make up a system. After you have identified your system's objects, you can determine the operations normally performed on the object. If you have a document object, for example, common operations might include printing, spell-checking, faxing or even discarding.

Object-oriented programming does not require a special programming language such as Java.You can write object-oriented programs in such languages as C++ or Java or C#. However, as you will learn, languages described as "object-oriented" normally provide class-based data structures that let your programs group the data and methods into one variable. Objects-oriented programming has many advantages, primarily object reuse and ease of understanding. As it turns out, you can often use the object that you write for one program in another program. Rather than building a collection of function libraries, object-oriented programmers build class libraries. Likewise, by grouping an object's data and methods, object-oriented programs are often more readily understood than their non-object- based counterparts.

88.

What Is Java Beans?

Answer»

JAVA Beans is the name of a project at JavaSoft to define a set of standard component software APIs (APPLICATION Programmers Interface) for the Java PLATFORM. By developing these standards, it becomes possible for software developers to DEVELOP reusable software components that end-users can then hook together using application-builder tools. In addition, these API's make it easier for developers to bridge to existing component models such as Microsoft's ActiveX, Apple's OpenDoc and Netscape's LiveConnect.

Java Beans is the name of a project at JavaSoft to define a set of standard component software APIs (Application Programmers Interface) for the Java platform. By developing these standards, it becomes possible for software developers to develop reusable software components that end-users can then hook together using application-builder tools. In addition, these API's make it easier for developers to bridge to existing component models such as Microsoft's ActiveX, Apple's OpenDoc and Netscape's LiveConnect.

89.

What Is The Java Idl System?

Answer»

The Interface DEFINITION Language (IDL) is an industry standard format useful for letting a Java client transparently invoke existing IDL object that reside on a remote server. In ADDITION, it ALLOWS a Java server to DEFINE objects that can be transparently invoked from IDL clients. The Java IDL system lets you define remote interfaces using the IDL interface definition language which you can then compile with the idlgen stub generator tool to GENERATE Java interface definitions and Java client and server stubs.

The Interface Definition Language (IDL) is an industry standard format useful for letting a Java client transparently invoke existing IDL object that reside on a remote server. In addition, it allows a Java server to define objects that can be transparently invoked from IDL clients. The Java IDL system lets you define remote interfaces using the IDL interface definition language which you can then compile with the idlgen stub generator tool to generate Java interface definitions and Java client and server stubs.

90.

What Is Java Jit Compilers?

Answer»
  • When your JAVA-enabled browser connects to a server and tries to VIEW a Web page that contains a Java applet, the server transmits the bytecode for that applet to your computer. Before your browser can run the applet, it must INTERPRET the bytecode data. The Java interpreter performs the task of interpreting the bytecode data.
  • As you have learned, using an interpreter to read bytecode files makes it possible for the same bytecode to run on any computer (such as a Window-based or Mac-based computer) that supports Java. The big drawback is that INTERPRETERS can be 20 to 40 times slower than code that was custom or native, for a specific computer.
  • As it turns out, a new type of browser-side software, called a Just-In-Time compiler (JIT), can convert (compile) the bytecode file directly into native code optimized for the computer that is browsing it. The JIT compiler will take the bytecode data sent by the server and compile it just before the applet needs to run. The compiled code will execute as fast as any application you already use on your computer. As you might expect, the major compiler and IDE manufacturers, such as Borland, Microsoft, Symantec and Metroworks, are all developing JIT compilers.

91.

What Is Remote Method Invocation (rmi)?

Answer»

As you develop more complicated Java APPLETS, and as other developers publish their own APPLET, you may find that you need to have your Java objects invoke other Java object methods residing on other computers. This is a natural extension of Java—you are able to USE Java-based resources throughout the Web to give your applet additional functionality. Remote Method Invocation (RMI) lets methods within your Java objects be invoked from Java code that may be running in a different virtual machine, often on another COMPUTER.

As you develop more complicated Java applets, and as other developers publish their own applet, you may find that you need to have your Java objects invoke other Java object methods residing on other computers. This is a natural extension of Java—you are able to use Java-based resources throughout the Web to give your applet additional functionality. Remote Method Invocation (RMI) lets methods within your Java objects be invoked from Java code that may be running in a different virtual machine, often on another computer.

92.

Why Call By Value Prevents Parameter Value Change?

Answer»
  • When you pass primitive types such as the types float, boolean, hit and char to a method, Java passes the variables by value. In other words, Java makes a copy of the original variable which the method can access and the original remains unchanged. Within a method, the code can change the values as much as it needs because Java created these values as copies of the originals.
  • WHEREVER you pass a primitive type as a parameter to a method, Java copies this parameter to a SPECIAL memory location known as the stack. The stack maintains information about variables used by the method while the method EXECUTES. When the method is complete, Java discards the stack's contents and the copies of the variables you passed into the method are gone FOREVER.
  • Because Java copies your original primitive type parameters, there is never any DANGER of a method altering your original values. Remember, this only applies to primitive types, which are automatically passed by value. Objects and arrays are not passed by value (instead they are passed by reference) and they are in danger of being changed.

93.

What Is The Primitive Type Short?

Answer»

The TYPE short is a primitive Java data type that uses TWO bytes to represent a number in the range -32768 to 32767. The Java type short is identical to the two-byte hit in many C/C++ COMPILERS.
The following statements declare two variables of type short:
short age;
short height, WIDTH;

The type short is a primitive Java data type that uses two bytes to represent a number in the range -32768 to 32767. The Java type short is identical to the two-byte hit in many C/C++ compilers.
The following statements declare two variables of type short:
short age;
short height, width;

94.

What Is The Primitive Type Byte?

Answer»

A byte is a primitive Java data type that uses eight BITES to represent a number ranging from -128 to 127. The following statements declare two byte VARIABLES. The FIRST variable, flag_bits, can store one value. The second byte variable, data_table, is an array, capable of HOLDING four VALUES. In this case, the Java compiler will preassign the array elements using the values specified between the left and right braces:

  • byte flag__bits;
  • byte data__table = { 32, 16, 8, 4 }; // Creates an array.

A byte is a primitive Java data type that uses eight bites to represent a number ranging from -128 to 127. The following statements declare two byte variables. The first variable, flag_bits, can store one value. The second byte variable, data_table, is an array, capable of holding four values. In this case, the Java compiler will preassign the array elements using the values specified between the left and right braces:

95.

What Is Java Literals?

Answer»

LITERALS correspond to a specific value in your Java program. For example, if you type the number 7 (the literal number 7) in a Java program, Java will treat the value as an int type. If you use the character JC WITHIN single quotes (V), Java will treat it as a char type. Likewise, if you PLACE the literal x within double quotes Ox'), Java will treat it as a String. Depending on the literal you are using, Java provides special rules for HEXADECIMAL, octal, characters, strings and BOOLEAN values. As you will learn, you can force a literal to be a certain type. For example, Java will treat the number 1 as an int. But you can force Java to treat the value as the type long by appending the L character to the literal number: 1L.

Literals correspond to a specific value in your Java program. For example, if you type the number 7 (the literal number 7) in a Java program, Java will treat the value as an int type. If you use the character JC within single quotes (V), Java will treat it as a char type. Likewise, if you place the literal x within double quotes Ox'), Java will treat it as a String. Depending on the literal you are using, Java provides special rules for hexadecimal, octal, characters, strings and boolean values. As you will learn, you can force a literal to be a certain type. For example, Java will treat the number 1 as an int. But you can force Java to treat the value as the type long by appending the L character to the literal number: 1L.

96.

What Is The Program Compilation Process?

Answer»

When you create programs, you will normally follow the same steps. To begin, you will use an editor to create your source file. Next, you will compile the program using a Java compiler. If the program CONTAINS syntax errors, you must edit the source file, correct the errors, and re-compile.
After the program successfully compiles, the compiler GENERATES a new file, KNOWN as bytecode. By using a Java interpreter, or appletviewer, you can execute the bytecode to test if it runs successfully. If the program does not work as you EXPECTED, you must REVIEW the source code to locate the error. After you correct the error, you must compile the source code to create a new byte code file. You can then test the new program to ensure that it performs the desired task. This illustrates the program development process.

When you create programs, you will normally follow the same steps. To begin, you will use an editor to create your source file. Next, you will compile the program using a Java compiler. If the program contains syntax errors, you must edit the source file, correct the errors, and re-compile.
After the program successfully compiles, the compiler generates a new file, known as bytecode. By using a Java interpreter, or appletviewer, you can execute the bytecode to test if it runs successfully. If the program does not work as you expected, you must review the source code to locate the error. After you correct the error, you must compile the source code to create a new byte code file. You can then test the new program to ensure that it performs the desired task. This illustrates the program development process.

97.

What Is Style And Indentation?

Answer»

As you write Java programs, you will discover that you have CONSIDERABLE flexibility in how you line your statements and INDENT lines. Some editor programs HELP you line up indented lines and indent NEW BLOCK. If you have already programmed in another language, you probably have your own style of indentation. Java does not impose any specific style, However, you may want to be consistent with your own style and always be conscious that a well-formatted program is easier to read and maintain. For example, the following two programs function equivalently. However, one is much easier to read than the other:

import java.applet. * ; public class am_i_readable extends Applet{public void init() { System.out.println("Can you guess whatI do?"); } } import java.applet.*; public class am__i_readable extends Applet { public void init() { System.out.println("Can you guess what I do?"); } }

As you write Java programs, you will discover that you have considerable flexibility in how you line your statements and indent lines. Some editor programs help you line up indented lines and indent new block. If you have already programmed in another language, you probably have your own style of indentation. Java does not impose any specific style, However, you may want to be consistent with your own style and always be conscious that a well-formatted program is easier to read and maintain. For example, the following two programs function equivalently. However, one is much easier to read than the other:

98.

What Is The Statements?

Answer»

A Java program consists of instructions that you want the computer to perform. WITHIN a Java applet, you USE statements to express these instructions in a format the Java compiler understands. If you are already familiar with C/C++, you will discover that Java statements are very similar. For example, the following statements produce a PROGRAMS which prints the words "Hello, Java!" in applet window:

import java.applet.*; import java.awt.Graphics;
public class hello_java extends Applet {
public void paint(Graphics g) {
g.drawstring("Hello, Java!", 20, 20); } }

A Java program consists of instructions that you want the computer to perform. Within a Java applet, you use statements to express these instructions in a format the Java compiler understands. If you are already familiar with C/C++, you will discover that Java statements are very similar. For example, the following statements produce a programs which prints the words "Hello, Java!" in applet window:

99.

Can You Explain The Cs Option Of Java Interpreter?

Answer»

When you develop Java using Sun's JDK, you normally compile your source by using the javac compiler. If no compile errors exist, you then run your application using the java interpreter. As a shortcut, you can specify the -cs COMMAND-line switch when you invoke the java interpreter. The java command, in TURN, will AUTOMATICALLY compile out-of-date (modified) source-code files for you.
By using the -cs switch, you can make changes to your source and IMMEDIATELY execute the java interpreter without having to manually run the java compiler yourself. The java interpreter knows which files it needs to recompile by comparing each file's MODIFICATION dates against the corresponding class modification date. Normally, programmers use the -cs option when they have made a minor change to the source files and know that the files contain no compilation errors. The following command illustrates the use of the -cs switch:

C: JAVACODE> Java -cs MyProgram <Enter>

When you develop Java using Sun's JDK, you normally compile your source by using the javac compiler. If no compile errors exist, you then run your application using the java interpreter. As a shortcut, you can specify the -cs command-line switch when you invoke the java interpreter. The java command, in turn, will automatically compile out-of-date (modified) source-code files for you.
By using the -cs switch, you can make changes to your source and immediately execute the java interpreter without having to manually run the java compiler yourself. The java interpreter knows which files it needs to recompile by comparing each file's modification dates against the corresponding class modification date. Normally, programmers use the -cs option when they have made a minor change to the source files and know that the files contain no compilation errors. The following command illustrates the use of the -cs switch:

100.

What Is The Difference Between Java Applets And Applications?

Answer»
  • With Java, you can create two types of programs: an applet or an application. As you have learned, a Java applet is a program that executes from within a Web browser. A Java application, on the other hand, is a program that is independent of the browser and can run as a standalone program.
  • Because an applet is run from within a Web browser, it has the advantage of having an existing vindow and the ability to respond to user interface events provided though the browser. In addition, because applets are designed for network use Java is much restrictive in the types of access that applets can have to your file SYSTEM than it is with non-network applications.
  • As you will, when you write a Java application, you must specify a main METHOD (much like the C/ C++ main), which the program executes when it begins. Within the main method, you specify the FUNCTIONALITY that your application performs. With an applet, on the other hand, you need to write additional methods that respond to events which are an IMPORTANT part of the applet's life cycle. The methods include INIT, start, stop, destroy and paint. Each of these events has a corresponding method and, when the event occurs, Java will call the appropriate method to handle it.
  • When you write your first Java programs, you can write them as if .they were applets and use the appletviewer to execute them. As it turns out, you can later convert your applet to an application by replacing your init method with a main method.