Shriansh Kumar has Published 324 Articles

Can we declare more than one class in a single Java program?

Shriansh Kumar

Shriansh Kumar

Updated on 20-May-2025 19:30:19

17K+ Views

Declaring Multiple Classes in Java Program A single Java program may contain two or more classes, it is possible in two ways: Multiple non-nested classes Nested classes The Multiple non-nested Classes We can create as many classes as we want ... Read More

What are the differences between compareTo() and compare() methods in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 20-May-2025 19:28:58

9K+ Views

The compareTo() and compare() methods are both used to compare two objects. They return an int value after comparison, which tells if both objects are equal, if not, which is lesser, and which is greater. The primary difference between these two methods is that the compareTo() method is used when ... Read More

What are unreachable catch blocks in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 20-May-2025 19:24:08

6K+ Views

A block of statements that the program control can never reach under any circumstances can be called an unreachable block. Java does not support unreachable blocks, such code will cause a compile-time error. Any code that is written but never executed is considered unnecessary by the Java compiler. In this ... Read More

Why Char[] array is more secure (store sensitive data) than String in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 20-May-2025 19:16:27

5K+ Views

Both String class and Char[] array in Java are used to store textual data. However, Strings are immutable, which means you can't make changes to a String once defined, and the char[] array is not immutable. In the official documentation of Java Cryptography Architecture, it is clearly written that String ... Read More

What are the differences between tight coupling and loose coupling in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 20-May-2025 18:33:46

16K+ Views

In object-oriented programming, coupling is a term used to describe the level of dependency each class or component of an application has on another. Tight coupling in Java means features of different classes and objects have high dependence on one another, whereas Loose coupling means components have very low or ... Read More

What are the differences between import and static import statements in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 20-May-2025 18:22:18

5K+ Views

The import statement is used to bring certain classes and interfaces from other packages into our Java program, so we can access them without using their fully qualified names. We can use the short name instead. Java also supports static import statements, which were introduced in Java 5. It ... Read More

What are the differences between Widening Casting (Implicit) and Narrowing Casting (Explicit) in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 20-May-2025 18:19:49

4K+ Views

A Type casting in Java is used to convert objects or variables from one data type to another. When we are converting or assigning one data type to another, automatic conversion will take place (if the types are compatible and the conversion is safe). However, if there is a ... Read More

How to resolve a NullPointerException in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 20-May-2025 17:25:10

2K+ Views

The NullPointerException is a subclass of the RuntimeException class. It is defined in java.lang package of Java. In this article, we are going to understand the reasons for NullPointerException and how to resolve them. Reason for NullPointerException in Java A NullPointerException is a runtime exception thrown by the JVM when our ... Read More

Why String literal is stored in String Constant Pool in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 19-May-2025 19:55:30

2K+ Views

In Java, the string literals (or, string objects) are stored in a separate memory area called string constant pool to improve the performance of string operations and optimize the memory while using them. Let's understand how. Creating String Objects in Java There are two ways to create a String object ... Read More

What are the differences between printStackTrace() method and getMessage() method in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 19-May-2025 19:36:14

5K+ Views

The errors that occur during runtime after compilation are called exceptions. To handle and rectify these errors, it is necessary to understand the cause and the point where the error occurs. There are two ways to find the details of the exception: one is the printStackTrace() method, and another is ... Read More

Previous 1 ... 5 6 7 8 9 ... 33 Next
Advertisements