- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Maruthi Krishna has Published 952 Articles
Maruthi Krishna
52 Views
Since Java 7 try-with resources was introduced. In this we declare one or more resources in the try block and these will be closed automatically after the use. (at the end of the try block)The resources we declare in the try block should extend the java.lang.AutoCloseable class.ExampleFollowing program demonstrates the ... Read More
Maruthi Krishna
479 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
Maruthi Krishna
762 Views
In Java you can declare three types of variables namely, instance variables, static variables and, local variables.Local variables − Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and the variable will be destroyed when the method has ... Read More
Maruthi Krishna
141 Views
No, for that matter to throw any exception explicitly you need to create an object of that exception and throw it using the throw keyword.Without creating an object you cannot throw an exception explicitly, you might create a scenario that causes the respective exception.ExampleFollowing Java program throws a NullPointerExceptionpublic class ... Read More
Maruthi Krishna
575 Views
While reading values from the user in the constructor or any method you can validate those values using if condition.ExampleIn the following Java example we are defining two custom exception classes verifying name and age.import java.util.Scanner; class NotProperAgeException extends Throwable{ NotProperAgeException(String msg){ super(msg); } } ... Read More
Maruthi Krishna
3K+ Views
Read the inputs and perform the required calculations within a method. Keep the code that causes exception in try block and catch all the possible exceptions in catch block(s). In each catch block display the respective message and call the method again.ExampleIn the following example we have an array with ... Read More
Maruthi Krishna
1K+ Views
IllegalStateException:This exception is thrown when you call a method at illegal or inappropriate time an IlleagalStateException is generated.For example, the remove() method of the ArrayList class removes the last element after calling the next() or previous methods.After removing the element at the current position you need to move to the ... Read More
Maruthi Krishna
284 Views
It is the sub class of IllegalStateException, This indicates that AWT component is not in an appropriate state i.e. if you are working with components but, not using them properly leads to this exception. There are several scenarios where this exception occursExampleIn the following example we are trying to build ... Read More
Maruthi Krishna
217 Views
An exception is an issue (run time error) occurred during the execution of a program. When an exception occurs the program gets terminated abruptly and, the code past the line that generated the exception never gets executed. Each exception is represented by its respective class.NosuchElement ExceptionThis is a Runtime exception ... Read More
Maruthi Krishna
986 Views
Whenever you need to create an object which cannot be changed after initialization you can define an immutable object. There are no specific rules to create immutable objects, the idea is to restrict the access of the fields of a class after initialization.A Set is an interface in collection framework, ... Read More
To Continue Learning Please Login
Login with Google