Java Interview Questions & Answers – Part3

Home/Uncategorized/Java Interview Questions & Answers – Part3

Java Interview Questions & Answers – Part3

1)Difference between Application server and Web server.

Web server Application server
Web server serves HTTP content Application server serves HTTP, RMI/RPC etc.
Webserver is suitable for static content. Application server supports dynamic content also.
Webserver does not contain inbuilt web server component. Application server contains inbuilt web server component.
IIS, Jetty, Tomcat, Apache etc… Is webserver SharePoint, JBOSS, EJB, WAS etc… Is application server.
Webserver does not add any functionality Application server adds functionality
To applications.

2)Difference between http and https.

HTTP HTTPS
URL begins with “http://” URL begins with “https://”
It uses port 80 for communication It uses port 443 for communication
Unsecured Secured
Operates at Application Layer Operates at Transport Layer
No encryption Encryption is present
No certificates required Certificates required

3)Difference between Static and Non-Static variable/Method.

Static Non-static
Static members are one per class Non-static Variables are 1 per instance.
Static members are accessed by their class name which encapsulates them Non-static members are accessed by object reference.
Static methods can be accessed directly from the class Non-static methods (or instance methods as I like to call them) have to be accessed from an instance.
static members can’t use non-static methods without instantiating an objet Non-static members can use static members directly.
static constructor is used to initialize static fields Non-static fields normal instance constructor is used.

4)Difference between String and StringBuffer.

String StringBuffer
String is used to manipulate character strings that cannot be changed (read-only and immutable). StringBuffer is used to represent characters that can be modified.
String is slow when performing concatenations because concatenating a string created new object. StringBuffer is faster when performing concatenations.
String is immutable StringBuffer is mutable
String is not synchronized StringBuffer is synchronized

5)Difference between Method Overloading and Overriding.

Method Overloading Method Overriding
Arguments Must change Arguments Must not change
Return type Can change Return type Can’t change except for covariant returns
Exceptions Can change Exceptions Can reduce or eliminate. Must not throw new or broader checked exceptions
Access Can change Access Must not make more restrictive (can be less restrictive)
Invocation Reference type determines which overloaded version is selected. Happens at compile time. Invocation Object type determines which method is selected. Happens at runtime

6)Difference between abstract class and interface.

Abstract Class Interfaces
An abstract class can provide complete, default code and/or just the details that have to be overridden. An interface cannot provide any code at all, just the signature.
In case of abstract class, a class may extend only one abstract class. A Class may implement several interfaces.
An abstract class can have non-abstract methods. All methods of an Interface are abstract.
An abstract class can have instance variables. An Interface cannot have instance variables.
An abstract class can have any visibility: public, private, protected. An Interface visibility must be public (or) none.
If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly. If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method.
An abstract class can contain constructors. An Interface cannot contain constructors.
Abstract classes are fast. Interfaces are slow as it requires extra indirection to find corresponding method in the actual class.

 

For More Interview Questions Click Here – Java Interview Questions

By | 2017-07-13T15:39:22+00:00 July 13th, 2017|Categories: Uncategorized|Tags: , , , |0 Comments

About the Author:

Leave A Comment