Skip to main content

400 Java Interview Questions(1 - 100)

1. What are the four corner stones of OOP ?
Abstraction, Encapsulation, Polymorphism and Inheritance.

2. What do you understand by private, protected and public ?
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.


3. Difference between a Class and an Object ?
A class is a definition or prototype whereas an object is an instance or living representation of the prototype.

4. What is Downcasting ?
Downcasting is the casting from a general to a more specific type, i.e. casting down the hierarchy.
5. What is Polymorphism ? What kinds ?



6. What is the difference between method overriding and overloading?
Overriding is a method with the same name and arguments as in a parent, whereas overloading is the same method name but different arguments.

7. What is the restriction on an Overridden methods’ accessibility ?
Overriding methods cannot reduce accessibility - they can either have same or greater accessibility.

8. What is the concept of a Virtual Function ?

9. What is the implication of a Virtual Destructor ? Virtual Constructor ?

10. Can a method be overloaded based on different return type but same argument type ?
No, because the methods can be called without using their return type in which case there is ambiquity for the compiler.

11. What is a "stateless" protocol ?
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.

12. What happens to a static var that is defined within a method of a class ?
Can't do it. You'll get a compilation error.

13. What is constructor chaining and how is it achieved in Java ?
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. 


14. How do you define a local inner class ?

15. How many static init can you have ?
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.

16. What is passed by ref and what by value ?
All Java method arguments are passed by value. However, Java does manipulate objects by reference, and all object variables themselves are references.

17. How do you ensure size of a primitive data type ?
You can't.

18. Describe the Garbage Collection process in Java ?
The JVM spec mandates automatic garbage collection outside of the programmers control. The System.gc() or Runtime.gc() is merely a suggestion to the JVM to run the

GC process but is NOT guaranteed.

19. What is the difference amongst JVM Spec, JVM Implementation, JVM Runtime ?
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.

20. Can RMI and Corba based applications interact ?
Yes they can. RMI is available with IIOP as the transport protocol instead of JRMP

21 .What is the diffrence between an Abstract class and Interface ?
Ans ) Interface defines the methods. There is no implementation.
Whereas Abstract class may have few implemented methods.If some common functionality needs to be shared.

22. What is user defined exception ?
Ans )

23. What do you know about the garbate collector ?
Ans ) Java has an inbuilt mechanisim for garbage collection.
All those objects not longer being referenced are garbage collected.i.e the memory used by these objects is released.

24.What is the difference between C++ & Java ?
25.Explain RMI Architecture?
26.How do you communicate in between Applets & Servlets ?

27.What is the use of Servlets ?
Ans ) To generate dynamic content based on the request.

28.What is JDBC? How do you connect to the Database ?
Ans ) Java Database connectivity.
Using jdbc drivers provided by db drivers.


29.In an HTML form I have a Button which makes us to open another page in 15 seconds. How will do you that ?


30.What is the difference between Process and Threads ?
Ans ) There could be no of processes(multi tasking) and every process could have no of threads(multi threading).

31. What is the difference between RMI & Corba ?
Ans ) Remote method invocation : java only. uses JRMP to communication between java objects
Common object request broker architecture : platform independent. Uses IIOP to communicate between objects.

32.What are the services in RMI ?
33.How will you initialize an Applet ?
34.What is the order of method invocation in an Applet?
35.When is update method called ?

36.How will you pass values from HTML page to the Servlet ?
Ans ) submitting the html form.

37.Have you ever used HashTable and Dictionary ?
Ans ) Dictionary is an abstract class. Hastable extends Dictionary.

38.How will you communicate between two Applets ?
39.What are statements in JAVA ?

40.What is JAR file ?
Ans ) Jar file is an archive of java classes.

41.What is JNI ?
Ans ) Java Native interfaces.

42.What is the base class for all swing components ?
43.What is JFC ?
Ans ) Java Foundation classes.

44.What is Difference between AWT and Swing ?

45.Considering notepad/IE or any other thing as process, What will happen if you start notepad or IE 3 times? Where 3 processes are started or 3 threads are started ?
Ans ) processes.

46.How does thread synchronization occurs inside a monitor ?
Ans ) A thread acquires the monitor.i.e it obtains a lock on the monitor.No other thread can acquire a lock on the same monitor until it is released by the previous thread.

