Tuesday, June 16, 2020

Java Interview Questions and Answers

Question 1. What Is The Most Important Feature Of Java?

Answer : Java is a platform independent language.

Question 2. What Do You Mean By Platform Independence?

Answer : Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (Linux,Solaris,etc).

Question 3. Are Jvm's Platform Independent?

Answer : JVM's are not platform independent. JVM's are platform specific run time implementation provided by the vendor.

Question 4. What Is A Jvm?

Answer : JVM is Java Virtual Machine which is a run time environment for the compiled java class files.

Question 5. What Is The Difference Between A Jdk And A Jvm?

Answer : JDK is Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM.

Question 6. What Is A Pointer And Does Java Support Pointers?

Answer : Pointer is a reference handle to a memory location. Improper handling of pointers leads to memory leaks and reliability issues hence Java doesn't support the usage of pointers.

Question 7. What Is The Base Class Of All Classes?

Answer : java.lang.Object

Question 8. Does Java Support Multiple Inheritance?

Answer : Java doesn't support multiple inheritance.

Question 9. Is Java A Pure Object Oriented Language?

Answer : Java uses primitive data types and hence is not a pure object oriented language.

Question 10. Are Arrays Primitive Data Types?

Answer : In Java, Arrays are objects.

Question 11. What Is Difference Between Path And Classpath?

Answer : Path and Classpath are operating system level environment variales. Path is used define where the system can find the executables(.exe) files and classpath is used to specify the location .class files.

Question 12. What Are Local Variables?

Answer : Local varaiables are those which are declared within a block of code like methods. Local variables should be initialised before accessing them.

Question 13. What Are Instance Variables?

Answer : Instance variables are those which are defined at the class level. Instance variables need not be initialized before using them as they are automatically initialized to their default values.

Question 14. How To Define A Constant Variable In Java?

Answer : The variable should be declared as static and final. So only one copy of the variable exists for all instances of the class and the value can't be changed also. static final int PI = 2.14; is an example for constant.

Question 15. Should A Main Method Be Compulsorily Declared In All Java Classes?

Answer : No not required. main method should be defined only if the source class is a java application.

Question 16. What Is The Return Type Of The Main Method?

Answer : Main method doesn't return anything hence declared void.

Question 17. Why Is The Main Method Declared Static?

Answer : main method is called by the JVM even before the instantiation of the class hence it is declared as static.

Question 18. What Is The Arguement Of Main Method?

Answer : main method accepts an array of String object as arguement.

Question 19. Can A Main Method Be Overloaded?

Answer : Yes. You can have any number of main methods with different method signature and implementation in the class.

Question 20. Can A Main Method Be Declared Final?

Answer : Yes. Any inheriting class will not be able to have it's own default main method.

Question 21. Does The Order Of Public And Static Declaration Matter In Main Method?

Answer : No it doesn't matter but void should always come before main().

Question 22. Can A Source File Contain More Than One Class Declaration?

Answer : Yes a single source file can contain any number of Class declarations but only one of the class can be declared as public.

Question 23. What Is A Package?

Answer : Package is a collection of related classes and interfaces. package declaration should be first statement in a java class.

Question 24. Which Package Is Imported By Default?

Answer : java.lang package is imported by default even without a package declaration.

Question 25. Can A Class Declared As Private Be Accessed Outside It's Package?

Answer : Not possible.

Question 26. Can A Class Be Declared As Protected?

Answer : A class can't be declared as protected. only methods can be declared as protected.

Question 27. What Is The Access Scope Of A Protected Method?

Answer : A protected method can be accessed by the classes within the same package or by the subclasses of the class in any package.

Question 28. What Is The Purpose Of Declaring A Variable As Final?

Answer : A final variable's value can't be changed. final variables should be initialized before using them.

Question 29. What Is The Impact Of Declaring A Method As Final?

Answer : A method declared as final can't be overridden. A sub-class can't have the same method signature with a different implementation.

Question 30. I Don't Want My Class To Be Inherited By Any Other Class. What Should I Do?

Answer : You should declared your class as final. But you can't define your class as final, if it is an abstract class. A class declared as final can't be extended by any other class.

Question 31. Can You Give Few Examples Of Final Classes Defined In Java Api?

Answer : java.lang.String,java.lang.Math are final classes.

Question 32. How Is Final Different From Finally And Finalize?

Answer : final is a modifier which can be applied to a class or a method or a variable. final class can't be inherited, final method can't be overridden and final variable can't be changed.

finally is an exception handling code section which gets executed whether an exception is raised or not by the try block code segment.

finalize() is a method of Object class which will be executed by the JVM just before garbage collecting object to give a final chance for resource releasing activity.

Question 33. Can A Class Be Declared As Static?

Answer : No a class cannot be defined as static. Only a method,a variable or a block of code can be declared as static.

Question 34. When Will You Define A Method As Static?

Answer : When a method needs to be accessed even before the creation of the object of the class then we should declare the method as static.

Question 35. What Are The Restriction Imposed On A Static Method Or A Static Block Of Code?

Answer : A static method should not refer to instance variables without creating an instance and cannot use "this" operator to refer the instance.

Question 36. I Want To Print "hello" Even Before Main Is Executed. How Will You Acheive That?

Answer : Print the statement inside a static block of code. Static blocks get executed when the class gets loaded into the memory and even before the creation of an object. Hence it will be executed before the main method. And it will be executed only once.

Question 37. What Is The Importance Of Static Variable?

Answer : static variables are class level variables where all objects of the class refer to the same variable. If one object changes the value then the change gets reflected in all the objects.

Question 38. Can We Declare A Static Variable Inside A Method?

Answer : Static variables are class level variables and they can't be declared inside a method. If declared, the class will not compile.

Question 39. What Is An Abstract Class And What Is It's Purpose?

Answer : A Class which doesn't provide complete implementation is defined as an abstract class. Abstract classes enforce abstraction.

Question 40. Can A Abstract Class Be Declared Final?

Answer : Not possible. An abstract class without being inherited is of no use and hence will result in compile time error.

Question 41. What Is Use Of A Abstract Variable?

Answer : Variables can't be declared as abstract. only classes and methods can be declared as abstract.

Question 42. Can You Create An Object Of An Abstract Class?

Answer : Not possible. Abstract classes can't be instantiated.

Question 43. Can A Abstract Class Be Defined Without Any Abstract Methods?

Answer : Yes it's possible. This is basically to avoid instance creation of the class.

Question 44. Class C Implements Interface I Containing Method M1 And M2 Declarations. Class C Has Provided Implementation For Method M2. Can I Create An Object Of Class C?

Answer : No not possible. Class C should provide implementation for all the methods in the Interface I. Since Class C didn't provide implementation for m1 method, it has to be declared as abstract. Abstract classes can't be instantiated.

Question 45. Can A Method Inside A Interface Be Declared As Final?

Answer : No not possible. Doing so will result in compilation error. public and abstract are the only applicable modifiers for method declaration in an interface.

Question 46. Can An Interface Implement Another Interface?

Answer : Intefaces doesn't provide implementation hence a interface cannot implement another interface.

Question 47. Can An Interface Extend Another Interface?

Answer : Yes an Interface can inherit another Interface, for that matter an Interface can extend more than one Interface.

Question 48. Can A Class Extend More Than One Class?

Answer : Not possible. A Class can extend only one class but can implement any number of Interfaces.

Question 49. Why Is An Interface Be Able To Extend More Than One Interface But A Class Can't Extend More Than One Class?

Answer : Basically Java doesn't allow multiple inheritance, so a Class is restricted to extend only one Class. But an Interface is a pure abstraction model and doesn't have inheritance hierarchy like classes(do remember that the base class of all classes is Object). So an Interface is allowed to extend more than one Interface.

Question 50. Can An Interface Be Final?

Answer : Not possible. Doing it will result in compilation error.

Question 51. Can A Class Be Defined Inside An Interface?

Answer : Yes it's possible.

Question 52. Can An Interface Be Defined Inside A Class?

Answer : Yes it's possible.

Question 53. What Is A Marker Interface?

Answer : An Interface which doesn't have any declaration inside but still enforces a mechanism.

Question 54. Which Oo Concept Is Achieved By Using Overloading And Overriding?

Answer : Polymorphism.

Question 55. If I Only Change The Return Type, Does The Method Become Overloaded?

Answer : No it doesn't. There should be a change in method arguements for a method to be overloaded.

Question 56. Why Does Java Not Support Operator Overloading?

Answer : Operator overloading makes the code very difficult to read and maintain. To maintain code simplicity, Java doesn't support operator overloading.

Question 57. Can We Define Private And Protected Modifiers For Variables In Interfaces?

Answer : No

Question 58. What Is Externalizable?

Answer : Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format. It has two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput in)

Question 59. What Modifiers Are Allowed For Methods In An Interface?

Answer : Only public and abstract modifiers are allowed for methods in interfaces.

Question 60. What Is A Local, Member And A Class Variable?

Answer : Variables declared within a method are "local" variables. Variables declared within the class i.e not within any methods are "member" variables (global variables). Variables declared within the class i.e not within any methods and are defined as "static" are class variables.

Question 61. What Is An Abstract Method?

Answer : An abstract method is a method whose implementation is deferred to a subclass.

Question 62. What Value Does Read() Return When It Has Reached The End Of A File?

Answer : The read() method returns -1 when it has reached the end of a file.

Question 63. Can A Byte Object Be Cast To A Double Value?

Answer : No, an object cannot be cast to a primitive value.

Question 64. What Is The Difference Between A Static And A Non-static Inner Class?

Answer : A non-static inner class may have object instances that are associated with instances of the class's outer class. A static inner class does not have any object instances.

Question 65. What Is An Object's Lock And Which Object's Have Locks?

Answer : An object's lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object's lock. All objects and classes have locks. A class's lock is acquired on the class's Class object.

Question 66. What Is The % Operator?

