Gestion de la mémoire
VM SWITCH |
VM SWITCH DESCRIPTION |
-Xms |
For setting the initial heap size when JVM starts |
-Xmx |
For setting the maximum heap size. |
-Xmn |
For setting the size of the Young Generation, rest of the space goes for Old Generation. |
-XX:PermGen |
For setting the initial size of the Permanent Generation memory |
-XX:MaxPermGen |
For setting the maximum size of Perm Gen |
-XX:SurvivorRatio |
For 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:NewRatio |
For providing ratio of old/new generation sizes. The default value is 2. |
RegExp
Modules
CLI
java --list-modules
java --describe-module java.base
Primitive types
Difference double, float
To sum up:
-
float is represented in 32 bits, with 1 sign bit, 8 bits of exponent, and 23 bits of the mantissa (or what follows from a scientific-notation number: 2.33728*1012; 33728 is the mantissa).
-
double is represented in 64 bits, with 1 sign bit, 11 bits of exponent, and 52 bits of mantissa. By default, Java uses double to represent its floating-point numerals (so a literal 3.14 is typed double). It’s also the data type that will give you a much larger number range, so I would strongly encourage its use over float.
There may be certain libraries that actually force your usage of float, but in general - unless you can guarantee that your result will be small enough to fit in float’s prescribed range, then it’s best to opt with double.
If you require accuracy - for instance, you can’t have a decimal value that is inaccurate (like 1/10 + 2/10), or you’re doing anything with currency (for example, representing $10.33 in the system), then use a BigDecimal, which can support an arbitrary amount of precision and handle situations like that elegantly.
Replace carriage return
Test
package com.oltruong;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(Parameterized.class)
public class RomanNumeralsTest {
private int arabic;
private String romans;
@Parameterized.Parameters
public static List<Object[]> data() {
return Arrays.asList(new Object[][] {
{1, "I"},
{2, "II"},
{3, "III"},
{4, "IV"},
{5, "V"},
{6, "VI"},
});
}
public RomanNumeralsTest(int arabic, String romans) {
this.arabic = arabic;
this.romans = romans;
}
@Test
public void toRomans(){
assertThat(RomanNumerals.toRomans(arabic)).as(String.valueOf(arabic)).isEqualTo(romans);
}
}