Just download JDK, and extract.
Download appropriate JDK. (i586, amd64. This depends on your linux system. If you choose different one, the system cannot recognize the executable files.)
cd ~/Downloads| # | |
| # Written by niceume | |
| # 2013 July. 11 | |
| # | |
| # also refer to src/share/skel/dot.cshrc | |
| # .cshrc - csh resource script, read at beginning of execution by each shell | |
| # see also csh(1), environ(7). | |
| # When creating String, usually double quotations or single quotations are used. | |
| # In double quotations, #{ var } can be used. \ should work. | |
| # In single quotations, \ also should work. | |
| "Hello, everyone" | |
| 'Hi, everyone' | |
| "Hello, \" everyone" | |
| 'Hi, \' everyone' | |
| greeting = "Good morning " |
| // Put the commons-math3-3.4.1.jar file in the same directory of this code. | |
| // Run : | |
| // $ javac -cp commons-math3-3.4.1.jar TTESTStat.java | |
| // $ java -cp .:commons-math3-3.4.1.jar TTESTStat | |
| // | |
| // When running "java", you have to be careful about "-cp option" having ".:" in its argument. | |
| // | |
| // "-cp" option clears previous CLASSPATH setting. | |
| // When running javac, TTESTStat.java means a file on filesystem (Not a java class yet. Still just a file at this point). | |
| // So ".:" is not required. |
| # This is a code for JRuby. | |
| # | |
| # Put the commons-math3-3.4.1.jar in the current code. | |
| # Run | |
| # $ jruby -J-cp commons-math3-3.4.1.jar TTESTStat.rb | |
| # | |
| require "java" | |
| module ACMStat |
| # require "java" provides top-level functions like com, org, java, and javax. | |
| require "java" | |
| ############################### | |
| # Access Java class. (with package name (Ruby namespace)) | |
| ############################### | |
| java.lang.StringBuffer | |
| # In JRuby, this class is recognized as | |
| # Java::JavaLang::StringBuffer | |
| # The begining Java:: means |
In JRuby, we can write Ruby code as if we are in real Ruby world. Moreover, From JRuby, most of the methods in Java class can be easily and seamlessly accessed!
One thing I have to keep in mind is that when we pass Ruby objects to Java method, how these objects are converted. And vice versa. (When Java objects are passed to Java methods, I don't have to take care about it. And also Ruby objects passed to Ruby methods.)
Most of the embedded Ruby libraries can be automatically converted to Java coresponding classes.
| # Class (Class object, eigenclass ) also has its own instance variable(class instance variable). | |
| # It can be accessed in static method. | |
| # By the way, the difference in practice btw class variable and class instance is as follows, | |
| # Class variable is shared by some related objects, say, its instances and inherited classes. | |
| # Class instance variable is an instance variable of only class object. | |
| # In code level, the difference is | |
| # class variable can be written anywhere | |
| # class instance variable can be written in class definition outside of method definitions or in static method definition. |