Because of security, synchronization, concurrency, caching, and class loading, the String is immutable in Java. The reason for making string final would be to destroy its immutability and help stop others from trying to extend it. String objects are cached in the String pool, making them immutable. One approach to not allow java 7 certifications serialization of attributes of a class in Java is by using writeObject() and readObject() methods in the subclass and throwing a not Serializable exception. The throw keyword is often used to explicitly throw an exception. It can only throw one exception at a time whereas throws can be used to declare multiple exceptions.
Let’s see the code to inject bean using dependency injection. ContextLoaderListener, on the other hand, is the listener to start up and shut down the WebApplicationContext in Spring root. Some of its important functions includes tying up the lifecycle of Application Context to the lifecycle of the ServletContext and automating the creation of ApplicationContext. Note that the availability of certain scopes depends on the type of application context you are using (e.g., web application context).
What are the observer and observable classes?
Sleep() is most commonly used for polling, or to check for certain results, at a regular interval. Wait() is generally used in multithreaded applications, in conjunction with notify() / notifyAll(), to achieve synchronization and avoid race conditions. In all versions of Java, the volatile keyword guarantees global ordering on reads and writes to a variable. This implies that every thread accessing a volatile field will read the variable’s current value instead of (potentially) using a cached value. The questions are also picked up from various interviews and they are, by no means, very difficult.
We can use getResultSet() to get the ResultSet and getUpdateCount() method to retrieve the update count. Batch processing helps you to group related SQL statements into a batch and execute them instead of executing a single query. By using batch processing technique in JDBC, you can execute multiple queries which makes the performance faster. The ResultSetMetaData interface returns the information of table such as total number of columns, column name, column type etc.
Q11. What is singleton class in Java and how can we make a class singleton?
Although it is platform dependent which means the software of JVM is different for different Operating Systems it plays a vital role in making Java platform Independent. Interviewing candidates to truly understand if they’re a good fit for your organization can be tough too. We’ve put together this helpful resource based on our experience.
Object cloning in Java is the process of creating an exact copy of an object. It basically means the ability to create an object with a similar state as the original object. To achieve this, Java provides a method clone() to make use of this functionality. This method creates a new instance of the class of the current object and then initializes all its fields with the exact same contents of corresponding fields. To object clone(), the marker interface java.lang.Cloneable must be implemented to avoid any runtime exceptions. One thing you must note is Object clone() is a protected method, thus you need to override it.
Explain ‘this’ keyword in Java.
The synchronized keyword in Java is used to identify synchronized blocks. In Java, a synchronized block is one that is tied to an object. Only one thread can be running at a time inside synchronized blocks since they are all synchronized on the same object.
- Dive into a series of potential interview questions and find out what turns out to be the most accurate answer.
- This table compares various courses offered by Simplilearn, based on several key features and details.
- When you create a subclass instance, you’re also creating an instance of the parent class, which is referenced to by the super reference variable.
- Any JVM operating system can run this platform-neutral byte code.