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 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 class, 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 makes the application robust. There is always a chance application code that may throw exceptions in runtime and you have to handle the exception by executing 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 is 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 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 blocks 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 not needed to create a new List in any way. There are many ways to do this because 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…


Java convert Set to List | ArrayList to HashSet

Java converts Set to List by using many methods like- Loop traverse, ArrayList constructor, addAll method, Java 8 Stream, Guava Library List.newArrayList(set). There is one more easiest way to convert Set to List in Java. Both both Set and List are extended to the Collection, so converting Set into the list is quite straightforward. It Read More…


Array to ArrayList | Create ArrayList from Array in Java

Conversion of Array To ArrayList in Java is the top question in one of the most viewed and voted questions on StackOverflow. You can convert an array to ArrayList using the following ways. Using Arrays.asList() method: Simply pass the array in method. Collections.addAll() method: Create a new list and add array elements using this method Read More…