Maruthi Krishna has Published 952 Articles

How to convert an array to Set and vice versa in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 03-Jul-2020 08:18:11

2K+ Views

Array is a container which can hold a fix number of entities, which are of the same type. Each entity of an array is known as element and, the position of each element is indicated by an integer (starting from 0) value known as index.Exampleimport java.util.Arrays; public class ArrayExample { ... Read More

Can We handle the RuntimeException in java?

Maruthi Krishna

Maruthi Krishna

Updated on 03-Jul-2020 08:08:02

74 Views

A Run time exception or an unchecked exception is the one which occurs at the time of execution. These include programming bugs, such as logic errors or improper use of an API. Runtime exceptions are ignored at the time of compilation.IndexOutOfBoundsException, ArithmeticException, ArrayStoreException and, ClassCastException are the examples of run ... Read More

Is there any way to skip finally block even if some exception occurs in exception block using java?

Maruthi Krishna

Maruthi Krishna

Updated on 03-Jul-2020 08:07:01

3K+ Views

An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.Try, catch, finally blocksTo handle exceptions Java provides a try-catch block mechanism.A try/catch block ... Read More

Is it possible to resume java execution after exception occurs?

Maruthi Krishna

Maruthi Krishna

Updated on 03-Jul-2020 08:05:25

5K+ Views

An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.There are two types of exceptions in Java.Unchecked Exception − An unchecked exception is ... Read More

How can we decide that custom exception should be checked or unchecked in java?

Maruthi Krishna

Maruthi Krishna

Updated on 03-Jul-2020 08:02:42

5K+ Views

An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.User defined exceptionsYou can create your own exceptions in Java and they are known ... Read More

How to print custom message instead of ErrorStackTrace in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 15:03:02

3K+ Views

An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed.Printing the Exception messageYou can print the exception message in Java using one of ... Read More

What is the difference between throw e and throw new Exception(e) in catch block in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:46:36

5K+ Views

An exception is an issue (run time error) occurred during the execution of a program. Here are some example scenarios −If you have an array of size 10 if a line in your code tries to access the 11th element in this array.If you are trying to divide a number ... Read More

How IllegalArgumentException automatically handled inside 'if' condition in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:44:42

686 Views

Whenever you pass inappropriate arguments to a method or constructor, an IllegalArgumentException is thrown. It is a Runtime exception therefore there is no need to handle this at the time of compilation.ExampleThe valueOf() method of the java.sql.Date class accepts a String representing a date in JDBC escape format yyyy-[m]m-[d]d and ... Read More

Why can I throw null in Java and why does it upcast to a NullPointerException?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:42:59

964 Views

In Java there is default value for every type, when you don’t initialize the instance variables of a class Java compiler initializes them on your be-half with these values. Null is the default value of the object type, you can also manually assign null to objects in a method.Object obj ... Read More

What happens if NullPointerException is not handled in main method of java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:41:34

364 Views

In Java there is default value for every type, when you don’t initialize the instance variables of a class Java compiler initializes them on your be-half with these values. Null is the default value of the object type, you can also manually assign null to objects in a method.Object obj ... Read More

Advertisements