47.What are 4 drivers available in JDBC ?
Ans ) jdbc-odbc bridge
Type 4 : pure java driver. no need to have db client installed on client mcs.

48.How you can know about drivers and database information ?
49.How will you perform transaction using JDBC ?
50.In RMI, server object first loaded into the memory and then the stub reference
is sent to the client ? or whether a stub reference is directly sent to the client ?
Suppose server object is not loaded into the memory, and the client request for it , what will happen?

51.What is serialization ?
Ans ) Process of persisting an object.

52.What is difference RMI registry and OSAgent ?

53.To a server method, the client wants to send a value 20,
with this value exceeds to 20, a message should be sent to the client ? What will you do for achieving for this ?


54 What are the benefits of Swing over AWT ?
55 Where the CardLayout is used ?
56 What is the Layout for ToolBar ?
57 What is the difference between Grid and GridbagLayout ?
58 How will you add panel to a Frame ?
59 What is the corresponding Layout for Card in Swing ?
60 What is light weight component ?
63 What is Servlet API used for conneting database ?
64 What is bean ? Where it can be used ?
65 What is difference in between Java Class and Bean ?
66 Can we send object using Sockets ?
67 What is the RMI and Socket ?
68 How to communicate 2 threads each other ?
72 What is the functionality stubs and skeletons ?
74 Diff between Application and Applet ?
75 What is serializable Interface ?
76 What is the difference between CGI and Servlet ?
77 What is the use of Interface ?
78 Why Java is not fully objective oriented ?
79 Why does not support multiple Inheritance ?
80 What it the root class for all Java classes ?
81 What is polymorphism ?
82 Suppose If we have variable 'I' in run method, If I can create one or more thread each thread will occupy a separate copy or same variable will be shared ?
83 In servlets, we are having a web page that is invoking servlets username and password ? which is cheks in the database ? Suppose the second page also If we want to
verify the same information whethe it will connect to the database or it will be used previous information?

90 What are session variable in Servlets ?
91 What is client server computing ?
93 Why we use OOPS concepts? What is its advantage ?
94 What is the middleware ? What is the functionality of Webserver ?
95 Why Java is not 100 % pure OOPS ?
96 When we will use an Interface and Abstract class ?
97 What is an RMI?
98 How will you pass parameters in RMI ? Why u serialize?
100 What is the main functionality of the Remote Reference Layer ?
 

Comments

Popular posts from this blog

Asynchronous Vs. Synchronous Communications

Synchronous (One thread):   1 thread -> |<---A---->||<----B---------->||<------C----->| Synchronous (multi-threaded):   thread A -> |<---A---->| \ thread B ------------> ->|<----B---------->| \ thread C ----------------------------------> ->|<------C----->|

WebSphere MQ Interview Questions

What is MQ and what does it do? Ans. MQ stands for MESSAGE QUEUEING. WebSphere MQ allows application programs to use message queuing to participate in message-driven processing. Application programs can communicate across different platforms by using the appropriate message queuing software products. What is Message driven process? Ans . When messages arrive on a queue, they can automatically start an application using triggering. If necessary, the applications can be stopped when the message (or messages) have been processed. What are advantages of the MQ? Ans. 1. Integration. 2. Asynchrony 3. Assured Delivery 4. Scalability. How does it support the Integration? Ans. Because the MQ is independent of the Operating System you use i.e. it may be Windows, Solaris,AIX.It is independent of the protocol (i.e. TCP/IP, LU6.2, SNA, NetBIOS, UDP).It is not required that both the sender and receiver should be running on the same platform What is Asynchrony? Ans. With messag...

Advantages & Disadvantages of Synchronous / Asynchronous Communications?

  Asynchronous Communication Advantages: Requests need not be targeted to specific server. Service need not be available when request is made. No blocking, so resources could be freed.  Could use connectionless protocol Disadvantages: Response times are unpredictable. Error handling usually more complex.  Usually requires connection-oriented protocol.  Harder to design apps Synchronous Communication Advantages: Easy to program Outcome is known immediately  Error recovery easier (usually)  Better real-time response (usually) Disadvantages: Service must be up and ready. Requestor blocks, held resources are “tied up”.  Usually requires connection-oriented protocol