Using JRuby to learn Java?

Hi there list,

I want to use JRuby to learn Java.

Why?

I want to use a popular Java API I found on the net to do … stuff.

I want to learn enough Java to get productive with this API I found.

But obviously I want to get better at JRuby also.

I’m at the very early stages of this effort.

I have learned that I can do a Java import like this:

include_class java.lang.System

And I deal with a class-name-clash like this:

include_class(java.lang.Math) { |package,name| “J#{name}”}

So, that is a small amount of progress.

Now I am looking at this java command:

package TestJavaClient;

When I wander around the net looking at .java files I frequently see
package declarations.

A web search reveals that this command helps me “package” a bunch of
.java files into group.

To do this in Ruby I guess I’d physically put all the .rb files in the
same directory.

Also, I would put a module declaration in each file so the code in
them would be grouped together at run-time.

Here is my question,
How do I call
package TestJavaClient;
in JRuby ?

And, would I ever want to call
package TestJavaClient;
in JRuby ?

Perhaps it makes sense to ignore the package declaration?

Obviously it makes sense to use this declaration if I am writing a
bunch of .java files.

But I’m not, I’m writing .rb files.

Let me know if you have any thoughts on this.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Welcome! Using JRuby is definitely a great way to get to know Java
libraries :slight_smile:

If you’re asking whether you need to specify a package for a piece of
Ruby code, the answer is “no”. Ruby code doesn’t namespace the same
way as Java, so there’s no explicit mechanism for forcing all contents
of a given file into a specific “package”.

If you’re asking how you can specify a package, so that some piece
of Ruby code can be called from Java…

There is support for this in JRuby 1.5, though it’s still a bit
experimental. If you write a Ruby class like this:

class Foo
def hello
puts ‘hello’
end
end

You can compile it directly with jrubyc --java to produce a Foo.class
that contains the Ruby logic but looks like a Java class.

jrubyc --java whatever.rb

Basic instructions are on the JRuby wiki here:
http://wiki.jruby.org/GeneratingJavaClasses

  • Charlie

On Fri, Aug 6, 2010 at 5:51 PM, Audrey L. [email protected]
wrote:

But obviously I want to get better at JRuby also.

.java files into group.
in JRuby ?
But I’m not, I’m writing .rb files.

Let me know if you have any thoughts on this.


To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

While I think JRuby is a great way to play with Java libraries in a
rapid
development environment, it’s not a great way to learn “industry
standard
Java”. I’m not saying I believe in “industry standard Java” dogma, but
one
of the key benefits of JRuby is that it takes away all the practices
people
use to get around nuisances from Java’s nanny state type safety:
catching/bubbling up exceptions, the need for dependency injection,
builder
patterns, generics, etc.

I proposed a talk a few years ago to a Ruby conference called “Java for
JRuby” which was an introduction to everything you needed to know about
Java
to jump into JRuby and leverage Java that goes beyond the JRuby
tutorial. I
think that once you know the following, you can jump right in:

  • Understanding the Java classpath
  • Java packaging
  • Industry standard technologies: servlets, Java logging
  • probably a few more topics

(It was rejected)

On Sat, Aug 7, 2010 at 7:23 AM, Charles Oliver N.

On Wed, Aug 11, 2010 at 1:53 PM, Ikai L. [email protected] wrote:

While I think JRuby is a great way to play with Java libraries in a rapid
development environment, it’s not a great way to learn “industry standard
Java”. I’m not saying I believe in “industry standard Java” dogma, but one
of the key benefits of JRuby is that it takes away all the practices people
use to get around nuisances from Java’s nanny state type safety:
catching/bubbling up exceptions, the need for dependency injection, builder
patterns, generics, etc.

Agreed. JRuby’s not a great way to learn Java, but it’s a great way to
learn about many Java libraries. There’s also somewhat of a mismatch;
unlike Groovy, which – for better or worse – supports and suffers from
almost all of those non-language-related pains of “Java”, JRuby is
rather isolated. Sometimes we suffer from similar pains, sometimes
they don’t exist (and so you don’t know how to cope with them if they
do come up). Sometimes we can support certain patterns (DI that uses
offline config files and .classes, annotation-based frameworks, etc)
and sometimes we can’t. There’s definitely a gap.

Sometimes I almost wish the Java world had been designed more like the
C library world, where the most interaction you might have between two
unrelated libraries is through “glue callbacks”, as if the only
integration mechanism is through dependency-injected one-method
interfaces.

I proposed a talk a few years ago to a Ruby conference called “Java for
JRuby” which was an introduction to everything you needed to know about Java
to jump into JRuby and leverage Java that goes beyond the JRuby tutorial. I
think that once you know the following, you can jump right in:

  • Understanding the Java classpath
  • Java packaging
  • Industry standard technologies: servlets, Java logging
  • probably a few more topics
    (It was rejected)

This would have been a great talk to see :slight_smile:

I’ve also realized lately that we don’t tout the other JVM languages –
and how easily you can use them from JRuby – nearly enough. Ok, so
Java’s not cool. But {clojure,scala} often are cool to Rubyists and
bored Java developers, and both work just fine with JRuby (and we know
of people using JRuby atop those other languages today). How do we do
better marketing and education?

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Wed, Aug 11, 2010 at 7:53 PM, Ikai L. [email protected] wrote:

While I think JRuby is a great way to play with Java libraries in a rapid
development environment, it’s not a great way to learn “industry standard
Java”. I’m not saying I believe in “industry standard Java” dogma, but one
of the key benefits of JRuby is that it takes away all the practices people
use to get around nuisances from Java’s nanny state type safety:
catching/bubbling up exceptions, the need for dependency injection, builder
patterns, generics, etc.

“Java’s nanny state type safety” - I’m writing that one down.

(It was rejected)

Shame. You still have the slides? If I was to add to your bullets I
would
have something like:

  • important Java libs/tech/servers/stuff that Rubyists really need to
    know.

Under which I would include Java Servlet/Rack containers. There is good
tech
on the Ruby side that Rubyists love that is totally
eclipsed by equivalent Java technology. I am thinking Integrity vs
Hudson.
Ruby Rack containers vs Trinidad/jetty-rack. In many
cases an objective appraisal of the options would conclude that a JRuby
approach is better.

On my current project, my :development and :test environments are JRuby
based (:production is Heroku). Using Trinidad as a Rack
container is a) fast as hell (production fast, development convenient),
b)
source reloading for FREE (this is very high ceremony under
native Ruby - you have to modify your source in a specific way to use
Rack::Reloader, use platform specific options, or do without).