Answer : It is referred to as the modulo or remainder operator. It returns the remainder of dividing the first operand by the second operand.

Question 67. When Can An Object Reference Be Cast To An Interface Reference?

Answer : An object reference be cast to an interface reference when the object implements the referenced interface.

Question 68. Which Class Is Extended By All Other Classes?

Answer : The Object class is extended by all other classes.

Question 69. Which Non-unicode Letter Characters May Be Used As The First Character Of An Identifier?

Answer : The non-Unicode letter characters $ and _ may appear as the first character of an identifier.

Question 70. What Restrictions Are Placed On Method Overloading?

Answer : Two methods may not have the same name and argument list but different return types.

Question 71. What Is Transient Variable?

Answer : Transient variable can't be serialize. For example if a variable is declared as transient in a Serializable class and the class is written to an ObjectStream, the value of the variable can't be written to the stream instead when the class is retrieved from the ObjectStream the value of the variable becomes null.

Question 72. What Is Collection Api?

Answer : The Collection API is a set of classes and interfaces that support operation on collections of objects. These classes and interfaces are more flexible, more powerful, and more regular than the vectors, arrays, and hashtables if effectively replaces.

Example of classes: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap.

Example of interfaces: Collection, Set, List and Map.

Question 73. What Is Casting?

Answer : There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.

Question 74. What Is The Return Type Of A Program's Main() Method?

Answer : void.

Question 75. If A Variable Is Declared As Private, Where May The Variable Be Accessed?

Answer : A private variable may only be accessed within the class in which it is declared.

Question 76. What Do You Understand By Private, Protected And Public?

Answer : These are accessibility modifiers. Private is the most restrictive, while public is the least restrictive. There is no real difference between protected and the default type (also known as package protected) within the context of the same package, however the protected keyword allows visibility to a derived class in a different package.

Question 77. What Is Downcasting ?

Answer : Downcasting is the casting from a general to a more specific type, i.e. casting down the hierarchy.

Question 78. What Modifiers May Be Used With An Inner Class That Is A Member Of An Outer Class?

Answer : A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.

Question 79. How Many Bits Are Used To Represent Unicode, Ascii, Utf-16, And Utf-8 Characters?

Answer : Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns.

Question 80. What Restrictions Are Placed On The Location Of A Package Statement Within A Source Code File?

Answer : A package statement must appear as the first line in a source code file (excluding blank lines and comments).

Question 81. What Is A Native Method?

Answer : A native method is a method that is implemented in a language other than Java.

Question 82. What Are Order Of Precedence And Associativity, And How Are They Used?

Answer : Order of precedence determines the order in which operators are evaluated in expressions. Associatity determines whether an expression is evaluated left-to-right or right-to-left.

Question 83. Can An Anonymous Class Be Declared As Implementing An Interface And Extending A Class?

Answer : An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.

Question 84. What Is The Range Of The Char Type?

Answer : The range of the char type is 0 to 2^16 - 1.

Question 85. What Is The Range Of The Short Type?

Answer : The range of the short type is -(2^15) to 2^15 - 1.

Question 86. Why Isn't There Operator Overloading?

Answer : Because C++ has proven by example that operator overloading makes code almost impossible to maintain.

Question 87. What Does It Mean That A Method Or Field Is "static"?

Answer : Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class. Static methods can be referenced with the name of the class rather than the name of a particular object of the class (though that works too). That's how library methods like System. out. println() work. out is a static field in the java.lang.System class.

Question 88. Is Null A Keyword?

Answer : The null value is not a keyword.

Question 89. Which Characters May Be Used As The Second Character Of An Identifier,but Not As The First Character Of An Identifier?

Answer : The digits 0 through 9 may not be used as the first character of an identifier but they may be used after the first character of an identifier.

Question 90. Is The Ternary Operator Written X : Y ? Z Or X ? Y : Z ?

Answer : It is written x ? y : z.

Question 91. How Is Rounding Performed Under Integer Division?

Answer : The fractional part of the result is truncated. This is known as rounding toward zero.

Question 92. If A Class Is Declared Without Any Access Modifiers, Where May The Class Be Accessed?

Answer : A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.

Question 93. Does A Class Inherit The Constructors Of Its Superclass?

Answer : A class does not inherit constructors from any of its superclasses.

Question 94. Name The Eight Primitive Java Types.

Answer : The eight primitive types are byte, char, short, int, long, float, double, and boolean.

Question 95. What Restrictions Are Placed On The Values Of Each Case Of A Switch Statement?

Answer : During compilation, the values of each case of a switch statement must evaluate to a value that can be promoted to an int value.

Question 96. What Is The Difference Between A While Statement And A Do Statement?

Answer : A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.

Question 97. What Modifiers Can Be Used With A Local Inner Class?

Answer : A local inner class may be final or abstract.

Question 98. When Does The Compiler Supply A Default Constructor For A Class?

Answer : The compiler supplies a default constructor for a class if no other constructors are provided.

Question 99. If A Method Is Declared As Protected, Where May The Method Be Accessed?

Answer : A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.

Question 100. What Are The Legal Operands Of The Instanceof Operator?

Answer : The left operand is an object reference or null value and the right operand is a class, interface, or array type.

Question 101. Are True And False Keywords?

Answer :

The values true and false are not keywords.

Question 102. What Happens When You Add A Double Value To A String?

Answer :

The result is a String object.

Question 103. What Is The Diffrence Between Inner Class And Nested Class?

Answer :

When a class is defined within a scope od another class, then it becomes inner class. If the access modifier of the inner class is static, then it becomes nested class.

Question 104. Can An Abstract Class Be Final?

Answer :

An abstract class may not be declared as final.

Question 105. What Is Numeric Promotion?

Answer :

Numeric promotion is the conversion of a smaller numeric type to a larger numeric type, so that integer and floating-point operations may take place. In numerical promotion, byte, char, and short values are converted to int values. The int values are also converted to long values, if necessary. The long and float values are converted to double values, as required.

Question 106. What Is The Difference Between A Public And A Non-public Class?

Answer :

A public class may be accessed outside of its package. A non-public class may not be accessed outside of its package.

Question 107. To What Value Is A Variable Of The Boolean Type Automatically Initialized?

Answer :

The default value of the boolean type is false

Question 108. What Is The Difference Between The Prefix And Postfix Forms Of The ++ Operator?

Answer :

The prefix form performs the increment operation and returns the value of the increment operation. The postfix form returns the current value all of the expression and then performs the increment operation on that value.

Question 109. What Restrictions Are Placed On Method Overriding?

Answer :

Overridden methods must have the same name, argument list, and return type. The overriding method may not limit the access of the method it overrides. The overriding method may not throw any exceptions that may not be thrown by the overridden method.

Question 110. What Is A Java Package And How Is It Used?

Answer :

A Java package is a naming context for classes and interfaces. A package is used to create a separate name space for groups of classes and interfaces. Packages are also used to organize related classes and interfaces into a single API unit and to control accessibility to these classes and interfaces.

Question 111. What Modifiers May Be Used With A Top-level Class?

Answer :

A top-level class may be public, abstract, or final.

Question 112. What Is The Difference Between An If Statement And A Switch Statement?

Answer :

The if statement is used to select among two alternatives. It uses a boolean expression to decide which alternative should be executed. The switch statement is used to select among multiple alternatives. It uses an int expression to determine which alternative should be executed.

Question 113. Can A Method Be Overloaded Based On Different Return Type But Same Argument Type ?

Answer :

No, because the methods can be called without using their return type in which case there is ambiquity for the compiler

Question 114. What Happens To A Static Var That Is Defined Within A Method Of A Class ?

Answer :

Can't do it. You'll get a compilation error

Question 115. How Many Static Init Can You Have ?

Answer :

As many as you want, but the static initializers and class variable initializers are executed in textual order and may not refer to class variables declared in the class whose declarations appear textually after the use, even though these class variables are in scope.

Question 116. What Is The Difference Between Method Overriding And Overloading?

Answer :

Overriding is a method with the same name and arguments as in a parent, whereas overloading is the same method name but different arguments

Question 117. What Is Constructor Chaining And How Is It Achieved In Java ?

Answer :

A child object constructor always first needs to construct its parent (which in turn calls its parent constructor.). In Java it is done via an implicit call to the no-args constructor as the first statement.

Question 118. What Is The Difference Between The Boolean & Operator And The && Operator?

Answer :

If an expression involving the Boolean & operator is evaluated, both operands are evaluated. Then the & operator is applied to the operand. When an expression involving the && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. The && operator is then applied to the first and second operands. If the first operand evaluates to false, the evaluation of the second operand is skipped.

Question 119. Which Java Operator Is Right Associative?

Answer :

The = operator is right associative.

Question 120. Can A Double Value Be Cast To A Byte?

Answer :

Yes, a double value can be cast to a byte.

Question 121. What Is The Difference Between A Break Statement And A Continue Statement?

Answer :

A break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement.

Question 122. Can A For Statement Loop Indefinitely?

Answer :

Yes, a for statement can loop indefinitely. For example, consider the following: for(;;) ;

Question 123. To What Value Is A Variable Of The String Type Automatically Initialized?

Answer :

The default value of an String type is null.

Question 124. What Is The Difference Between A Field Variable And A Local Variable?

Answer :

A field variable is a variable that is declared as a member of a class. A local variable is a variable that is declared local to a method.

Question 125. How Are This() And Super() Used With Constructors?

Answer :

this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.

Question 126. What Does It Mean That A Class Or Member Is Final?

Answer :

A final class cannot be inherited. A final method cannot be overridden in a subclass. A final field cannot be changed after it's initialized, and it must include an initializer statement where it's declared.

Question 127. What Does It Mean That A Method Or Class Is Abstract?

Answer :

An abstract class cannot be instantiated. Abstract methods may only be included in abstract classes. However, an abstract class is not required to have any abstract methods, though most of them do. Each subclass of an abstract class must override the abstract methods of its superclasses or it also should be declared abstract.

