Pages

Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Java 7 and Groovy on Mac OS X Mountain Lion

I usually keep all my softwares and SDKs to the latest version but jdk7 was probably amongst the longest resisted update/upgrade. Mostly running groovy, I never got motivated enough to upgrade and then there have been several security and compatibility issues reported by many.

Anyways, today I just thought of doing it, primarily to reap benefits of invokedynamic, the thing I have not even looked at so far. The download was pretty simple in form of a .dmg and then the .pkg installer.

I fired up terminal with to check java and viola:
[~]
kunal@kaydee $ java -version
java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

The second natural thing was to just verify groovy, but what the heck, the JVM version I see is:
[~] 
kunal@kaydee $ groovy -version
Groovy Version: 2.0.6 JVM: 1.6.0_37 Vendor: Apple Inc. OS: Mac OS X

Apparently Java 7 got installed at
/Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home/

But the one available to groovy was something else:
[~]
kunal@kaydee $ groovysh
Groovy Shell (2.0.6, JVM: 1.6.0_37)
...
groovy:000> System.properties["java.home"]
===> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

Setting JAVA_HOME Environment variable comes to rescue (in .zshrc or .bash_profile or whatever profile file you use.)
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home"

Reload the iTerm and

[~]
kunal@kaydee $ groovy -version
Groovy Version: 2.0.6 JVM: 1.7.0_11 Vendor: Oracle Corporation OS: Mac OS X


Presentation on Log4j

I had presented this some time back at my workplace. May be you'll find it useful.

Log4j Logging Mechanism
View SlideShare presentation or Upload your own. (tags: log4jjava)

Interesting Identifiers in Java

Ever seen a declaration like

_ _ = new _();

or call to a method like

System.out.println(_._());


Try this example, you'll see, these are valid java statements.
read on..


package test.identifiers;

/**
* example that shows various legal identifiers
*
* @author Kunal
*
*/
public class LegalIdentifiers {

int $1 = 1; // valid
long _6 = 6L; // valid
char t = '\t'; // of course valid, did u have any doubt ;)

class t{
}
t $; // now here t is type & $ is object of type t

class _{
int _ = 0;
int _(){ // method with name of constructor
return _;
}
}
_ _ = new _(); // _ is an object of type _ (underscore)

void display(){
System.out.println(_._()); // interesting, isn't it?
}
// this is not a fill-in-the-blanks question
// it actually compiles and runs :)

// this means
String String = "String"; // is valid
// yes it is !!!
// so you can have variable name same as class name

public static void main(String[] args) {
(new LegalIdentifiers()).display();
}
}