Technology
http://www.bratandblekning.com Top Blogs Java interview questions ~ JAVA TUTORIAL

Tuesday, 18 June 2013

Java interview questions

Q.1 What is the difference b/w abstract class and interface?
Ans. If a class is, abstract class then there must  be its subclass, and also, if a class is abstract then this does not mean that its method must be abstract.
In interface, methods are only declared but not defined. By the help of interface, multiple inheritance can also be achieved.

Q.2 What is the purpose of garbage collection in java?
Ans. The only purpose of garbage collection , is to avail the space by removing those resources which are not used from a long time and the space obtained by removing them, is used for other objects.
System.gc();

Q.3 Describe synchronization in respect to multithreading?
Ans. With respect to multithreading, In Java, synchronization is the capability to control the access of multiple threads to shared resources. In Java, without synchronization, it is possible for one thread to modify a shared variable while another thread is in the process of using or updating same shared variable. That normally leads to significant errors.

Q.4 What are pass by value and pass by reference?
Ans. In pass by reference the address of parameter or variable is passed while in pass by value , only copy of parameter or variable is passed. for ex:- in C and C++, Call by value and Call by reference.

Q.5 How can we use threads?
Ans. Threads could be used by implementing Runnable interface.
ex: public class Thread implements Runnable
{
Public void run()
{
System.out.println(“show is called”);
}
Public static void main(String args[])
{
//////////
}
}

1 comment:

  1. Great article. It will be helpful in preparing java interviews.
    also, check Java classes in Pune

    ReplyDelete