Showing posts with label Java 8. Show all posts
Showing posts with label Java 8. Show all posts

Sunday, July 9, 2023

Java (JVM) Memory Model - Switches

 

VM SwitchVM Switch Description
-XmsFor setting the initial heap size when JVM starts
-XmxFor setting the maximum heap size.
-XmnFor setting the size of the Young Generation, rest of the space goes for Old Generation.
-XX:PermGenFor setting the initial size of the Permanent Generation memory
-XX:MaxPermGenFor setting the maximum size of Perm Gen
-XX:SurvivorRatioFor providing ratio of Eden space and Survivor Space, for example if Young Generation size is 10m and VM switch is -XX:SurvivorRatio=2 then 5m will be reserved for Eden Space and 2.5m each for both the Survivor spaces. The default value is 8.
-XX:NewRatioFor providing ratio of old/new generation sizes. The default value is 2.

Wednesday, July 14, 2021

Consumer Example in Java 8

 

Consumer Example in Java 8 


forEach in Iterable.java interface which uses Consumer: 

default void forEach(Consumer<? super T> action) 

{

    Objects.requireNonNull(action);

    for (T t : this) {

        action.accept(t);

    }

}



@FunctionalInterface
public interface Consumer<T>
Represents an operation that accepts a single input argument and returns no result. Unlike most other functional interfaces, Consumer is expected to operate via side-effects.

This is a functional interface whose functional method is accept(Object).

Method:

void accept(T t)
  • andThen

    default Consumer<T> andThen(Consumer<? super T> after)
    Returns a composed Consumer that performs, in sequence, this operation followed by the after operation. If performing either operation throws an exception, it is relayed to the caller of the composed operation. If performing this operation throws an exception, the after operation will not be performed.
    Parameters:
    after - the operation to perform after this operation
    Returns:
    a composed Consumer that performs in sequence this operation followed by the after operation
    Throws:
    NullPointerException - if after is null

Example:

import java.util.Arrays;

import java.util.List;

import java.util.function.Consumer;


public class ConsumerEx {


public static void main(String[] args) {


List<String> list = Arrays.asList("india", "uk", "fiji");


Consumer<String> consumer = (t) -> {

System.out.println(t.toUpperCase());

};


list.forEach(consumer);


}


}


Output:

INDIA

UK

FIJI

Create a Digital Clock using HTML and JavaScript

Create a Digital Clock using HTML and JavaScript  <! DOCTYPE html> < html > < head > ...

Followers

Search This Blog

Popular Posts