When to use static methods in Java | How to use & examples

A Static method is declared with the static keyword. Making a static method in java required when you don’t want a create an object or method is not using any instance variable or method definition will not change or can’t be overridden. This is some reason when to use static methods in java. It’s an Read More…


Java print stack trace to log | Logger class

To print a stack trace to log you Should declare logger and method info(e.toString()) or log(Level.INFO, e.toString()). Logging is the process of writing log messages during the execution of a program to get an error and warning messages as well as info messages. The java.util.logging package provides the logging capabilities via the Logger class. In general, at the top of every Read More…


Java print stack trace to string | How to Convert Program example

Using Core Java API to print the stack trace to strings provides an easy and efficient way to convert stack trace to string using StringWriter and PrintWriter. A printStackTrace() method is used for get information about exception. You don’t need any special method to convert a print stack trace to a string. In the try-catch-finally exceptions block, we Read More…


try catch finally Java Blocks | Exception Handling Examples

Try catch and finally, Java block is used to handle an exception in programs. Each block has its own functionalities and important. This block helps in preventing ugly application crashes and make application robust. There is always a chance application code that may throw exceptions in runtime and you have to handle the exception by executing alternate Read More…


Uses of Return keyword in Java | Get value, Statement & Examples

Java return keyword is used in a method to get return value after execution is completed. In the method when the return statement executed, that time program will return to the code that invoked it. It’s not a necessary method to have a return statement. For that, the method must be declared void and it Read More…


Use finally block in java | Exception handling

Finally block in java is very important, it has crucial statements that must be executed whether an exception occurs or not. A “finally bock” is used with a try-catch block in java. It follows try or catch block. Important: Java finally block is always executed whether an exception is handled or not. In some cases, Read More…


try catch Java Block | Exception handling example

Try and Catch are block in Java programming. It’s used for exception handling in Java. Where try block contains a set of statements where an exception can occur and catch block is where you handle the exceptions. A try block is always followed by a catch block, which handles the exception that occurs in the associated Read More…


When finally block is not executed OR finally block always get executed in Java

The “finally” will be called after the execution of the try or catch code blocks. Some programmers think  finally block always executes, no matter what. But it’s not true. Note: finally will be called after the execution of the try or catch code blocks. Must Read- What is try-catch Java Block? Some condition (cases) where “finally” won’t be called are: System.exit() invoked in block Read More…


Best Way to Initialization ArrayList in one line | Java List

Actually, probably the “best” way to initialize the ArrayList is the method is no needed to create a new List in any way. There are many ways to do because of java versions are changed, First, wee the way then decide which is the Best Way to Initialization ArrayList in one line. Normal Way:- Multiline See below only quite Read More…