Question 128. Can An Anonymous Class Be Declared As Implementing An Interface And Extending A Class?

Answer :

An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.

Question 129. What Is The Catch Or Declare Rule For Method Declarations?

Answer :

If a checked exception may be thrown within the body of a method, the method must either catch the exception or declare it in its throws clause.

Question 130. What Are Some Alternatives To Inheritance?

Answer :

Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn’t force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass).

Question 131. What Are The Different Identifier States Of A Thread?

Answer :

The different identifiers of a Thread are: R - Running or runnable thread, S - Suspended thread, CW - Thread waiting on a condition variable, MW - Thread waiting on a monitor lock, MS - Thread suspended waiting on a monitor lock.

Question 132. What Is Garbage Collection? What Is The Process That Is Responsible For Doing That In Java?

Answer :

Reclaiming the unused memory by the invalid objects. Garbage collector is responsible for this process.

Question 133. What Kind Of Thread Is The Garbage Collector Thread?

Answer :

It is a daemon thread.

Question 134. What Is A Daemon Thread?

Answer :

These are the threads which can run without user intervention. The JVM can exit when there are daemon thread by killing them abruptly.

Question 135. How Will You Invoke Any External Process In Java?

Answer :


Question 136. What Is The Finalize Method Do?

Answer :

Before the invalid objects get garbage collected, the JVM give the user a chance to clean up some resources before it got garbage collected.

Question 137. What Is Mutable Object And Immutable Object?

Answer :

If a object value is changeable then we can call it as Mutable object. (Ex., StringBuffer, …) If you are not allowed to change the value of an object, it is immutable object. (Ex., String, Integer, Float, …)

Question 138. What Is The Basic Difference Between String And Stringbuffer Object?

Answer :

String is an immutable object. StringBuffer is a mutable object.

Question 139. What Is The Purpose Of Void Class?

Answer :

The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void.

Question 140. What Is Reflection?

Answer :

Reflection allows programmatic access to information about the fields, methods and constructors of loaded classes, and the use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions.

Question 141. What Is The Base Class For Error And Exception?

Answer :


Question 142. What Is The Byte Range?

Answer :

128 to 127

Question 143. What Is The Implementation Of Destroy Method In Java.. Is It Native Or Java Code?

Answer :

This method is not implemented.

Question 144. What Are The Approaches That You Will Follow For Making A Program Very Efficient?

Answer :

By avoiding too much of static methods avoiding the excessive and unnecessary use of synchronized methods Selection of related classes based on the application (meaning synchronized classes for multiuser and non-synchronized classes for single user) Usage of appropriate design patterns Using cache methodologies for remote invocations Avoiding creation of variables within a loop and lot more.

Question 145. What Is A Databasemetadata?

Answer :

Comprehensive information about the database as a whole.

Question 146. What Is Locale?

Answer :

A Locale object represents a specific geographical, political, or cultural region.

Question 147. How Will You Load A Specific Locale?

Answer :

Using ResourceBundle.getBundle(…);

Question 148. What Is Jit And Its Use?

Answer :

Really, just a very fast compiler… In this incarnation, pretty much a one-pass compiler — no offline computations. So you can’t look at the whole method, rank the expressions according to which ones are re-used the most, and then generate code. In theory terms, it’s an on-line problem.

Question 149. Is Jvm A Compiler Or An Interpreter?

Answer :


Question 150. What Is The Purpose Of Assert Keyword Used In Jdk1.4.x?

Answer :

In order to validate certain expressions. It effectively replaces the if block and automatically throws the AssertionError on failure. This keyword should be used for the critical arguments. Meaning, without that the method does nothing.

Question 151. How Will You Get The Platform Dependent Values Like Line Separator, Path Separator, Etc., ?

Answer :

Using Sytem.getProperty(…) (line.separator, path.separator, …)

Question 152. Is "abc" A Primitive Value?

Answer :

The String literal “abc” is not a primitive value. It is a String object.

Question 153. What Is Singleton?

Answer :

It is one of the design pattern. This falls in the creational pattern of the design pattern. There will be only one instance for that entire JVM. You can achieve this by having the private constructor in the class. For eg., public class Singleton { private static final Singleton s = new Singleton(); private Singleton() { } public static Singleton getInstance() { return s; } // all non static methods … }

Question 154. Can You Instantiate The Math Class?

Answer :

You can’t instantiate the math class. All the methods in this class are static. And the constructor is not public.

Question 155. What Are The Methods In Object?

Answer :

clone, equals, wait, finalize, getClass, hashCode, notify, notifyAll, toString.

Question 156. What Is Aggregation?

Answer :

It is a special type of composition. If you expose all the methods of a composite class and route the method call to the composite method through its reference, then it is called aggregation.

Question 157. What Is Composition?

Answer :

Holding the reference of the other class within some other class is known as composition.

Question 158. What Is Inner Class?

Answer :

If the methods of the inner class can only be accessed via the instance of the inner class, then it is called inner class.

Question 159. What Is Nested Class?

Answer :

If all the methods of a inner class is static then it is a nested class.

Question 160. What Is The Major Difference Between Linkedlist And Arraylist?

Answer :

LinkedList are meant for sequential accessing. ArrayList are meant for random accessing.

Question 161. What Is The Significance Of Listiterator?

Answer :

You can iterate back and forth.

Question 162. What Is The Final Keyword Denotes?

Answer :

final keyword denotes that it is the final implementation for that method or variable or class. You can’t override that method/variable/class any more.

Question 163. What Is Skeleton And Stub? What Is The Purpose Of Those?

Answer :

Stub is a client side representation of the server, which takes care of communicating with the remote server. Skeleton is the server side representation. But that is no more in use… it is deprecated long before in JDK.

Question 164. Why Does It Take So Much Time To Access An Applet Having Swing Components The First Time?

Answer :

Because behind every swing component are many Java objects and resources. This takes time to create them in memory. JDK 1.3 from Sun has some improvements which may lead to faster execution of Swing applications.

Question 165. What Is The Difference Between Instanceof And Isinstance?

Answer :

instanceof is used to check to see if an object can be cast into a specified type without throwing a cast class exception. isInstance() Determines if the specified Object is assignment-compatible with the object represented by this Class. This method is the dynamic equivalent of the Java language instanceof operator. The method returns true if the specified Object argument is non-null and can be cast to the reference type represented by this Class object without raising a ClassCastException. It returns false otherwise.

Question 166. What Does The "final" Keyword Mean In Front Of A Variable? A Method? A Class?

Answer :

FINAL for a variable: value is constant. FINAL for a method: cannot be overridden. FINAL for a class: cannot be derived.

Question 167. Describe What Happens When An Object Is Created In Java?

Answer :

Several things happen in a particular order to ensure the object is constructed properly: Memory is allocated from heap to hold all instance variables and implementation-specific data of the object and its superclasses. Implemenation-specific data includes pointers to class and method data. The instance variables of the objects are initialized to their default values. The constructor for the most derived class is invoked. The first thing a constructor does is call the consctructor for its superclasses. This process continues until the constrcutor for java.lang.Object is called, as java.lang.Object is the base class for all objects in java. Before the body of the constructor is executed, all instance variable initializers and initialization blocks are executed. Then the body of the constructor is executed. Thus, the constructor for the base class completes first and constructor for the most derived class completes last.

Question 168. What Is The Difference Amongst Jvm Spec, Jvm Implementation, Jvm Runtime ?

Answer :

The JVM spec is the blueprint for the JVM generated and owned by Sun. The JVM implementation is the actual implementation of the spec by a vendor and the JVM runtime is the actual running instance of a JVM implementation.

Question 169. How Does Java Handle Integer Overflows And Underflows?

Answer :

It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.

Question 170. Why Are There No Global Variables In Java?

Answer :

Global variables are considered bad form for a variety of reasons: Adding state variables breaks referential transparency (you no longer can understand a statement or expression on its own: you need to understand it in the context of the settings of the global variables), State variables lessen the cohesion of a program: you need to know more to understand how something works. A major point of Object-Oriented programming is to break up global state into more easily understood collections of local state, When you add one variable, you limit the use of your program to one instance. What you thought was global, someone else might think of as local: they may want to run two copies of your program at once. For these reasons, Java decided to ban global variables.

Question 171. Whats The Difference Between Notify() And Notifyall()?

Answer :

notify() is used to unblock one waiting thread; notifyAll() is used to unblock all of them. Using notify() is preferable (for efficiency) when only one blocked thread can benefit from the change (for example, when freeing a buffer back into a pool). notifyAll() is necessary (for correctness) if multiple threads should resume (for example, when releasing a “writer” lock on a file might permit all “readers” to resume).

Question 172. How Can My Application Get To Know When A Httpsession Is Removed?

Answer :

Define a Class HttpSessionNotifier which implements HttpSessionBindingListener and implement the functionality what you need in valueUnbound() method. Create an instance of that class and put that instance in HttpSession.

Question 173. What Interface Must An Object Implement Before It Can Be Written To A Stream As An Object?

Answer :

An object must implement the Serializable or Externalizable interface before it can be written to a stream as an object.

Question 174. What Is Your Platform's Default Character Encoding?

Answer :

If you are running Java on English Windows platforms, it is probably Cp1252. If you are running Java on English Solaris platforms, it is most likely 8859_1.

Question 175. What An I/o Filter?

Answer :

An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.

Question 176. What Is The Purpose Of Finalization?

Answer :

The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.

Question 177. Which Class Should You Use To Obtain Design Information About An Object?

Answer :

The Class class is used to obtain information about an object’s design.

Question 178. What Is The Purpose Of The System Class?

Answer :

The purpose of the System class is to provide access to system resources.

Question 179. Can We Use The Constructor, Instead Of Init(), To Initialize Servlet?

Answer :

Yes , of course you can use the constructor instead of init(). There’s nothing to stop you. But you shouldn’t. The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructur a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or Servlet Context.

Question 180. How Can A Servlet Refresh Automatically If Some New Data Has Entered The Database?

Answer :

You can use a client-side Refresh or Server Push.

Question 181. The Code In A Finally Clause Will Never Fail To Execute, Right?

Answer :

Using System.exit(1); in try block will not allow finally code to execute.

Question 182. How Many Messaging Models Do Jms Provide For And What Are They?

Answer :

JMS provide for two messaging models, publish-and-subscribe and point-to-point queuing.

Question 183. What Information Is Needed To Create A Tcp Socket?

Answer :

The Local System?s IP Address and Port Number. And the Remote System’s IPAddress and Port Number.

Question 184. What Class.forname Will Do While Loading Drivers?

Answer :

It is used to create an instance of a driver and register it with the DriverManager. When you have loaded a driver, it is available for making a connection with a DBMS.

Question 185. How Many Jsp Scripting Elements Are There And What Are They?

Answer :

There are three scripting language elements: declarations, scriptlets, expressions.

Question 186. What Are Stored Procedures? How Is It Useful?

Answer :

A stored procedure is a set of statements/commands which reside in the database. The stored procedure is pre-compiled and saves the database the effort of parsing and compiling sql statements everytime a query is run. Each database has its own stored procedure language, usually a variant of C with a SQL preproceesor. Newer versions of db’s support writing stored procedures in Java and Perl too. Before the advent of 3-tier/n-tier architecture it was pretty common for stored procs to implement the business logic( A lot of systems still do it). The biggest advantage is of course speed. Also certain kind of data manipulations are not achieved in SQL. Stored procs provide a mechanism to do these manipulations. Stored procs are also useful when you want to do Batch updates/exports/houseKeeping kind of stuff on the db. The overhead of a JDBC Connection may be significant in these cases.

Question 187. How Do I Include Static Files Within A Jsp Page?

Answer :

Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase. Do note that you should always supply a relative URL for the file attribute. Although you can also include static resources using the action, this is not advisable as the inclusion is then performed for each and every request.

Question 188. Why Does Jcomponent Have Add() And Remove() Methods But Component Does Not?

Answer :

Because JComponent is a subclass of Container, and can contain other components and jcomponents.

Question 189. How Can I Implement A Thread-safe Jsp Page?

Answer :

You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive <%@ page isThreadSafe="false" % > within your JSP page.

Question 190. What Is The Difference Between Procedural And Object-oriented Programs?

Answer :

a) In procedural program, programming logic follows certain procedures and the instructions are executed one after another. In OOP program, unit of program is object, which is nothing but combination of data and code.
b) In procedural program, data is exposed to the whole program whereas in OOPs program, it is accessible with in the object and which in turn assures the security of the code.

