Skip to content

Instantly share code, notes, and snippets.

View babanin's full-sized avatar

Ivan Babanin babanin

View GitHub Profile
@babanin
babanin / quiz1.java
Last active December 30, 2015 04:19
Integer x = 127;
System.out.println(x); // 1
System.out.println(127); // 2
System.out.println((Integer) 127); // 3
System.out.println(new Integer(127)); // 4
static {
// high value may be configured by property
int h = 127;
String integerCacheHighPropValue =
sun.misc.VM.getSavedProperty("java.lang.Integer.IntegerCache.high");
if (integerCacheHighPropValue != null) {
int i = parseInt(integerCacheHighPropValue);
i = Math.max(i, 127);
// Maximum array size is Integer.MAX_VALUE
h = Math.min(i, Integer.MAX_VALUE - (-low) -1);
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveTask;
/**
* @author Ivan Babanin ([email protected])
*/
public class TestFJP {
public static void main(String[] args) throws InterruptedException {
ForkJoinPool forkJoinPool = new ForkJoinPool(1);
forkJoinPool.submit(new Task(0));
@babanin
babanin / StoreFloatsInDouble.java
Created August 12, 2013 09:34
pack two floats in single double
import java.nio.ByteBuffer;
/**
* @author Ivan Babanin ([email protected])
*/
public class StoreFloatsInDouble {
public static void main(String[] args) {
double pack = pack(1.1f, 1.2f);
float[] unpack = unpack(pack);
System.out.println(unpack[0] + "\n" + unpack[1]);