To the original poster (Audrey L.):
Speaking from experience, I don’t think it is a good idea to try to
learn
two languages together like that (Java + Ruby) both language
ecosystems are very big and complex and you won’t be able to leverage
one to
learn the other (the important bit). Learn one, to
decent levels of competency and use your knowledge as a reference point
for
the other. If you need to use a Java lib (your primary goal)
you are probably better off economising on the amount of things to know.

Not trying to talk down Ruby or JRuby, but I have been there/done
that/burned the T-shirt. You often hit issues that take good in-depth
understanding of both Ruby and Java to get through.

regards,
Richard.

On 12 Aug 2010, at 23:53, Charles Oliver N. wrote:

This would have been a great talk to see :slight_smile:

It’s definitely something that I feel a real need for, as someone who
has just started with JRuby but has no previous experience with the Java
platform. I’ve been really impressed by what I’ve seen and learned so
far, but there’s a certain level of platform knowledge required to get
going (JRE vs. JDK, JDBC, the classpath).

Since I couldn’t find a “Java for JRuby” guide that covers the kinds of
topics that Ikai mentions I’ve actually started writing one…

Source: http://github.com/stuartellis/jruby_quickstart
PDF:
http://github.com/downloads/stuartellis/jruby_quickstart/jruby_quickstart.pdf

I’ve also realized lately that we don’t tout the other JVM languages –
and how easily you can use them from JRuby – nearly enough. Ok, so
Java’s not cool. But {clojure,scala} often are cool to Rubyists and
bored Java developers, and both work just fine with JRuby (and we know
of people using JRuby atop those other languages today). How do we do
better marketing and education?

FWIW, I think that the Railscasts format of 10 to 15 minute screencasts
on very specific topics is brilliant for both documenting and promoting.
The short length presumably makes them fairly easy for Ryan to produce,
as well as making them more accessible and convenient to people than
longer presentations. It also makes it practical to produce a complete
text version of each episode as reference material (the “ASCIICasts”).


Stuart E.
[email protected]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

The Jruby quickstart is a good idea.

I have recently started playing with Jruby to explore some java
libraries. While I can translate most of the java code 1-to-1 to Jruby I
occasionally find some java-specific constructs which I don’t know how
to deal with. A side by side comparison of java code and its equivalent
jruby code showcasing the interop that is neccessary for some common
cases would be very helpful.

On 14 Aug 2010, at 12:40, Kredaxx P. wrote:

The Jruby quickstart is a good idea.

I have recently started playing with Jruby to explore some java
libraries. While I can translate most of the java code 1-to-1 to Jruby I
occasionally find some java-specific constructs which I don’t know how
to deal with. A side by side comparison of java code and its equivalent
jruby code showcasing the interop that is neccessary for some common
cases would be very helpful.

The content that I’ve written so far is focussed on the platform, just
because that’s my own current interest, but I’ve ticketed this as an
issue.

If anybody would like to comment/contribute/fork the project, please
feel free to do so. It uses the excellent (Ruby) Glyph framework so the
source is just Textile markup plus macros, and the build process is
simple - a step-by-step is on the README.


Stuart E.
[email protected]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Nice very informative
Java Classes in Pune