Question 191. What Are Encapsulation, Inheritance And Polymorphism?

Answer :

Encapsulation is the mechanism that binds together code and data it manipulates and keeps both safe from outside interference and misuse.

Inheritance is the process by which one object acquires the properties of another object.

Polymorphism is the feature that allows one interface to be used for general class actions.

Question 192. What Is The Difference Between Assignment And Initialization?

Answer :

Assignment can be done as many times as desired whereas initialization can be done only once.

Question 193. What Is Oops?

Answer :

Object oriented programming organizes a program around its data, i. e. , objects and a set of well defined interfaces to that data. An object-oriented program can be characterized as data controlling access to code.

Question 194. What Are Class, Constructor And Primitive Data Types?

Answer :

Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created. Primitive data types are 8 types and they are: byte, short, int, long, float, double, boolean, char.

Question 195. What Is An Object And How Do You Allocate Memory To It?

Answer :

Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data. When an object is created using new operator, memory is allocated to it.

Question 196. What Is The Difference Between Constructor And Method?

Answer :

Constructor will be automatically invoked when an object is created whereas method has to be called explicitly.

Question 197. What Are Methods And How Are They Defined?

Answer :

Methods are functions that operate on instances of classes in which they are defined. Objects can communicate with each other using methods and can call methods in other classes. Method definition has four parts. They are name of the method, type of object or primitive type the method returns, a list of parameters and the body of the method. A method’s signature is a combination of the first three parts mentioned above.

Question 198. What Is The Use Of Bin And Lib In Jdk?

Answer :

Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and all packages.

Question 199. How Many Ways Can An Argument Be Passed To A Subroutine And Explain Them?

Answer :

An argument can be passed in two ways.

Passing by value: This method copies the value of an argument into the formal parameter of the subroutine.

Passing by reference: In this method, a reference to an argument (not the value of the argument) is passed to the parameter.

Question 200. What Is The Difference Between An Argument And A Parameter?

Answer :

While defining method, variables passed in the method are called parameters. While using those methods, values passed to those variables are called arguments.

Question 201. How Would You Implement A Thread Pool?

Answer :

The ThreadPool class is a generic implementation of a thread pool, which takes the following input Size of the pool to be constructed and name of the class which implements Runnable (which has a visible default constructor) and constructs a thread pool with active threads that are waiting for activation. once the threads have finished processing they come back and wait once again in the pool.

Question 202. What Are The Advantages And Disadvantages Of Reference Counting In Garbage Collection?

Answer :

An advantage of this scheme is that it can run in small chunks of time closely linked with the execution of the program. These characteristic makes it particularly suitable for real-time environments where the program can't be interrupted for very long time. A disadvantage of reference counting is that it does not detect cycles. A cycle is two or more objects that refer to one another. Another disadvantage is the overhead of incrementing and decrementing the reference count each time. Because of these disadvantages, reference counting currently is out of favor.

Question 203. Why Java Is Said To Be Pass-by-value ?

Answer :

When assigning an object to a variable, we are actually assigning the memory address of that object to the variable. So the value passed is actually the memory location of the object. This results in object aliasing, meaning you can have many variables referring to the same object on the heap.

Question 204. What Are The Access Modifiers Available In Java?

Answer :

Access modifier specify where a method or attribute can be used.

Public is accessible from anywhere.

Protected is accessible from the same class and its subclasses.

Package/Default are accessible from the same package.

Private is only accessible from within the class.

Question 205. What Is The Difference Between A Switch Statement And An If Statement?

Answer :

If statement is used to select from two alternatives. It uses a boolean expression to decide which alternative should be executed. The expression in if must be a boolean value. The switch statement is used to select from multiple alternatives. The case values must be promoted to an to int value.

Question 206. What Are Synchronized Methods And Synchronized Statements?

Answer :

Synchronized methods are methods that are declared with the keyword synchronized. thread executes a synchronized method only after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. It is a block of code declared with synchronized keyword. A synchronized statement can be executed only after a thread has acquired the lock for the object or class referenced in the synchronized statement.

Question 207. What Are The Different Ways In Which A Thread Can Enter Into Waiting State?

Answer :

There are three ways for a thread to enter into waiting state. By invoking its sleep() method, by blocking on I/O, by unsuccessfully attempting to acquire an object's lock, or by invoking an object's wait() method.

Question 208. What Is The Difference Between Static And Non Static Variables ?

Answer :

A static variable is associated with the class as a whole rather than with specific instances of a class. There will be only one value for static variable for all instances of that class. Non-static variables take on unique values with each object instance.

Question 209. What Is The Difference Between Notify And Notifyall Method?

Answer :

notify wakes up a single thread that is waiting for object's monitor. If any threads are waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and occurs at the discretion of the implementation. notifyAll Wakes up all threads that are waiting on this object's monitor. A thread waits on an object's monitor by calling one of the wait methods.

Question 210. What Are Different Type Of Exceptions In Java?

Answer :

There are two types of exceptions in java. Checked exceptions and Unchecked exceptions. Any exception that is is derived from Throwable and Exception is called checked exception except RuntimeException and its sub classes. The compiler will check whether the exception is caught or not at compile time. We need to catch the checked exception or declare in the throws clause. Any exception that is derived from Error and Runtime Exception is called unchecked exception. We don't need to explicitly catch a unchecked exception.

Question 211. Explain About The Select Method With An Example?

Answer :

Select part is useful in selecting text or part of the text. Arguments specified for the select command are the same as applicable to substring. First index is usually represents the start of the index. End of line makers are counted as one character. Example t.select (10,15) .

Question 212. Can There Be An Abstract Class With No Abstract Methods In It?

Answer :


Question 213. Can We Define Private And Protected Modifiers For Variables In Interfaces?

Answer :


Question 214. What Is Garbage Collection? What Is The Process That Is Responsible For Doing That In Java?

Answer :

Reclaiming the unused memory by the invalid objects. Garbage collector is responsible for this process.

Question 215. Can There Be An Abstract Class With No Abstract Methods In It?

Answer :


Question 216. Can An Interface Have An Inner Class?

Answer :


