
Find the Number of Processors Available
There are abundant resources available in the java.lang package. Learn more about the server/host on which you are working. The Runtime class has numerous functionalities. To learn the number of
There are abundant resources available in the java.lang package. Learn more about the server/host on which you are working. The Runtime class has numerous functionalities. To learn the number of
Google Guava Preconditions are quite useful for validating arguments of methods. Here it is an example: public void setAge(int age) { Preconditions.checkArgument(assert age = 0, “Age cannot be negative”); …}
We can check if a given port is free by trying to construct a ServerSocket with the port that needs to be checked: import java.io.*;import java.net.*;public class CheckingIfPortIsFree{ public static
A zip file is a compressed file that can hold one or more files. The following code snippet lets us scan the contents of a given zip file. Code snippet:
Adding Log4j2 in a Spring Boot application can be done in two steps. For Maven, in pom.xml, exclude Spring Boot’s default logging: org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-logging Further, add Log4j2 dependency:
ArrayList has an overloaded method that accepts a string, as well as an Integer, as an argument. The remove method can remove elements based on the string, along with the
The Hijri calendar system is somewhat different from the Gregorian calendar. This example does not discuss the complete Hijri calendar. This is only to educate you regarding the existence of
Moving away from the age old way of fixed arguments, Java supports variable arguments. The code sample below illustrates variable arguments. If the method has multiple arguments, it is mandatory
Java has a very powerful library for REGEX. A very basic usage of REGEX is being presented in the code snippet below and we can improve on this to develop