Maruthi Krishna has Published 870 Articles

How to print custom message instead of ErrorStackTrace in java?

Maruthi Krishna

Maruthi Krishna

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

4K+ 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

6K+ 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

976 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

1K+ 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

When does a Java Array Throws a NullPointerException?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:40:03

4K+ 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 are try, catch, finally blocks in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:35:00

2K+ Views

An exception is an issue (run time error) occurred during the execution of a program. For understanding purpose let us look at it in a different manner.Generally, when you compile a program, if it gets compiled without a .class file will be created, this is the executable file in Java, ... Read More

What is the cause of NoSuchElementException and how can we fix it in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:33:06

1K+ Views

What is the cause of NoSuchElementException and how can we fix it in java?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. ... Read More

How to handle MalformedURLException in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:31:32

2K+ Views

While working with client-server programming in Java (JSE), if you are using java.net.URL class object in your program, you need to instantiate this class by passing a string representing required URL to which you need to establish connection. If the url you have passed in the string which cannot be ... Read More

Why variables defined in try cannot be used in catch or finally in java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:30:03

6K+ Views

A class in Java will have three kinds of variables namely, static (class), instance and, local.Instance variables − These variables belong to the instances (objects) of a class. These are declared within a class but outside methods. These are initialized when the class is instantiated. They can be accessed from ... Read More

Do all properties of an Immutable Object need to be final in Java?

Maruthi Krishna

Maruthi Krishna

Updated on 02-Jul-2020 14:29:20

1K+ Views

Immutable class/object is the one whose value cannot be modified. For example, Strings are immutable in Java i.e. once you create a String value in Java you cannot modify it. Even if you try to modify, an intermediate String is created with the modified value and is assigned to the ... Read More

Advertisements