public interface abc {
static int i=0;
void dd();
class a1 {
a1() {
int j;
System.out.println("in interfia");
public static void main(String a1[]) {
System.out.println("in interfia"); } } }

Question 217. What Is User Defined Exception?

Answer :

Apart from the exceptions already defined in Java package libraries, user can define his own exception classes by extending Exception class.

Question 218. What Is The Difference Between Logical Data Independence And Physical Data Independence?

Answer :

Logical Data Independence - meaning immunity of external schemas to changed in conceptual schema.

Physical Data Independence - meaning immunity of conceptual schema to changes in the internal schema.

Question 219. What Are The Practical Benefits, If Any, Of Importing A Specific Class Rather Than An Entire Package (e.g. Import Java.net.* Versus Import Java.net.socket)?

Answer :

It makes no difference in the generated class files since only the classes that are actually used are referenced by the generated class file. There is another practical benefit to importing single classes, and this arises when two (or more) packages have classes with the same name. Take java.util.Timer and javax.swing.Timer, for example. If I import java.util.* and javax.swing.* and then try to use "Timer", I get an error while compiling (the class name is ambiguous between both packages). Let’s say what you really wanted was the javax.swing.Timer class, and the only classes you plan on using in java.util are Collection and HashMap. In this case, some people will prefer to import java.util.Collection and import java.util.HashMap instead of importing java.util.*. This will now allow them to use Timer, Collection, HashMap, and other javax.swing classes without using fully qualified class names in.

Question 220. How Many Methods Do U Implement If Implement The Serializable Interface?

Answer :

The Serializable interface is just a "marker" interface, with no methods of its own to implement. Other ’marker’ interfaces are

Question 221. What Does The "abstract" Keyword Mean In Front Of A Method? A Class?

Answer :

Abstract keyword declares either a method or a class. If a method has a abstract keyword in front of it,it is called abstract method.Abstract method has no body.It has only arguments and return type.Abstract methods act as placeholder methods that are implemented in the subclasses.

Abstract classes can’t be instantiated.If a class is declared as abstract,no objects of that class can be created.If a class contains any abstract method it must be declared as abstract.

Question 222. You Can Create A String Object As String Str = "abc"; Why Cant A Button Object Be Created As Button Bt = "abc";? Explain

Answer :

The main reason you cannot create a button by Button bt= "abc"; is because "abc" is a literal string (something slightly different than a String object, by-the-way) and bt is a Button object. The only object in Java that can be assigned a literal String is java.lang.String. Important to note that you are NOT calling a java.lang.String constuctor when you type String s = "abc";

Question 223. Can Rmi And Corba Based Applications Interact ?

Answer :

Yes they can. RMI is available with IIOP as the transport protocol instead of JRMP.

Question 224. What Is Passed By Reference And Pass By Value ?

Answer :

All Java method arguments are passed by value. However, Java does manipulate objects by reference, and all object variables themselves are references.

Question 225. What Is A "stateless" Protocol ?

Answer :

Without getting into lengthy debates, it is generally accepted that protocols like HTTP are stateless i.e. there is no retention of state between a transaction which is a single request response combination.

Question 226. Difference Between A Class And An Object ?

Answer :

A class is a definition or prototype whereas an object is an instance or living representation of the prototype.

Question 227. What Are The Four Corner Stones Of Oop?

Answer :

Abstraction, Encapsulation, Polymorphism and Inheritance.

Question 228. What Gives Java It's "write Once And Run Anywhere" Nature?

Answer :

Java is compiled to be a byte code which is the intermediate language between source code and machine code. This byte code is not platorm specific and hence can be fed to any platform. After being fed to the JVM, which is specific to a particular operating system, the code platform specific machine code is generated thus making java platform independent.

Question 229. How Can A Dead Thread Be Restarted?

Answer :

A dead thread cannot be restarted.

Question 230. What Happens If An Exception Is Not Caught?

Answer :

An uncaught exception results in the uncaughtException() method of the thread’s ThreadGroup being invoked, which eventually results in the termination of the program in which it is thrown.

Question 231. What Is A Compilation Unit?

Answer :

A compilation unit is a Java source code file.

Question 232. What Is A Task's Priority And How Is It Used In Scheduling?

Answer :

A task’s priority is an integer value that identifies the relative order in which it should be executed with respect to other tasks. The scheduler attempts to schedule higher priority tasks before lower priority tasks.

Question 233. What Value Does Readline() Return When It Has Reached The End Of A File?

Answer :

The readLine() method returns null when it has reached the end of a file.

Question 234. Can An Object's Finalize() Method Be Invoked While It Is Reachable?

Answer :

An object’s finalize() method cannot be invoked by the garbage collector while the object is still reachable. However, an object’s finalize() method may be invoked by other objects.

Question 235. Does Garbage Collection Guarantee That A Program Will Not Run Out Of Memory?

Answer :

Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection.

Question 236. Is Sizeof A Keyword?

Answer :

The sizeof operator is not a keyword.

Question 237. What State Does A Thread Enter When It Terminates Its Processing?

Answer :

When a thread terminates its processing, it enters the dead state.

Question 238. Can A Lock Be Acquired On A Class?

Answer :

Yes, a lock can be acquired on a class. This lock is acquired on the class’s Class object.

Question 239. How Are Observer And Observable Used?

Answer :

Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.

Question 240. What Is A Transient Variable?

Answer :

transient variable is a variable that may not be serialized.

Question 241. Wha Is The Output From System.out.println("hello"+null); ?

Answer :


Question 242. What Are E And Pi?

Answer :

E is the base of the natural logarithm and PI is mathematical value pi.

Question 243. If An Object Is Garbage Collected, Can It Become Reachable Again?

Answer :

Once an object is garbage collected, it ceases to exist. It can no longer become reachable again.

Question 244. Can An Exception Be Rethrown?

Answer :

Yes, an exception can be rethrown.

Question 245. What Is The Purpose Of The File Class?

Answer :

The File class is used to create objects that provide access to the files and directories of a local file system.

Question 246. Is A Class Subclass Of Itself?

Answer :

No. A class is not a subclass of itself.

Question 247. What Modifiers May Be Used With An Interface Declaration?

Answer :

An interface may be declared as public or abstract.

Question 248. What Classes Of Exceptions May Be Caught By A Catch Clause?

Answer :

A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.

Question 249. What Is The Difference Between The Reader/writer Class Hierarchy And The Inputstream/outputstream Class Hierarchy?

Answer :

The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.

Question 250. Can An Object Be Garbage Collected While It Is Still Reachable?

Answer :

A reachable object cannot be garbage collected. Only unreachable objects may be garbage collected.

Question 251. What Is An Object's Lock And Which Object's Have Locks?

Answer :

An object’s lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object’s lock. All objects and classes have locks. A class’s lock is acquired on the class’s Class object.

Question 252. How Are Commas Used In The Intialization And Iteration Parts Of A For Statement?

Answer :

Commas are used to separate multiple statements within the initialization and iteration parts of a for statement.

Question 253. What Must A Class Do To Implement An Interface?

Answer :

It must provide all of the methods in the interface and identify the interface in its implements clause.

Question 254. What Is The Difference Between Preemptive Scheduling And Time Slicing?

Answer :

Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors.

Question 255. What Restrictions Are Placed On The Location Of A Package Statement Within A Source Code File?

Answer :

A package statement must appear as the first line in a source code file (excluding blank lines and comments).

Question 256. What Are Wrapped Classes?

Answer :

Wrapped classes are classes that allow primitive types to be accessed as objects.

Question 257. Is It Possible To Specify Multiple Jndi Names When Deploying An Ejb?

Answer :

No. To achieve this you have to deploy your EJB multiple times each specifying a different JNDI name.

Question 258. What Is Java And Their Uses?

Answer :

Java is an object-programming language that was designed to be portable across multiple platforms and operating systems. Developed by Sun Microsystems, Java is modeled after the C++ programming language and includes special features that make it ideal for programs on the Internet. Still, you may be wondering why Java is suddenly receiving so much hype, and what possible improvements could have been made to this new language so as to push aside a well-established language such as C++.
First and foremost, Java makes it easy to put interactive graphics and other special effects on a World Wide Web page. As with any programming language, Java lets you write programs. Special Java programs, called applets, execute inside a Web page with a capacity matching that of any traditional program. Furthermore, when you run a Java applet, the remote server, Java transmits the applet to your browser across the Internet. So rather than going out to a computer store to buy software, Java applets let you download applications automatically when you need them.

Question 259. What Is Hotjava?

Answer :

Programmers often mention the name "HotJava" in the same breath as Java. Whereas Java is a programming language, HotJava was the first Web browser that could download and play (execute) Java applets. HotJava, created by Sun, is simply a browser, much like the Netscape Navigator or Microsoft's Internet Explorer.
Although HotJava was the first browser to support Java applets, many browsers now support or will soon support applets. Starting with Netscape Navigator 2.0, for example, you can play Java applets for many platforms (Windows 95, the Mac, and so on). Another distinguishing feature of HotJava is that unlike most browsers which are written in C/C++, the HotJava browser is written with the Java programming language.

Question 260. How Can You Say Java Is Object Oriented?

Answer :

Java is an object-oriented programming language which means you can use Java to develop your programs in terms of data and the methods (functions) that operate on the data. In Java, a class is a collection of the data and methods which describe an object with which your program works. Think of an object as a "thing," such as a graphics image, a dialog box, or a file.
Java applets can arrange classes in hierarchical fashion which means you can build new classes from existing classes, improving upon or extending the existing class's capabilities. Everything in Java, except for a few primitive types such as numbers, characters, and boolean (true and false) types, is an object. Java comes with an extensive set of classes that you can use in your programs. In fact, a Java applet itself is a Java class.

Question 261. Why Java Is Platform Independent? Explain. ?

Answer :

When you write and compile a Java applet, you end up with a platform-independent file called a bytecode. Like a standard program, a bytecode consists of ones and zeros. Unlike a standard program, however, the bytecode is not processor specific. In other words, the bytecode does not correspond to an Intel Pentium or a Motorola processor. Instead, after the server downloads the bytecode to your browser, special code within the browser reads and interprets the bytecode, in turn running the applet. To run the bytecode in this way, the interpreter translates the platform independent ones and zeros into ones and zeros your computer's processor understands. In other words, it maps the bytecode to ones and zeros that correspond to the current processor, such as a Pentium.
Each computer platform (Mac, Windows, and so on) can have its own Java interpreter. However, the bytecode file that the server downloads to each browser is identical. In this way, you use the same bytecode on a browser running on a Mac, a PC, or a Silicon Graphics workstation. The multi-platform bytecode file is just one aspect of Java's portability. Java's designers also took the extra effort to remove any platform dependence in the Java language. Thus, you will not find any hardware specific references in Java.

Question 262. Why Java Is Secure? Explain. ?

Answer :

A computer virus is a program written by someone who to maliciously damage the files you have stored on your disks or your computer's disk itself. To encounter a virus from across the Internet, you must download and run a program. Unfortunately, with Java applets, a remote sever downloads the applet to a browser on your system which, in turn, runs the applet. At first glance these downloaded Java applets are an ideal way for malicious programmers to create viruses. Luckily, the Java developers designed Java with networking in mind. Therefore, Java has several built-in security defenses which reduce a programmer's ability to use Java to create a virus.
First, Java applets cannot read or write local files that reside on your disk. In this way, the applet cannot store the virus on your disk or attach the virus to a file. That the applet simply cannot perform disk input and output. Second, Java applets are "blind" to your computer's memory layout. Specifically, Java applets do not have pointers to memory, and programmers cannot use this traditional back door to your computer. Third, Java cannot use memory outside its own memory space. By building these precautions into programming language itself, the Java developers have greatly impaired Java's use in creating and transmitting computer viruses.

Question 263. Why Do People Says "java Is Robust"?

Answer :

When people talk about code being robust, they are referring to the code's reliability. Although Java has not eliminated unreliable code, it has made writing high-quality software easier. To begin, Java eliminates many of the memory problems that are common in languages such as C and C++. Java does not support direct access to pointers to memory. As a result, a Java applet cannot corrupt your computer's memory. Also, Java performs run-time checks (while the applet is running) to make sure that all array and string references are within each items's bounds. In other programming languages, many software bugs result from the program not freeing memory that ought to be freed or freeing the same memory more than once. Java, on the other hand, performs automatic garbage collection (which releases unused memory), eliminating the program's need to free unused memory.
Next, Java is more strongly typed than C++ and requires method declarations, which reduces the potential for type-mismatch errors. Finally, Java institutes an error trapping method known as exception handling. When a program error occurs Java signals the program with an exception, which provides the program with a chance to recover from the error- and warns the user that something caused a specific operation to fail.

Question 264. How Java Is Similar To C?

Answer :

If you are already familiar with C/C++, you will find that Java is actually a simpler language to master. Java incorporates the basic tenets of object-oriented design, yet it eliminates some of the more complicated of the other language, such as multiple inheritance and templates. Many of the language keywords are the same or have only minor differences, which increases portability.
If you are a C programmer dreading the seemingly inevitable push toward C++, you may rejoice over Java's cleaner approach to object-oriented programming. In fact, you want to skip C++ altogether and learn Java instead. Java's manageable selection of predefined classes are both useful and easy to understand. Many of the common operations that may take you hundreds or thousands of lines of code are already done for you. For example, you can write a simple network chat program without having to know much about sockets, protocols, and other low-level network issues.

Question 265. What's The Difference Between Applets And Standalone Program?

Answer :

Sun designed Java from the start to fit hand-in-glove on the Internet. Applets are special Java programs that execute from within a Web browser. In contrast, a Java application (an application program as opposed to an applet) does not run within a browser. As it turns out, Java applets are not much different from standalone Java application. You can start developing your Java program from either an applet or an application and cross over any time. For example, assume that you are writing a new Java-based application that is initially designed as a standalone (non-Internet) game for Mac computers. At the end of your program's development cycle, you decide that you want it to run on Web browsers. Your task to make it into a Web-based applet involves very trivial changes, and the addition of some simple HTML code. At the same time, you will find that the game will also run on computers other than Macs! The point you should remember is that Java applets run within browsers across the Web, whereas Java application programs do not.

Question 266. Why Java Applets Are More Useful For Intranets As Compared To Internet?

Answer :

An intranet is an in-house version of the Internet. An intranet uses the same technologies, software, and equipment that the Internet uses (primarily TCP/IP). Whereas the Internet has information servers miles away controlled by other organizations, your company controls the servers and client computers inside your office in an intranet. During the past year, intranets have experienced explosive popularity growth because they offer a very low cost way for companies to maintain and distribute internal information in an easy-to-use format.
Because intranets work like the Internet, Java also finds a home on company intranets. All the techniques that you will learn and, in fact the same applets that you will use for the Internet, may be applied in your intranet. You may find that Java applets will help you solve special software problems within the intranet. You can use applets to provide a friendly interface to company databases, documentation stores, equipment controls, and so on, while running on any computer from a Mac to a PC to a UNIX workstation.

Question 267. How Can You Set The Applet Size?

Answer :

Java applets run within their own window: Within your HTML file, you set the size of an applet window, using the <APPLET> tag's WIDTH and HEIGHT attributes. The size values you specify for each attribute are in pixels. For example, the following <APPLET> entry creates applet window that is 30 pixels tall by 100 pixels wide:

<APPLET CODE=clock.class  WIDTH=100 HEIGHT=30> </APPLET>

Question 268. How Can You Set An Applet's Height And Width As A Percentage?

Answer :

You use the <APPLET> tag WIDTH and HEIGHT attributes to specify the pixel size of an applet window. In addition to letting you specify the applet window size in terms of pixels, many browsers let you specify the applet window's size as a percentage of the browser's window's size. You do this by specifying a percentage value for the HEIGHT and WIDTH attributes within the <APPLET> tag. For example, the following <APPLET> entry creates an applet window based on 50% of the height and 100% of the width of the browser's window:

<applet code=test.class width=100% height=50%> </applet>.

Question 269. What Is Codebase?

Answer :

The Java applets your browser executes reside in a file with the .class extension. When you create a Web page, you can store you Java .class files in a directory which is different from the directory that contains the page's HTML files. Within the HTML <APPLET> tag, you can use the CODEBASE attribute to specify the directory within which the applet's .class files reside. The CODEBASE location can be a directory on the same computer or a directory at another computer. The CODEBASE attribute specifies (to the browser) the base URL (relative or specifies) of the directory that contain the .class files. If an <APPLET> tag does not use the CODEBASE attribute, the browser uses the current directory (the one containing the HTML file) to locate the .class files. The following <APPLET> tag directs the browser to look for the applet files in the directory called /server_a/applets.

<APPLET CODE="MyFirst.class"CODEBASE^"/server_a/applets" WIDTH=300


Question 270. What Is Appletviewer?

Answer :

Most Java development environments include a special program called an appletviewer. using the appletviewer, you can execute your applet just as if it were running within a Web page displayed a browser. In most cases, the appletviewer can run your applet faster than a browser, making the appletviewer convenient for testing your applet. As you develop your applet, you will want to run it each time you add features. By using the appletviewer, you can quickly try out your applet without starting your Java-enabled Web browser. You run the appletviewer that accompanies Sun's Java Developer's Kit from the command line, specifying the name of the HTML file that contains the <APPLET> entry for applet you want to view:

C:> appletviewer SomeFileName.HTML <ENTER>

Question 271. Explain, Java Is Compatible With All Servers But Not All Browsers?

Answer :

When a Java applet runs over a network, two sides are working. One is the server, which is responsible for maintaining and handling browser requests for the various files it controls. On the server side, a Java applet is just a file like any other file an HTTP server already handles. You do not need any special server software for Java since the real work of executing the Java applet is performed by the browser, not the server.

On the other side is the client, or browser, which request, receives, and interprets files from the server. The browser is responsible for displaying the Web page, playing sounds, running animations and. in general, determining the type of data the server is sending and handling that data accordingly.

When a Web page contains a Java applet, the page's HTML file will contain an <APPLET> entry. If the browser is Java-enabled, the browser will request the applet file from the server. The server, in turn, will send the applet's bytecode to the browser, which will start its Java interpreter to execute the code.

Question 272. What Is The Program Development Process?

Answer :

Depending on what development package you use to create your Java programs, will go about compiling, organizing, and testing your programs in different ways. However, the general development process is mostly the same no matter which package or platform you use.

As discussed, the end result of the Java programs development process is a bytecode file which the server downloads to the browser for interpretation and execution. When you compile your Java source file, you are creating a bytecode file. Java source-code files, on the other hand, contain the class definitions and program statements you write using the Java language. In addition to the Java source-code files, you must create a small HTML file, which the browser uses to invoke your applet.

After the compiler creates the bytecode and you create an HTML file, you can test your applet using either your browser or an appletviewer. If your applet contains errors, many Java development environments provide a debugger program that you can use to track down the errors. When you are ready to release your applet to the public, you must place the applet and a corresponding HTML file on a Web server.

Therefore, the general development cycle of a Java applet includes the creation of source-code and HTML files, compiling the source into bytecode, testing the bytecode through an appletviewer, detecting and removing any errors from the applet using a debugger and, finally, releasing the applet for use on a Web server.

Question 273. What Is The File Type?

Answer :

When you create Java source-code files that contain classes and methods, you need to be aware of the Java file-naming convention. Each Java source-code file must end with the Java extension. In addition, the file's name must match the name of the public class the file defines. For example, if your source-code file creates a class named MorphaMatic, your source-code file must use the name MorphaMatic.java. As you can see, the letters of the source-code file name must match the class name exactly, including the use of upper and lowercase letters.

The HTML file that you use to run the applet can have any name. As a rule, however, you should use the standard extension for your system, typically .html or .htm. Also, to help organize your files, you may want to use a name similar to that of your applet for the HTML file name, such as MorphaMatic. html.

Finally, the bytecode file the Java compiler creates will have the .class extension. In this case, the bytecode file will have the name MorphaMatic.class. As discussed, the .class file is the file the Web server downloads to your browser which, in turn, interprets and executes the files's contents.

Question 274. What Is Javac_g?

Answer :

As you have learned, the javac compiler examines your source-code files and produces the bytecode .class files. As your Java applets become more complex, it may become difficult for you to locate errors (bugs) within your code. To help you locate such errors, most Java development environments provide a special debugger program. In the case of the Sun's Java Developer's Kit, the debugger program is named jdb (for Java debugger). To provide jdb with more information to work with, the Sun's JDK provides special version of the compiler named javac__g. Sun designed the javac _g compiler for use with debuggers. Essentially, javacjg is a non-optimized version of the javac compiler which place tables of information within the bytecode that the debugger can use to track down errors. To compile a Java applet using the javac__g compiler, you simply specify the applet source-file named within the javac^g command line, as shown here:

C:JAVACODE> javac „ g SomeFile.Java <Enter>

Question 275. How To Optimize The Javac Output?

Answer :

When you compare the performance of a Java program against that of a C/C++ program, you will find that the current generation of Java programs can be as much as twenty times slower than their C/C++ counterparts. This performance loss is mostly due to the fact that the browser musf interpret the Java bytecode and convert it into the computer's native code (such as a Pentium or Motorola-specific code) before the code can run. In C/C++, the code is in the processor's native format to begin with, so this time-consuming translation step is not required. Remember, however, that Java's generic bytecode allows the same Java code to run on multiple platforms.
The Java designers are working on various solutions to speed up Java. In the meantime, you can use the -O compiler switch with javac, which may increase the applet's performance. The -0 switch directs javac to optimize its bytecode by "inlining" static, final and private methods. For now, don't worry what "inlining" such code means other than it may improve your applet performance. Unfortunately, when you use inlining, you may increase the size of your bytecode file, which will increase the applet's download time. The following Javac command illustrates how you use the -0 switch:

C:JAVACODE> javac -O  MyFirst.java  <Enter>

Question 276. 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.

Question 277. 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>

Question 278. 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);



