100+ Core Java Interview Questions and Answers for Freshers and Experienced in 2023

It’s certainly not going to be easy, but by following these questions, you are one step closer to accomplishing your goal. Apart from obvious, you also need to make sure that you should not expose the internals of an Immutable object, mainly if it contains a mutable member. You can achieve the same functionality by making member as non-final but private and not modifying them except in constructor. This is the one point, which has gone unnoticed until knowledgeable readers of the Javarevisited blog suggested it. To learn more about the difference between a String literal and String object, see this article. Does not put the object str in the String pool, we need to call String.

Reflection is a runtime API for inspecting and changing the behavior of methods, classes, and interfaces. Java Reflection is a powerful tool that can be really beneficial. Java Reflection allows you to analyze classes, interfaces, fields, and methods during runtime without knowing what they are called at compile time. Reflection can also be used to create new objects, call methods, and get/set field values. External, user-defined classes can be used by creating instances of extensibility objects with their fully-qualified names.

Q10. What is exception hierarchy in java?

The string class is immutable but the other two are mutable in nature. StringBuffer is synchronous whereas the StringBuilder is asynchronous. String uses string pool as memory storage whereas the other two use heap memory for storage purposes. The error we will get in Line 3 is – the integer number too large.

‘IS-A’ relationship is related to the Inheritance property of OOPs Java. It is a kind of parent-child relationship that is established between two classes. Reflection is a property of Java, enabling the Java code to inspect itself. A Java class, for example, can get the names of all its members and showcase them. Because Strings are immutable, any change will result in the creation of a new String, whereas char[] allows you to set all of the elements to blank or zero.

Interview Questions List

As we know, that this refers to the current class object, therefore, it must be similar to the current class object. However, there can be two main advantages of passing this into a method instead of the current class object. Constructor chaining enables us to call one constructor from another constructor of the class with respect to the current class object. We can use this keyword to perform constructor chaining within the same class. Consider the following example which illustrates how can we use this keyword to achieve constructor chaining. Two main restrictions are applied to the static methods. Here, the data type of the variables a and b, i.e., byte gets promoted to int, and the first parameterized constructor with the two integer parameters is called.

  • There are many differences between constructors and methods.
  • Candidates aren’t expected to go into granular detail on all aspects of the app.
  • When formulating an answer to this question, applicants should consider their professional expectations, anticipated career path and hard and soft skills.
  • It contains a set of libraries + other files that JVM uses at runtime.

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 feedback for entering proper values etc. Using pageContext JSP EL implicit object you how to become a java developer can get the request object reference and make use of the dot operator to retrieve the HTTP method name in the JSP page. JSP is a technology on the server’s side to make content generation simple. They are document-centric, whereas servlets are programs.

leave your comment

Your email address will not be published.