Java Interview Questions and Answers

Java Interview Question

 

Question 1
What are the differences between JDK, JVM, and JRE?
Answer
Java Virtual Machine (JVM) provides the necessary runtime environment for the executable java bytecodes.

Whereas, Java Runtime Environment (JRE) contains some important sets of files that are required by JVM in the runtime environment.

JDK (Java Development Kit) should be seen as a benefactor of JRE since it constitutes along with the development tools and JRE, which is crucial to execute and write a program.

Answer : JavaScript Object Notation (JSON) is a much readable and simpler alternative option in the place of XML. It is a standard format to structure the data. Transmission of data between the server and the web application can be done with JSON. It is essentially an independent and easily portable of all available programming languages. Its fundamental usage is to communicate between the server to server or client to the server environment.

Answer : The search engine produces the results in various languages and in different formats when we surf through it for information. It is because a client may make an HTTP request to a server. The particular media type also can be specified.

Here the client specifies the notations as to what can be accepted from the host. As the server and client negotiate on the format and language of the content, this process is called content negotiation.

Answer :

  • If a particular class is incorporated with the abstract keyword in its declaration format, then it is an abstract class. It has both abstract and non-abstract methods with the body and varies in its methods.
  • An abstract class may consist of private, public, protected variables that may be both constants and defaults.
  • It is necessarily extended and the inherent methods are implemented.
  • A class must be declared abstract even if that class has at least a single abstract method.

Answer : Transient is used to specify the variable that is not serialized. Saving an object’s state in Java is Serialization. But if we keep on insisting the default state of the object, the instance variable is stored. In some important instances, if needs are to avoid those few variables since we do not possess the requirements to transmit all across the network. And in that instance, it is declared as transient.

Answer : If any given variable is confirmed as being transient in its inner workings, then it does not insist to keep on existing. So the transient keyword is utilized with that particular instance variable that will not necessarily participate in the process of serialization. We are not to use the static in combination with a transient variable since they are a part in the whole of the instance variable. Hence, volatile keyword is always used in the event of the variable in Java and it assures that the value that the volatile variable contains will not be read from the thread’s local cache but from the main memory.

Answer : Tunnelling is the encapsulation process of private network data information and it also has in mind to transmit that information through public network settings. Tunnelling encrypts the data and sends it encapsulated in a connection but never sends it as a packet of data. The outside clients can be allowed to gather the data from the ORB (client-side Object Request Broker) and it should be sent to the server-side ORB. The major advantage of HTTP tunnelling process is it does mask other protocol requests just as HTTP requests.

Abstract Class Interfaces
An Abstract class provides default and complete code for the exact details that have to be overridden. But an interface does not provide any code other than the signature.
In the event of an abstract class, a class extends just a single abstract class. Here a Class implements multiple interfaces at a given time.
An abstract class would contain also non-abstract methods. The entire set of methods of an Interface are only abstract.
An abstract class can have all the public, private, protected visibilities. An Interface visibility should be only public or none.
An abstract class contains constructors. An Interface is completely devoid of constructors.

Answer :

  • Method Overloading is a process where Methods of the similar class shares the similar name. But here each method contains a different number of parameters or the parameters have various order and types.
  • Method Overloading is mainly used to extend or add more elements to the behavior of the method.
  • In its inherent settings, it is a compile-time polymorphism.
  • The methods should contain a different signature.

Answer : An aggregation is a distinct form of association in Java, where the objects are constituted if their own lifecycle, whereas the child object cannot be owned by any other parent object. For instance, if we take an example of a department and its teacher, a single teacher cannot work at a time in multiple departments. But the deletion of the department will not delete the object of the teacher.

Answer :

  • Java Servlet is a set of server-side technologies that extend the abilities of web servers by lending them the necessary support to respond dynamically and the endurance of data.
  • We can write our own servlets with the interfaces and classes of javax.servlet and javax.servlet.http packages.
  • All servlets must be implemented with the javax.servlet.Servlet interface, because it alone defines servlet lifecycle methods. The GenericServlet class given with the Java Servlet API also can be extended when a generic service is implemented in the first place.
  • If we are to handle HTTP-specific services, we do have doGet() and doPost() provided by the HttpServlet class.

Answer : The Session can be defined as a state between client and server and it contains several chains of request and response between server and client. It is also important to note that both HTTP and Web Server are devoid of a state, we can only maintain a session by passing some exclusive information about the session or the session id between client and server in each request and response.

Here are the usual methods of session management in servlets:

1.User Authentication
2.Rewriting the URL
3.Session Management API
4.Cookies
5.HTML Hidden Field

Answer : The major role of a Connection interface is to maintain a session with the relevant database. It is mainly used to manage the transaction. This interface is the major factor that provides factory methods with the returns of the instance of Statement, DatabaseMetaData, CallableStatement and PreparedStatement.

Answer : We can map application domain model objects to the relational database tables with the programming technique of Object-relational mapping (ORM). In that same line of products, Hibernate is an ORM tool based on Java. It provides the necessary framework to map the application domain objects to the relational database tables and conversely.

Answer : An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. These JVM errors you cannot repair them at runtime. Though error can be caught in catch block but the execution of application will come to a halt and is not recoverable.

While exceptions are conditions that occur because of bad input or human error etc. e.g. FileNotFoundException will be thrown if the specified file does not exist. Or a NullPointerException will take place if you try using a null reference. In most of the cases it is possible to recover from an exception (probably by giving the user a feedback for entering proper values etc.

 

Are you Interested In Joining ?

Attend a Free Demo Session with a sip of Coffee.

October 12, 2018
© 2019 Hope Tutors. All rights reserved.

Site Optimized by GigCodes.com

Request CALL BACK