Shriansh Kumar has Published 324 Articles

Why Object class is the super class for all classes in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 30-May-2025 17:21:43

4K+ Views

The java.lang.Object class is the root or superclass of the class hierarchy, it belongs to the java.lang package. All predefined classes and user-defined classes are direct or indirect subclasses of the Object class. Why is Object Class a Superclass? To understand why the Object class is the superclass of every class ... Read More

Java Program to Convert a String into the InputStream

Shriansh Kumar

Shriansh Kumar

Updated on 30-May-2025 17:14:32

2K+ Views

To convert a given string into an InputStream, Java provides the ByteArrayInputStream class that is used along with a built-in method named getBytes(). While displaying a long input string, we are sometimes required to process it in smaller units. At that time, converting that string into an InputStream will be helpful. ... Read More

Java Program to Add Two Matrix Using Multi-Dimensional Arrays

Shriansh Kumar

Shriansh Kumar

Updated on 30-May-2025 17:09:49

1K+ Views

For two given matrices, each of size m x n, we need to write a Java program to add them. Amatrix has a row and column arrangement of its elements. A matrix with m rows and n columns can be called as m x n matrix. Individual entries in the ... Read More

Java Program to Compute Quotient and Remainder

Shriansh Kumar

Shriansh Kumar

Updated on 30-May-2025 17:05:52

1K+ Views

Given an integer a and a non-zero integer d, our task is to write a Java program to compute the quotient and remainder. Quotient can be calculated using the formula "Quotient = Dividend / Divisor" and for remainder, use "Remainder = Dividend % Divisor". When a number, i.e., dividend, is ... Read More

Java Program to Categorize Taller, Dwarf and Average by Height of a Person

Shriansh Kumar

Shriansh Kumar

Updated on 30-May-2025 16:22:30

499 Views

The given task is to categorize Taller, Dwarf, and Average by the Height of a Person. First of all, we need to define tall, dwarf, and average height of a person. Let us assume -A person with a height between 170cm to 195cm is considered taller.If his height is between 150cm ... Read More

How to handle the ArithmeticException (unchecked) in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 27-May-2025 11:31:15

7K+ Views

Java ArithmeticException The ArithmeticException of java.lang package is an unchecked exception in Java. It is raised when an attempt is made to use a wrong mathematical expression in the Java program. An example of ArithmeticExeption is division by 0. If you divide two numbers and the number in the denominator ... Read More

Why we should follow the naming conventions in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 27-May-2025 11:10:23

4K+ Views

The Java team and developer community suggest us to follow naming conventions. They are just conventions and are not mandatory but help in writing Java programs that are more understandable and easier to read. For example, class names should generally be nouns, and interface names should be adjectives. Additionally, capitalize ... Read More

How to handle the NumberFormatException (unchecked) in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 27-May-2025 10:50:11

2K+ Views

The NumberFormatException is a class that represents an unchecked exception thrown by parseXXX() methods when they are unable to format (convert) a string into a number. Here, the parseXXX() is a group of Java built-in methods that are used to convert string representations of numbers into their corresponding primitive data ... Read More

When to use an abstract class and when to use an interface in Java?

Shriansh Kumar

Shriansh Kumar

Updated on 27-May-2025 10:43:00

47K+ Views

An interface can be used to define a contract for behavior that classes must implement, and it can also act as a contract between two systems to interact. An abstract class is mainly used to define default behavior for subclasses. All child classes inherited from the abstract class can override ... Read More

Java Program to Add Two Complex numbers

Shriansh Kumar

Shriansh Kumar

Updated on 27-May-2025 10:22:40

2K+ Views

Complex numbers are expressed in the form of p + iq, where p and q indicate real numbers and i represents imaginary numbers. For instance, 8.2 + 5.6i is a complex number, where 8.2 is the real part and 5.6i is the imaginary part. As you can see, the real ... Read More

Previous 1 ... 3 4 5 6 7 ... 33 Next
Advertisements