Weird Funny Java!

Weird Funny Java!

01public static void main(String... args) {
02        System.out.println("Hello World");
03    }
04
05    static {
06        try {
07            Field value = String.class.getDeclaredField("value");
08            value.setAccessible(true);
09            value.set("Hello World", value.get("G'Day Mate."));
10        catch (Exception e) {
11            throw new AssertionError(e);
12        }
13    }
prints
G’Day Mate.
BTW: Strine is the Australian Dialect of English.

Randomly not so random

In a random sequence, all sequences are equally likely, even not so random ones.
1Random random = new Random(441287210);
2    for(int i=0;i<10;i++)
3        System.out.print(random.nextInt(10)+" ");
4    }
prints 1 1 1 1 1 1 1 1 1 1
and
1Random random = new Random(-6732303926L);
2    for(int i=0;i<10;i++)
3        System.out.println(random.nextInt(10)+" ");
4    }
prints 0 1 2 3 4 5 6 7 8 9
Lastly
01public static void main(String ... args) {
02    System.out.println(randomString(-229985452)+' '+randomString(-147909649));
03}
04
05public static String randomString(int seed) {
06    Random rand = new Random(seed);
07    StringBuilder sb = new StringBuilder();
08    for(int i=0;;i++) {
09        int n = rand.nextInt(27);
10        if (n == 0break;
11        sb.append((char) ('`' + n));
12    }
13    return sb.toString();
14}
prints hello world

Java plus

A confusing piece of code here for you to parse. ;)
1int i = (byte) + (char) - (int) + (long) - 1;
2System.out.println(i);
prints 1

Comments

Popular posts from this blog

SinglePass Terms of Service

Jasper Report Viruatization

JasperReports Tutorial