Question 279. 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?");

Question 280. 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.

Question 281. 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.

Question 282. 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.

Question 283. 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;

Question 284. 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.

Question 285. 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.

Question 286. 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.

Question 287. 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.

Question 288. 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.

Question 289. 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.

Question 290. 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.

Question 291. 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.

Question 292. How Does The Application Server Handle The Jms Connection?

Answer :

App server creates the server session and stores them in a pool.

Connection consumer uses the server session to put messages in the session of the JMS.

Server session is the one that spawns the JMS session.

Applications written by the Application programmers creates the message listener.

Question 293. 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.

Question 294. 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



Question 295. 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



Question 296. 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



Question 297. 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;

Question 298. 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;

Question 299. 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;

Question 300. 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;

Question 301. 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.

Question 302. 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;

Question 303. 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;

Question 304. 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;

Question 305. 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.

Question 306. 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();

Question 307. 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();

Question 308. 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();

Question 309. 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();

Question 310. 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();

Question 311. 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) ;

Question 312. 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( )

Question 313. 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()




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.

Question 314. 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


Question 315. What Is Multithreading?

Answer :

Multithreading is the ability to have various parts of a program perform steps seemingly at the same time. For example, many Web browsers let users view various pages and click on hot links while the browser is downloading various pictures, text, sounds, and while drawing objects on the screen, The Java design began with the goal of supporting multiple threads of execution. Java lets programs interleave multiple program steps through the use of threads.

