Python with statement | Example code

Python with statement is used with try/finally statements. It is used with unmanaged resources (like file streams). The with the statement clarifies code that previously would use try…finally blocks to ensure that clean-up code is executed. Syntax Example “with statement” in Python Simple example code using “with statement”. In the normal file operation, we have Read More…


Python elif Statement with AND Operator | Example code

Let’ see how to use AND operator to combine two basic conditional expressions in the boolean expression of the Python elif condition statement. Example elif Statement with AND Operator in Python Simple python example code. Output: RohitDegree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like Read More…



How to capitalize elements in list Python | Example code

Use string upper() method to convert every element in a list of strings into uppercase (capitalize) in Python code. Example capitalize elements in list Python Simple python example code. Using an upper() method with Loop Use a Python for loop to iterate through each item in a given list of strings by index. Then use Read More…


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 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 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…