Shriansh Kumar has Published 310 Articles

What are the differences between default constructor and parameterized constructor in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 21-May-2025 16:55:43

14K+ Views

The default and parameterized constructors are two types of Constructor in Java. The constructor is a special member of a Java class whose name is the same as the class name. It is used to assign values to a class variable at the time of object creation. In this article, ... Read More

What are the different types of classes in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 21-May-2025 16:09:47

2K+ Views

In Java, a class is a datatype which defines properties (variables) and behaviors (methods) of an object. Defining an object does not consume memory; only its object or instance does.Depending on the requirement, we will create various types of classes in Java. In this article, we are going to discuss ... Read More

What is the contract between equals() and hashCode() methods in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 21-May-2025 15:49:06

14K+ Views

Every Java object has two very important methods,  equals() and hashCode(), and these methods are designed to be overridden according to their specific general contract. Since the Object class is the parent class of every class, the default implementation of the equals() and hashCode() methods is already present in each class. ... Read More

Interface variables are static and final by default in Java, Why?

Shriansh Kumar

Shriansh Kumar

Updated on 21-May-2025 15:04:19

20K+ Views

In Java, interfaces are used to achieve abstraction and multiple inheritance. They can contain methods and variables, but there are specific rules about how those members should behave. For example, all variables declared in an interface are public, static, and final by default, even if you don't use these keywords ... Read More

How to handle the ArrayStoreException (unchecked) in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 21-May-2025 14:59:40

294 Views

In Java, ArrayStoreException is a public class that extends the RuntimeException class of the java.lang package. It is thrown by the Java Virtual Machine when a runtime error occurs. Since it is an unchecked exception, it does not require an explicit declaration in a method or a constructor's throws clause. ... Read More

How many ways to prevent method overriding in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 21-May-2025 10:55:44

4K+ Views

Method overriding works because of the run-time method binding feature in Java. So, if we force the Java compiler to do static binding for a method then we can prevent that method from being overridden in a derived class. Preventing Method Overriding in Java We can prevent method overriding in ... Read More

What are the differences between StackOverflowError and OutOfMemoryError in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 21-May-2025 10:46:45

1K+ Views

A Java program may contain an interface, a variable, a method, a class, and an object. When we execute the program, the operating system allocates some memory to Java Virtual Machine. Then, JVM divides allocated memory into two parts, which are the Heap and the Stack. The values of variables, methods, and ... Read More

What are the differences between the Heap memory and the String Constant Pool in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 21-May-2025 10:41:06

6K+ Views

The Heap Memory and String Constant Pool are two different memory locations in Java where objects are stored during the execution of programs. Both memory areas are managed by the Java Virtual Machine. In this article, we are going to discuss the difference between Heap Memory and String Constant Pool ... Read More

Can we declare a try catch block within another try catch block in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 21-May-2025 10:29:14

10K+ Views

Yes, we can declare a try-catch block within another try-catch block in Java, this is called nested try-catch block. The try-catch block is used to handle runtime errors that occur during the execution of a program, and the process of handling these errors is called exception handling. The runtime errors ... Read More

What are the differences between length and length () in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 21-May-2025 10:23:36

4K+ Views

In Java, both the length property and the length() method are used to determine the size of data, or we can say they help us to find the number of elements an object contains. However, they are used with different Java objects. The length is an instance variable used for arrays, whereas length() is ... Read More

1 2 3 4 5 ... 31 Next
Advertisements