Question 316. 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.

Question 317. 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.

Question 318. 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++.

Question 319. What Is Binary Search?

Answer :

You know that you can find an element in an array by searching each element of the array one by one. Unfortunately, sequential searches are very inefficient for large arrays. If your array is sorted, you can use a binary search instead to locate a value within the array. A binary search repeatedly subdivides the array until it finds your desired element. For example, you have undoubtedly searched for a word in a dictionary. A sequential search is equivalent to searching each word one by one, starting from the very first word. If the word is much past the first page, this type of search is a very inefficient process.

A binary search is equivalent to opening a dictionary in the middle, and then deciding if the word is in the first half or second half of the book. You then open the next section in the middle and if the word is in the first half or second half of that section. You can then repeat this process of dividing the book in half until you find the word for which you are looking. If you have never tried, pick a word and try to find it in a dictionary using a binary search technique. You might be surprised at how few divisions it takes to get very close to the word you are looking for. A binary search is very efficient. However, the array must be sorted for it to work.

Question 320. 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.

Question 321. 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

Question 322. What Is The Difference Between Final, Finally And Finalize?

Answer :

 final—declare constant

 finally—handles exception

 Finalize—helps in garbage collection.

Question 323. 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.

Question 324. 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.

Question 325. 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.

Question 326. 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. 

Question 327. 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.

Question 328. What Is A Platform?

Answer :

A platform is the hardware or software environment in which a program runs. Most platforms can be described as a combination of the operating system and hardware, like Windows 2000/XP, Linux, Solaris and MacOS.

Question 329. What Is The Main Difference Between Java Platform And Other Platforms?

Answer :

The Java platform differs from most other platforms in that it's a software-only platform that runs on top of other hardware-based platforms, The Java platform has two components:

The Java Virtual Machine (Java VM).

The Java Application Programming Interface (Java API).

Question 330. What Is The Java Virtual Machine?

Answer :

The Java Virtual Machine is software that can be ported onto various hardware-based platforms.

Question 331. What Is The Java Api?

Answer :

The Java API is a large collection of ready-made software components that provide many useful capabilities, such as graphical user interface (GUI) widgets.

Question 332. What Is The Package?

Answer :

The package is a Java namespace or part of Java libraries. The Java API is grouped into libraries of related classes and interfaces; these libraries are known as packages.

Question 333. What Is Native Code?

Answer :

The native code is a code that after you compile it, the compiled code runs on a specific hardware platform.

Question 334. Is Java Code Slower Than Native Code?

Answer :

Not really. As a platform-independent environment, the Java platform can be a bit slower than native code. However, smart compilers, well-tuned interpreters, and just-in-time bytecode compilers can bring performance close to that of native code without threatening portability.

Question 335. What Is The Serialization?

Answer :

The serialization is a kind of mechanism that makes a class or a bean persistence by having its properties or fields and state information saved and restored to and from storage.

Question 336. How To Make A Class Or A Bean Serializable?

Answer :

By implementing either the java.io.Serializable interface or the java.io.Externalizable interface. As long as one class in a class's inheritance hierarchy implements Serializable or Externalizable, that class is serializable.

Question 337. How Many Methods Are There In The Serializable Interface?

Answer :

There is no method in the Serializable interface. The Serializable interface acts as a marker, telling the object serialization tools that your class is serializable.

Question 338. How Many Methods Are There In The Externalizable Interface?

Answer :

There are two methods in the Externalizable interface. You have to implement these two methods in order to make your class externalizable. These two methods are

readExternal() and


Question 339. Which Containers Use A Border Layout As Their Default Layout?

Answer :

The Window, Frame and Dialog classes use a border layout as their default layout.

Question 340. What Is Synchronization And Why Is It Important?

Answer :

With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object's value. This often causes dirty data and leads to significant errors.

Question 341. What Are Three Ways In Which A Thread Can Enter The Waiting State?

Answer :

A thread can enter the waiting state by invoking its sleep() method, by blocking on I/O, by unsuccessfully attempting to acquire an object's lock or by invoking an object's wait() method. It can also enter the waiting state by invoking its (deprecated) suspend() method.

Question 342. What Is The Preferred Size Of A Component?

Answer :

The preferred size of a component is the minimum component size that will allow the component to display normally.

Question 343. Can Java Object Be Locked Down For Exclusive Use By A Given Thread?

Answer :

Yes. You can lock an object by putting it in a "synchronized" block. The locked object is inaccessible to any thread other than the one that explicitly claimed it.

Question 344. Can Each Java Object Keep Track Of All The Threads That Want To Exclusively Access It?

Answer :


Question 345. What Is The Purpose Of The Wait(), Notify() And Notifyall() Methods?

Answer :

The wait(), notify(), and notifyAll() methods are used to provide an efficient way for threads to wait for a shared resource. When a thread executes an object's wait() method, it enters the waiting state. It only enters the ready state after another thread invokes the object's notify() or notifyAll() methods.

Question 346. What Are The High-level Thread States?

Answer :

The high-level thread states are ready, running, waiting and dead.

Question 347. What Is The Collections Api?

Answer :

The Collections API is a set of classes and interfaces that support operations on collections of objects.

Question 348. What Is The List Interface?

Answer :

The List interface provides support for ordered collections of objects.

Question 349. How Many Bits Are Used To Represent Unicode, Ascii, Utf-16 And Utf-8 Characters?

Answer :

Unicode requires 16 bits.

ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits.

UTF-8 represents characters using 8, 16, and 18 bit patterns.

UTF-16 uses 16-bit and larger bit patterns.

Question 350. What Is The Properties Class?

Answer :

The properties class is a subclass of Hashtable that can be read from or written to a stream. It also provides the capability to specify a set of default values to be used.

Question 351. What Is The Purpose Of The Runtime Class?

Answer :

The purpose of the Runtime class is to provide access to the Java runtime system.

Question 352. What Is The Purpose Of The Finally Clause Of A Try-catch-finally Statement?

Answer :

The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught.

Question 353. What Is The Locale Class?

Answer :

The Locale class is used to tailor program output to the conventions of a particular geographic, political or cultural region.

Question 354. What Is A Protected Method?

Answer :

A protected method is a method that can be accessed by any method in its package and inherited by any subclass of its class.

Question 355. What Is A Static Method?

Answer :

A static method is a method that belongs to the class rather than any object of the class and doesn't apply to an object or even require that any objects of the class have been instantiated.

Question 356. What Is The Difference Between A Window And A Frame?

Answer :

A frame is a resizable, movable window with title bar and close button. Usually it contains Panels. Its derived from a window and has a borderlayout by default.

A window is a Container and has BorderLayout by default. A window must have a parent Frame mentioned in the constructor.

Question 357. What Are Peerless Components?

Answer :

The peerless components are called light weight components.

Question 358. What Is The Difference Between The Reader/writer Class Hierarchy And The Inputstream/outputstream Class Hierarchy?

Answer :

The Reader/Writer class hierarchy is character-oriented and the InputStream/OutputStream class hierarchy is byte-oriented.

Question 359. What Is The Difference Between Throw And Throws Keywords?

Answer :

