This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
java/kawa hello world example
- From: David Dreisigmeyer <david dot dreisigmeyer at gmail dot com>
- To: kawa at sources dot redhat dot com
- Date: Sat, 21 Aug 2010 11:28:30 -0400
- Subject: java/kawa hello world example
Hi,
I'm new to kawa and java. ?I was wondering if anyone can provide a
"hello world" example (more details are better) of how to write the
hello world example in java, create a jar file and then use that in
the kawa repl?
An example doing this using clojure is:
Java part:
package demo;
public class counter{
?? ? ? ?int c = 0;
?? ? ? ?public void increment()
?? ? ? ?{
?? ? ? ? ? ? ? ?++c;
?? ? ? ?}
?? ? ? ?public int get()
?? ? ? ?{
?? ? ? ? ? ? ? ?return c;
?? ? ? ?}
?? ? ? ?public static int sqr(int x)
?? ? ? ?{
?? ? ? ? ? ? ? ?return x*x;
?? ? ? ?}
}
Clojure part:
;; To get this to run in SLIME do the following (where we're in demo/ to start):
;;
;; > javac counter.java
;; > cd ../
;; > jar cvf demo.jar demo
;; > mv demo.jar lib/
;;
;; Remember we were in demo/ to start. The directory lib/ is created when we
;; run lein new. So now we have the jar file we created placed with all of the
;; other jar files on the classpath. So we can continue:
;;
;; > lein swank
;;
;; Now start up emacs and M-x slime-connect (accepting 127.0.0.1 and
4005 defaults).
;; At the repl in emacs do
;;
;; user> (import '(demo counter))
;; user> (counter/sqr 4)
Thanks!
-Dave
P.S. I asked this same question for abcl, so it'll be interesting to
campare the three methods (kawa, abcl and clojure).