GeekInterview.com
Series: Subject: Topic:

Java Interview Questions

Showing Questions 1 - 20 of 936 Questions
First | Prev | | Next | Last Page
Sort by: 
 | 

What is the difference between exception and error

Asked By: Interview Candidate | Asked On: May 12th, 2005

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

Answered by: sravani on: Jun 3rd, 2013

Exception is nothing but error but some difference whenever exception will raise program can execute continuously where as error program will not execute

Answered by: sreerenjini s on: May 18th, 2013

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.

What is the difference between static variable and instance variable?

Asked By: shams | Asked On: Oct 31st, 2007

Answered by: sravani on: Jun 3rd, 2013

Those are variables static can be defined where the variable is constant,instance variable can be defined instance of class object

Answered by: Isaaq on: Mar 13th, 2013

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

Core Java question

Asked By: vshri12 | Asked On: Jan 22nd, 2013

Will it compile and run?? If No ... please explain?

Code
  1.  
  2. public class Test{
  3.  
  4. public static void main(String asd[]){
  5.  
  6. System.out.println(" Test!! ");
  7. }
  8.  
  9. }
  10.  
  11. protected class A{
  12. }
  13.  
  14. private class B extends A{
  15. }

Answered by: venkataramana on: May 29th, 2013

first of it will not compile,because outer classes we cant create with the modifier protected

Answered by: Abhinav Rohatgi on: Apr 1st, 2013

Class will only be public,default,final
protected & private yield to compile time error

Predict the output of the given code:

Asked By: lalithakasiraj | Asked On: Dec 15th, 2012

Code
  1. public class Test {
  2. private static String msg = "HCL ";
  3. static{
  4. Thread t = new Thread(new Runnable(){
  5. public void run(){
  6. msg = "Technologies ";
  7. }
  8. });
  9. t.start();
  10. }
  11. public static void main(String[] args){
  12. System.out.print(msg);
  13. }}

a) Compiles and prints HCL
b) Compiles and prints Technologies
c) Compiles and prints HCL Technologies
d) Output can be HCL or Technologies

Answered by: satish Vishwakarma on: May 10th, 2013

b) Compiles and prints Technologies

Answered by: sujitpingale on: Mar 26th, 2013

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?

Asked By: lalithakasiraj | Asked On: Dec 15th, 2012

A) sleep() b) join() c) start() d) yield()

Answered by: satish vishwakarma on: May 10th, 2013

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

Answered by: vasanth on: Mar 2nd, 2013

(a)sleep (c)start

What is a transient variable

Asked By: Interview Candidate | Asked On: Sep 4th, 2005

A transient variable is a variable that may not be serialized.

Star Read Best Answer

Editorial / Best Answer

Answered by: sivagopal

View all answers 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.

Answered by: raisha on: May 6th, 2013

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

Answered by: vijay on: Sep 12th, 2011

A transient variable is a variable that may not be serialised.

What are the legal operands of the instanceof operator

Asked By: Interview Candidate | Asked On: Aug 25th, 2004

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

Answered by: Digpal Singh Chouhan on: Apr 19th, 2013

the left operand is an object reference or null vale
the right operand is a cla,interface,or aaray type

Answered by: Sandhya.Kishan on: Jul 14th, 2012

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?

Asked By: prasadd0013 | Asked On: Oct 23rd, 2011

Code
  1. {
  2. cath(Exception e)
  3. {System.out.println("A");
  4. }
  5. {System.out.println("b");
  6. }
  7. cath(InvalidException e2)
  8. {System.out.println("c");
  9. }
  10. finally()
  11. {
  12. System.out.println("x");
  13. }
  14.  

Answered by: Ravi on: Apr 16th, 2013

Compile Time Error..

Answered by: MD.Aftab Alam on: Apr 7th, 2013

Compile Time Error

Thread and runnable

Asked By: sougandhika | Asked On: Apr 2nd, 2013

When we will use thread and runnable in Java program ?

Answered by: happy on: Apr 7th, 2013

Unicast v/s multicast difference in proper format in networking

What will be the result of compiling and executing the code listed below?

Asked By: lalithakasiraj | Asked On: Dec 15th, 2012

Code
  1.  
  2. public class Finder {
  3. public static void main(String[] args){
  4. System.out.println(X.Y.Z);
  5. }}
  6. class X{
  7. static class Y{ static String Z ="Apple"; }
  8. static W Y = new W();
  9. }
  10. class W{ String Z = "Orange";}

a) Apple
b) Orange
c) Compile time Error
d) Runtime Exception is thrown

Answered by: Abhinav Rohatgi on: Apr 1st, 2013

Orange

Answered by: sujitpingale on: Mar 26th, 2013

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:

Asked By: lalithakasiraj | Asked On: Dec 15th, 2012

Code
  1. public class Class1 {
  2. Class1(String s){ }
  3. Class1() { }
  4. }
  5. class Class2 extends Class1{
  6. Class2(){ }
  7. Class2(String s) {super(s);}
  8. void m1() {
  9. // insert code here
  10. }
  11. }

a) Class1 c1 = new Class1("HCL"){ }
b) Class1 c1 = new Class2(){ };
c) Class2 c3 = new Class1(String s){};
d) Class1 c1 = new Class1(100){ };

Answered by: Abhinav Rohatgi on: Apr 1st, 2013

Both a & b

Answered by: Somone on: Mar 29th, 2013

a & b

Select appropriate answers for the incomplete declaration listed below?

Asked By: lalithakasiraj | Asked On: Dec 15th, 2012

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

Answered by: Abhinav Rohatgi on: Mar 30th, 2013

a) is the correct answer because a class firstly extends another class & then implements interface.

When to use interface over abstract class?

Asked By: Interview Candidate | Asked On: Jun 27th, 2005

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

Answered by: seenthil on: Mar 25th, 2013

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.

Answered by: aparna on: Dec 19th, 2011

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

Asked By: Interview Candidate | Asked On: Jul 21st, 2005

Answered by: Vijay Kumar on: Mar 15th, 2013

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

Answered by: Pattukkottai Arun on: Jul 21st, 2005

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

Asked By: Interview Candidate | Asked On: Aug 26th, 2004

Answered by: Prasad MN on: Mar 8th, 2013

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

Asked By: Interview Candidate | Asked On: Aug 26th, 2004

Answered by: Prasad MN on: Mar 8th, 2013

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?

Asked By: debraj | Asked On: Aug 22nd, 2006

Answered by: Preetam Singh on: Feb 6th, 2013

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

Answered by: bobby on: Apr 15th, 2012

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?

Asked By: lalithakasiraj | Asked On: Dec 15th, 2012

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.

Answered by: Amith on: Feb 5th, 2013

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

Asked By: Interview Candidate | Asked On: Aug 26th, 2004

Answered by: Prasad MN on: Dec 28th, 2012

We can implements SingleThreadModel in Servlets Class.

Code
  1. import javax.servle*.;
  2. public class Simple implements SingleThreadModel
  3. {
  4.   }

Answered by: Sandhya.Kishan on: Jul 26th, 2012

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?

Asked By: Interview Candidate | Asked On: Sep 28th, 2004

Answered by: chaithanya chatla on: Dec 28th, 2012

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.

Answered by: Ajit4U on: Dec 24th, 2012

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

First | Prev | | Next | Last Page

 

 

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.