Using java and Ruby on rails at the same time... possible? - java

I am currently developing a search engine and I have some implemented algorithms that are written in Java but also I need to get some Database communication which is easy thing in Ruby an Rails. Thus, Is there any way to use both language in the web application development
Regards :)

Easily. You can run Ruby on top of the JVM by using JRuby, or you can have Ruby communicate with Java by using RJB (Ruby-Java Bridge). Or you could reimplement the algorithms in Ruby.

Sounds like JRuby is the sort of thing you're looking for, although I haven't (yet) used it myself.
JRuby with Rails - including guides for Rails 3
https://github.com/jruby/jruby/wiki/JRubyOnRails
Making Java calls
https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby

Related

Implementing a Java Application in Ruby

Is it possible to implement a program written in Java on a website coded using Ruby? Currently developing a website where data from a form must be taken in, parsed, and used to fill out objects in the application. Currently a Java Programmer which is why using Java to develop the application would be much easier. However, Ruby is similar enough that it will work if need be.
I know that there are applications such as JRuby that allow Ruby to be used in Java. Is the reverse true, and if so, how does it work?
JRuby allows you to call Java from Ruby as well: https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby
Before going this route, if you prefer to write your web application in Java (you mentioned that you are more comfortable with Java), why not use Spring Boot? Spring Boot lets you develop with minimal setup like Ruby on Rails.
You can go the jRuby way and mix Ruby and Java and yes it wors in both directions.
See this wiki for examples and how to.
CallingJavaFromJRuby
In theory you can call a java Jar and catch the results in Ruby but for a website I advise against it.
You could present the Java functionality as a webservice but you could program the whole thing in Java or Ruby also.

Rule engine in java & ruby (Suggest me a good approach)

I need to implement a rule engine either in java or in ruby (a independent project) which i have to integrate in a Java EE web-application so should I implement this in java because it will be easy to integrate or should I go with ruby on rails.
If you are trying to integrate it into a Java EE web-application then I'd definitely suggest going with a Java-based option. You want to minimise the proliferation of different application stacks as much as you can, and integration across different stacks is always painful.
I think you will also find that the Java libraries in this area (rules engines / workflow) are more mature. I'd suggest looking at Drools: It is open source and well-proven.
Alternatively, if you really want to use Ruby but still want to integrate with Java / use Java libraries like Drools then JRuby might be a good choice.

Should I try to reuse Ruby code in a Java project?

