Java

Calling Java Methods Using Lambda Expressions

To call Java methods using Lambda expressions you can use: – Car::makeCar //Static method of a class- Car::drive // Method of an instance- Car::new //Constructor of a class- Car::drive // Instance method, but referenced without using an actual instance.

UUID in Java

/*A UUID is a 36 character string, 32 alphanumeric characters and 4 hypens123e4567-e89b-12d3-a456-426655440000Java supports generation and usage of this using the java.util.UUID class*/public class JavaUUID{ public static void main(String args[]) { generateUUID(); } private static void generateUUID() { //Creating a UUID java.util.UUID uuid = java.util.UUID.fromString(“63982000-bc30-ab45-df12-8752fbac99”); System.out.println(“The UUID value: ” +

Comparison of Arrays

public class CompareArrays{ public static void main(String args[]) { compareArrays(); } private static void compareArrays() { int[] intArray1 = new int[5]; int[] intArray2 = new int[5]; //Changing the value so that the contents of the arrays will differ //Comment this line and the result will be true intArray1[0] = 15;

Timer in Java

import java.util.*;public class TimerTaskDemo extends TimerTask{ public static void main(String args[]) { //Creating a TimerTask and a Timer that together helps achieving the required result TimerTask timeTaskDemo = new TimerTaskDemo(); //Initializing a Timer Timer timer = new Timer(); System.out.println(“Task started: ” + new Date()); //Scheduling the timer //Signature of scheduleAtFixedRate(TimerTask

Increasing the Size of an Array

public class ArraySize{ public static void main(String args[]) { changeArraySize(); } private static void changeArraySize() { int[] intArray = new int[5]; System.out.println(“Before change: size(): ” + intArray.length); // Increasing the size by 2 times //Signature of Arrays.copyOf (original array, new length) intArray = java.util.Arrays.copyOf(intArray, intArray.length * 2); System.out.println(“After change: size():

Understanding the Time Taken to Execute a Task

There are situations when we need to understand the time taken for executing a section of code. We are also aware that System.currentTimeMillis() provides a good estimate of time. System.nanoTime() is a more accurate version of time and can be used as below. public class ExecuteTask{ public static void main(String

Variable Argument Method

The following class describes a method that can accept a variable argument instead of a fixed argument list. This can be handy where the developer is not sure of the number of arguments that can come in for processing. public class VariableArgs { public static void main(String args[]) { System.out.println(“Sum

Memory Tuning: Key Performance Indicators

When you are tuning the application’s memory and garbage collection settings, you should take well-informed decisions based on the key performance indicators. But there is an overwhelming amount of metrics reported; which one to choose and which one to leave? This article intends to explain the right KPIs and right

Thread Dump Analysis Pattern

Threads in ‘runnable’ state consume CPU. So when you are analyzing thread dumps for high CPU consumption, threads in ‘runnable’ state should be thoroughly reviewed. Typically, in thread dumps several threads are classified in ‘RUNNABLE’ state. But in reality several of them wouldn’t be actually running, rather they would be

No more posts to show