The throw keyword denotes a statement that causes an exception to be initiated. It takes the Exception object to be thrown as argument. The exception will be caught by an immediately encompassing try-catch construction or propagated further up the calling hierarchy. The throws keyword is a modifier of a method that designates that exceptions may come out of the method, either by virtue of the method throwing the exception itself or because it fails to catch such exceptions that a method it calls may throw.

Question 360. Name Primitive Java Types?

Answer :

The primitive Java types are byte, char, short, int, long, float, double and boolean.

Question 361. How Can A Gui Component Handle Its Own Events?

Answer :

A component can handle its own events by implementing the required event-listener interface and adding itself as its own event listener.

Question 362. What Advantage Do Java's Layout Managers Provide Over Traditional Windowing Systems?

Answer :

Java uses layout managers to layout components in a consistent manner across all windowing platforms. Since Java's layout managers aren't tied to absolute sizing and positioning, they are able to accommodate platform-specific differences among windowing systems.

Question 363. What Are The Problems Faced By Java Programmers Who Don't Use Layout Managers?

Answer :

Without layout managers, Java programmers are faced with determining how their GUI will be displayed across multiple windowing systems and finding a common sizing and positioning that will work within the constraints imposed by each windowing system.

Question 364. What Is The Difference Between Static And Non-static Variables?

Answer :

A static variable is associated with the class as a whole, rather than with specific instances of a class. Non-static variables take on unique values with each object instance.

Question 365. What Is The Difference Between The Paint() And Repaint() Methods?

Answer :

The paint() method supports painting via a Graphics object. The repaint() method is used to cause paint() to be invoked by the AWT painting thread.

Question 366. What Is A Container In A Gui?

Answer :

A Container contains and arranges other components (including other containers) through the use of layout managers, which use specific layout policies to determine where components should go as a function of the size of the container.

Question 367. Is Iterator A Class Or Interface? What Is Its Use?

Answer :

Iterator is an interface which is used to step through the elements of a Collection.

Question 368. How You Can Force The Garbage Collection?

Answer :

Garbage collection is an automatic process and can't be forced.

Question 369. Describe The Principles Of Oops?

Answer :

There are three main principals of oops which are called Polymorphism, Inheritance and Encapsulation.

Question 370. Explain The Encapsulation Principle?

Answer :

Encapsulation is a process of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. One way to think about encapsulation is as a protective wrapper that prevents code and data from being arbitrarily accessed by the other code defined outside the wrapper.

Question 371. Explain The Inheritance Principle?

Answer :

Inheritance is the process by which one object acquires the properties of another object.

Question 372. How To Define An Abstract Class?

Answer :

A class containing abstract method is called Abstract class. An Abstract class can't be instantiated.
Example of Abstract class: abstract

class testAbstractClass {

protected String myString;

public String getMyString() { return myString;


public abstract string anyAbstractFunction{);


Question 373. How To Define An Interface?

Answer :

In Java, Interface defines the methods but does not implement them. Interface can include constants. A class that implements the interfaces is bound to implement all the methods defined in Interface.
Example of Interface:

public interface samplelnterface {

public void functionOne();

public long CONSTANTJDNE = 1000;


Question 374. Explain The Polymorphism Principle?

Answer :

The meaning of Polymorphism is something like one name, many forms. Polymorphism enables one entity to be used as a general category for different types of actions. The specific action is determined by the exact nature of the situation. The concept of polymorphism can be explained as "one interface, multiple methods".

Question 375. Explain The Different Forms Of Polymorphism?

Answer :

From a practical programming viewpoint, polymorphism exists in three distinct forms in Java:

Method overloading

Method overriding through inheritance

Method overriding through the Java interface.

Question 376. What Are Access Specifiers Available In Java?

Answer :

Access specifiers are keywords that determine the type of access to the member of a class. These are:





Question 377. What Do You Understand By A Variable?

Answer :

The variables play a very important role in computer programming. Variables enable programmers to write flexible programs. It is a memory location that has been named so that it can be easily be referred to in the program. The variable is used to hold the data and it can be changed during the course of the execution of the program.

Question 378. What Do You Understand By Numeric Promotion?

Answer :

The Numeric promotion is the conversion of a smaller numeric type to a larger numeric type, so that integer and floating-point operations may take place. In the numerical promotion process the byte, char and short values are converted to int values. The int values are also converted to long values, if necessary the long and float values are converted to double values, as required.

Question 379. Differentiate Between A Class And An Object.

Answer :

A Class is only the definition or prototype of real life object. Whereas an object is an instance or living representation of real life object. Every object belongs to a class and every class contains one or more related objects.

Question 380. What Is The Use Of Object And Class Classes?

Answer :

The Object class is the superclass of all other classes and it is highest-level class in the Java class hierarchy. Instances of the class Class represent classes and interfaces in a running Java application. Every array also belongs to a class that is reflected as a Class object that is shared by all arrays with the same element type and number of dimensions. The primitive Java types (boolean, byte, char, short, int, long, float and double) and the keyword void are also represented as Class objects.

Question 381. What Do You Understand By Casting In Java Language?

Answer :

The process of converting one datatype to another in Java language is called Casting.

Question 382. What Are The Types Of Casting?

Answer :

There are two types of casting in Java, these are Implicit casting and Explicit casting.

Question 383. What Do You Understand By Downcasting?

Answer :

The process of Downcasting refers to the casting from a general to a more specific type, i.e; casting down the hierarchy.

Question 384. What Do You Understand By Final Value?

Answer :

FINAL for a variable: value is constant.

FINAL for a method: cannot be overridden.

FINAL for a class: cannot be derived.

Question 385. What Are Keyboard Events?

Answer :

When Java generates a keyboard event, it passes an Event object that contains information about the key pressed, Java recognizes normal keys, modifier keys, and special keys, For normal keys, the event object contains the key's ASCII value. For the function, arrow and other special keys, there are no ASCII codes, so Java uses special Java-defined code. You have learned how to detect modifier keys. The modifier keys are stored in the modifiers variable in the Event object.

Question 386. What Is The Intersection And Union Methods?

Answer :

When your program uses Rectangle objects, you may need to determine the screen region that holds both objects or two Rectangle objects intersect, to find the intersection or the union of two rectangles, you can use the Rectangle class intersection and union methods. The intersection method returns the area where two Rectangle objects overlap. That is, the intersecting method return the area that two Rectangle objects have in common.

The union method, on the other hand, behaves differently than you might expect. The union method returns the smallest rectangle that encloses two Rectangle objects, instead of returning just the area covered by both objects. This illustrates the behavior of the intersection and union methods.

Question 387. What Are Controls And Their Different Types In Awt?

Answer :

Controls are components that allow a user to interact with your application and the AWT supports the following types of controls:

Labels, Push Buttons, Check Boxes, Choice Lists, Lists, Scrollbars, Text Components.

These controls are the subclasses of the Component.

Question 388. What Is The Difference Between Choice And List?

Answer :

A Choice is displayed in a compact form that requires you to pull it down to see the list of available choices and only one item may be selected from a choice. A List may be displayed in such a way that several list items are visible and it supports the selection of one or more list items.

Question 389. What Is The Difference Between Scrollbar And Scrollpane?

Answer :

A Scrollbar is a Component, but not a Container whereas Scrollpane is a Container and handles its own events and perform its own scrolling.

Question 390. Which Containers Use A Flow Layout As Their Default Layout?

Answer :

Panel and Applet classes use the FlowLayout as their default layout.

Question 391. What Are Wrapper Classes?

Answer :

Wrapper classes are classes that allow primitive types to be accessed as objects.

Question 392. What Is The Difference Between Set And List?

Answer :

Set stores elements in an unordered way but does not contain duplicate elements, where as list stores elements in an ordered way but may contain duplicate elements.

Question 393. How Can The Checkbox Class Be Used To Create A Radio Button?

Answer :

By associating Checkbox objects with a CheckboxGroup.

Question 394. Which Textcomponent Method Is Used To Set A Textcomponent To The Read-only State?

Answer :


Question 395. What Methods Are Used To Get And Set The Text Label Displayed By A Button Object?

Answer :

getLabel() and setLabel().

Question 396. What Is The Difference Between Yield() And Sleep()?

Answer :

When a object invokes yield() it returns to ready state. But when an object invokes sleep() method enters to not ready state.

Question 397. How To Handle A Web Browser Resize Operation?

Answer :

You know how important it is to suspend your threads when Java calls an applet's stop method. Normally, Java calls the stop method when a browser leaves the corresponding Web page. However, in some cases, a Web browser will unexpectedly call an applet's stop method. When a browser window is resized, the browser may first call the stop method and then the start method. If you only stop a thread when its applet stops and create a new thread when the applet restarts, the applet will probably not behave the way that a user expects. To prevent unwanted behavior after resizing the browser, your program should suspend threads when the applet stops and resume the threads when the applet starts.

Question 398. Explain The Concept Of Hashtables?

Answer :

A hashtable is a data structure that lets you look up stored items using an associated key. With an array, you can quickly access an element by specifying an integer index. The limitation of an array is that the look up key can only be an integer. With a hashtable, on the other hand, you can associate an item with a key and then use the key to look up the item. You can use an object of any type as a key in a hashtable.

For example: you might specify the license-plate number as the key and use the key to look up the vehicle owner's record. To distinguish one item from the next, the associated key that you use must be unique for each item, as in the case of a vehicle's license plate number.

Question 399. What Is The Jdbc?

Answer :

Java Database Connectivity (JDBC) is a standard Java API to interact with relational databases form Java. JDBC has set of classes and interfaces which can use from Java application and talk to database without learning RDBMS details and using Database Specific JDBC Drivers.

Question 400. What Is Jdbc Driver Interface?

Answer :

The JDBC Driver interface provides vendor-specific implementations of the abstract classes provided by the JDBC API. Each vendor driver must provide implementations of the java.sql.Connection, Statement, Prepared Statement,  CallableStatement, ResultSet and Driver.