I'd rather not "reinvent the wheel" and I've found a Ruby project that provides functionality I need in my Java app (there is no preexisting Java project that does what I need - trust me, I've looked). So, best case scenario, I am able to run the Ruby code from my Java code (ala JSR223).
However, this Ruby project depends on having several gems installed. I'm not at all interested in converting the entire Java app into a JRuby app, but I'd like to be able to leverage this project. Is there an easy way to load the code from a gem into a ScriptEngine, or am I just asking for headaches?
JRuby is a solid platform and integrates well with Java. But Rubygems do not integrate so well with Java build tools.
If any of the gems include native C code, then forget it, you can't use them from JRuby.
If all the gems (and all their dependencies) are pure Ruby, it is technically possible to use them from JRuby, but you will have headaches getting them packaged in JARs so that the JRuby runtime can find them.
Mostly I'd say no because of complexity. Although it's subjective, I'd personally rather take the time to re-write it anyway--you can make improvements and when you're done, you'll understand it better.
One option you might consider is splitting your application into two pieces, which interact using either something like pipes/files (or simply stdin and stdout) or some sort of an RPC mechanism. Whether an approach like this makes sense really depends on what the Ruby library does - creating the interface between the two applications might be more complex than actually reimplementing the stuff in Java.
I've reused Java code from JRuby, I don't see why this can't go both ways.
Another thought, can you run the Ruby code and then just tack on a web service or set of web services to call from the Java app? Sinatra makes it ridiculously simple to write a web service wrapper for ruby code. And Java has no shortage of tools to call Web Services.

Is php very limited?

I've tried asp.net and jsp...and the programming language was powerful enough to create both desktop and Windows apps.
Butwhat can I possibly do with php other than creating web applications? Does it have some kind of runtime or framework?
Thanks
Powerful is an unfortunate word. It's about focus, not power. PHP is not very well suited for desktop applications. In part because of weak library support (Though some exists), and in part because of its memory management model. It can be used for jobs outside the web world though; It's often used as a general scripting language, as well as various background tasks.
PHP is not "limited" per se. PHP is primarily only used to develop Web applications. However, there are products like WinBinder that promise to allow you to use PHP to build a desktop application; I wouldn't exactly recommend that though. Also, you probably have not built Windows applications with ASP.NET and JSP but rather more likely .NET WinForms and Java (perhaps Swing). PHP is used by thousands of developers building many different Web applications. It is possible to build other kinds of applications with it but again I wouldn't recommend going down that path.
PHP was intended as a web development language, but you can write console scripts with it, and if you're feeling brave, use something like PHP-GTK to write GUI apps.
PHP makes a surprisingly good shell scripting tool. It has a wealth of simple functions built in.
File IO
String manipulation
Array manipulation
While you can do the same thing in JSP and C# you will spend a lot more time vs. any scripting langauge.
The biggest advantage PHP has over other scripting languages is PHP.net Documentation. Out of any language I have ever used this single resource defines what good documentation and organization of a langauge reference should be.
PHP can be run via an interpreter on the command line, so any computation task can be done in PHP. I don't know about desktop apps and GUI.
PHP has a runtime but it's not fully interpreted like some languages. For example, you can't redefine a method. As far as desktop apps, PHP has bindings for creating desktop apps but it's not very good. It's great for command line tools. Zend and CakePHP are two frameworks for web apps. PHP is like a very-easy to use version of C with a very good community of extensions (look at the extensions on php.net docs). PHP is well supported on windows (even by Msft).
Quite often it is the "limitation" or for want of a better word "focus" of a language that makes it powerful rather than weak.
I'd say PHP is best suited for web application development.
It does the job, and does it well.
But that's not to say that it is not useful for anything else. It can be used as a generic scripting language.
With Qt, you can even develop desktop apps using PHP. Check out http://php-qt.org/
But the focus must be with web apps: PHP was intended for the web.
Depends on what you consider powerful?
It is designed for server-side web-development, and it does that perfectly.
I can't see myself saying one language is more powerful than the other, as it is always a matter of preference, the task at hand and whether the language was designed for what you are trying to accomplish.

python vs java on web service development?

i am currently using php as backend language in webdevelopment. but im wondering what you need to install to get running with python and java.
with php i need apache and mysql.
can i use those for java and python too?
i cant find good guides equivalent to LAMP/MAMP/WAMP so i understand the parts when using either java or python. would be great if you could give me some good links on the installation and what is required.
and i have read that its easier with python. but is this the only advantage of using python instead of java. cause with java i can create java applets, desktop and mobile applications. they all tend to have java installed. but not python.
so why should i use python instead of java.
I can only give suggestions for web development in python:
Use Tornado - A non blocking web server.
Use Jinja2 - A templating engine.
Use MongoDB - A schema less database server | You can also use any RDBMS according to your requirement.
Above 3 tools are enough to build a web application in python.
or you can always choose Django - The giant web framework with all the features required to build a scalable web application in python.
You need to look into the Web Application Framework subject. Some SO pointers:
simple-webserver-or-web-testing-framework
web-application-frameworks-c-vs-python
django-vs-other-python-web-frameworks
what-web-application-framework-for-java-is-recommended
can-anyone-recommend-a-simple-java-web-app-framework
...
Good luck.
web2py is a python web framework that is completely self-contained, runs portably off a USB drive even. The manual is available on scribd, and after an hour or two of tutorial you will have a pretty good idea of what a python web framework will be like. I can't comment on Java at all.
EDIT: Django and web2py are very, very similar. I think I prefer web2py because it does more for me that I don't have to do, but from the POV of, say, Java frameworks, Django and web2py may as well be the same thing.

Categories