What is the difference between exception and error
Answered by scott on 2005-05-12 09:50:36: an exception can be caught and recovered: arrayindexoutofboundsexception means you tried to access a position of an array that does not exist - no big deal. an error is unrecoverable: outofmemoryerror means that the JVM has no more memory to contin
What is the difference between static variable and instance variable?
Those are variables static can be defined where the variable is constant,instance variable can be defined instance of class object
1) An instance variable is one whose memory space is creating each and every time whenever an object is created. 1) Static variables are whose memory space is creating only once when the class is load...
Will it compile and run?? If No ... please explain?
first of it will not compile,because outer classes we cant create with the modifier protected
Class will only be public,default,final
protected & private yield to compile time error
Predict the output of the given code:
a) Compiles and prints HCL b) Compiles and prints Technologies c) Compiles and prints HCL Technologies d) Output can be HCL or Technologies
b) Compiles and prints Technologies
Answer is a.
Static variables value can be change by only static method . Here, Run is not a static method so the value of variable msg can not change.
Which of the following methods defined in thread class are static?
A) sleep() b) join() c) start() d) yield()
Sleep and yields methods are static .Please refer given below doc for the explanation.
http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Thread.html
(a)sleep (c)start
A transient variable is a variable that may not be serialized.
Answered by: sivagopal
Member Since Jun-2009 | Answered On : Jun 8th, 2009
A variable that won't be allowed for object serialisation. so that the state
of the value will always be defaulted after the deserialisation.
For example a variable x's value is set to 9, it's default value is '0' say,
when the object has been serialized having x's value 9, after deserialisation
will be defaulted to '0'
Use: In Java, serialization of an object allowed only when all the underlying
objects of the object that is currently under serialization contains has a
relationship, will not be allowed, some times the developer has no choice of
implementing serializable marker interface on some classes as the classes might
have been arrived from a third party and the developer has no control over them,
but the developer needs to serialize the object's state, then the developer has
the choice of marking the objects that not serializable as transient.
transient is a keyword....If a variable is declared as a Transient ,we cant serialize that variable.. The important points about Transient are: 1) Transient keyword can only be applied to fields or ...
A transient variable is a variable that may not be serialised.
What are the legal operands of the instanceof operator
The lEFT operand is an object reference or null value and the right operand is a class,interface, or array type.
the left operand is an object reference or null vale
the right operand is a cla,interface,or aaray type
The legal operands of instance of operator are
1. Left operand which is an object reference.
2. Right operand which can be a class or an interface.
What is the output of below syntax?
Compile Time Error..
Compile Time Error
When we will use thread and runnable in Java program ?
Unicast v/s multicast difference in proper format in networking
What will be the result of compiling and executing the code listed below?
a) Apple b) Orange c) Compile time Error d) Runtime Exception is thrown
Orange
Answer is B. Orange
Static block always executed before invoking the main method. here, we are creating object of class W. So, it will print Orange
Which of the following options can be inserted at the commented line to compile the given code:
a) Class1 c1 = new Class1("HCL"){ } b) Class1 c1 = new Class2(){ }; c) Class2 c3 = new Class1(String s){}; d) Class1 c1 = new Class1(100){ };Code
public class Class1 { Class1(String s){ } Class1() { } } class Class2 extends Class1{ Class2(){ } Class2(String s) {super(s);} void m1() { // insert code here } }
Both a & b
a & b
Select appropriate answers for the incomplete declaration listed below?
Class a ______ b ______ C { } // line 4 a) the 1st blank should be extends and the 2nd blank should be implements. b) the 1st blank should be implements and the 2nd blank should be extends. c) b is a class and C is an interface d) b and C can be EIther class or interface depending upon the placement...
a) is the correct answer because a class firstly extends another class & then implements interface.
When to use interface over abstract class?
Abstract classes: classes which cannot be instantiated. This means one cannot make a object of this class or in other way cannot create object by saying classabs abs = new classabs(); where classabs is abstract class.Abstarct classes contains have one or more abstarct methods, ie method body only...
1. If you are creating something that provides common functionality to unrelated classes, use an interface.
2. If you are creating something for objects that are closely related in a hierarchy, use an abstract class.
If you want common functionality(generalization) for some classes go for abstract
If you dont want generalization then go for abstract class
What is the purpose of finalisation
Finalization is a facility provided by Java for classes who use native resources to clean up before the objects are garbage collected. Since native resources or allocations are beyond the control of ...
The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.
How have you done validation of the fileds in your project
Yes.
Using of the validation framework we can do the form validations. Struts provides ready made validation. Using of the validation.xml file we can do the form validation.
Second approaches is using javascript.
What is meant by session, tell me something about httpsession class
Session is nothing but a small amount of data that is storing at server side. We can handle sessions in different approaches.
1. HttpSessions
2.Cookies.
3.URL Rewriting.
4.Hidden Form..
Using of HttpSessions we can store the information is server side. Its available to till session expire.
Why is the main() method declared public and static?
We declare, main method in java as : public static void main(String args[]) public : means it can be accessible to all other classes. static : main is the entry point of a class. In java everythin...
We declare, main method in java as : public static void main(String args[]) public : means it can be accessible to all other classes. static : main is the entry point of a class. In java everythin...
Which of the following is true about packages?
A) classes in the same package can access each other. b) the inherited class should be in the same package as the parent class. c) package name a.B implies, package b is inherits from package a. d) package access is next to priVATe access in being restrictive.
I think your first option is true. But any how these things depends on access specifiers. If you are not specifying any access specifier default package level access will be applied to the classes, wh...
Have you used threads in servlet
We can implements SingleThreadModel in Servlets Class.
Code
import javax.servle*.; public class Simple implements SingleThreadModel { }
Servlets dont run in their own threads. Instead, when a request comes in, the app server removes a thread from a master thread pool and uses it to drive the servlets service method. Once the service method has returned, the thread is returned to the thread pool.
What is the use of having finally?
Finally block having the statements which are releasing the resource, closing the streams, closing the connection and so on. If exception is raised or not but closing the resource are necessary. So we can keep statements inside the finally block those should be get executed compulsory.
Finally is the block which will be executed irrespective of exception caught in catch block.
Hence it is useful to do any resource releasing/ connection closing after exception handling
Exception is nothing but error but some difference whenever exception will raise program can execute continuously where as error program will not execute
An exception is a condition that is caused by a run time error in the program .When the java interpreter encounters an error like division by zero,it creates an exception object and throws it.