Wednesday, December 27, 2006

A Java Program in Unicode

Here is one of my favourite Java programs - written entirely in Unicode. Who says you need to declare a class or even have any Java keywords?!

/*
\u0050\u0076\u0064\u004c\u0020\u0031\u0020\u0041\u0070\u0072\u0039\u0036
\u002a\u002f\u0020\u0063\u006c\u0061\u0073\u0073\u0020\u0068\u0020\u007b
\u0020\u0020\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0020\u0020\u0020
\u0073\u0074\u0061\u0074\u0069\u0063\u0020\u0020\u0076\u006f\u0069\u0064
\u006d\u0061\u0069\u006e\u0028\u0020\u0053\u0074\u0072\u0069\u006e\u0067
\u005b\u005d\u0061\u0029\u0020\u007b\u0053\u0079\u0073\u0074\u0065\u006d
\u002e\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u006c\u006e
\u0028\u0022\u0048\u0069\u0021\u0022\u0029\u003b\u007d\u007d\u002f\u002a
*/

Save as h.java, compile and run!

Monday, December 18, 2006

Program Without Class Keyword

Here is how you can write a standalone Java program WITHOUT a class keyword:

enum E{
X;{
System.out.println("Hello World");
System.exit(0);
}
}

Here is how you can write a standalone Java program WITHOUT a main method:

class Hello{
static{
System.out.println("Hello World");
System.exit(0);
}
}

To avoid the "Could not find main method" exception, the System.exit(0); statement is used which terminates the program after printing out Hello World.

Update (1/1/2013): These examples work on older versions of Java but not on Java 6 and above.

Wednesday, December 06, 2006

Linux - CPU, Memory and Version

Find out which version of SuSE you are running:
more /etc/SuSE-release

SUSE LINUX Enterprise Server 9 (i586)
VERSION = 9
PATCHLEVEL = 2

Find out how much Memory you have:
more /proc/meminfo

MemTotal: 8141344 kB
MemFree: 1983696 kB
Buffers: 74736 kB
Cached: 258836 kB
SwapCached: 2581836 kB
Active: 5485116 kB
Inactive: 444240 kB
HighTotal: 7299036 kB
HighFree: 1408888 kB
LowTotal: 842308 kB
LowFree: 574808 kB
SwapTotal: 9437144 kB
SwapFree: 5436028 kB
Dirty: 244 kB
Writeback: 0 kB
Mapped: 5571044 kB
Slab: 75912 kB
Committed_AS: 5085896 kB
PageTables: 28032 kB
VmallocTotal: 112632 kB
VmallocUsed: 9720 kB
VmallocChunk: 102640 kB
HugePages_Total: 0
HugePages_Free: 0
Hugepagesize: 2048 kB

Find out how much processor power you have:

I have a dual core 2.2 GHz machine.
more /proc/cpuinfo

processor : 0
vendor_id : AuthenticAMD
cpu family : 15
model : 33
model name : AMD Opteron(tm) Processor 275
stepping : 2
cpu MHz : 2204.865
cache size : 1024 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8...
bogomips : 4325.37

processor : 1
vendor_id : AuthenticAMD
cpu family : 15
model : 33
model name : AMD Opteron(tm) Processor 275
stepping : 2
cpu MHz : 2204.865
cache size : 1024 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8...
bogomips : 4325.37

processor : 2
vendor_id : AuthenticAMD
cpu family : 15
model : 33
model name : AMD Opteron(tm) Processor 275
stepping : 2
cpu MHz : 2204.865
cache size : 1024 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8...
bogomips : 4407.29

processor : 3
vendor_id : AuthenticAMD
cpu family : 15
model : 33
model name : AMD Opteron(tm) Processor 275
stepping : 2
cpu MHz : 2204.865
cache size : 1024 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8...
bogomips : 4390.91

I am Perl

You are Perl. People have a hard time understanding you, but you are always able to help them with almost all of their problems.
Which Programming Language are You?