How to integrate programs written in different programming languages? - java

I have two developers in my team. One will develop a Python application, the other will develop a Java application. The Java app generates a boolean value which is used by the Python app.
How can I integrate these applications? I have thought about using:
Return codes: Python app calls the Java app, then the Java app uses
the return code to inform the boolean value.
Sockets: Connect both
applications through sockets and exchange information. I think this
is overkill.
Files: The Java app does its stuff, writes the output to
a file, then the Python app reads this file and retrieves the boolean
value it needs.
Any other suggestions? I'm not just looking for a solution, I'm also considering here aspects such as code organization and "beauty" of the overall solution.
Edit 1:
Thank you #user2387370 for the recommendation of using Jython, but I can't use it.
Edit 2: Thank you #RickyA, I'll have a look at messaging systems (such as zeromq, which you mentioned).

Use a messaging system like zeromq. That has libraries for both languages and allows you to integrate them seamlessly.
Your proposed options will get clunky interoperability. (filelocks, dead sockets, dead processes etc..)
Also this page lists some tools that can be used for pyton/java interop. I can't recommend one since I used none.

Related

Is it possible to use more than one framework at the backend(Spring boot + Django)?

tl;dr: Is Spring + Django back-end possible?
When I was new to industry and was still working my way around the office, I got interested in Django and created a very small, basic-level application using the framework. When I got to meet my team after a few weeks, they said to go for Spring framework. After spending half a year on the framework and the main proj, I finally started to get time to start working off-hours. But, I don't want to lose both the skills - My teammate(when we were still in office ;) ) once told me that they worked on a project that started with python code, and then later added features using Java. And I am unable to find any helpful google searches(mostly showing Spring vs Django).
How should I go about it? Is it too much to ask for? Is it worthwhile? Will I learn some new concepts of application architecture a noob like me would have missed. Please provide me with some insight.
Are there resources(docs) I can go through?
P.S. I'm not a diehard fan of either of the frameworks right now, just another coder testing waters.
You can't write java in python.
You can extend Python with C/C++ which is quite common: Extending Python with C or C++
And about the part that they told that they added features with java:
It's common to create different parts of a project using different languages and tools. Microservice architecture is a common architecture for these kinds of use cases. You basically code different parts of the project in a language you want and then you connect all the parts using different methods like REST APIs, gRPC and etc.
Imagine you are creating a website like youtube that lets others upload videos. There is a form that users upload their files and you store them in your storage and then you have to encode the video file for different qualities. You can code the form handler using Python and Django to store the files in your storage. Then you can code another service using java that handles the encoding part which is a heavy process. When an upload is completed, you send the file or file path to your java service using an internal REST API and tell the service to start encoding the video and notify the Django service and then the Django service will publish the video on the feed that can itself be written in another language.
I would say go for 1 framework and stick with it. For example Django if you want to code in python, and spring if you want to code in java. Learning both frameworks however brings a lot of value, because you can compare their benefits (eg. spring forces you to write clean code, django has build-in and simpler database management)
I like Django's build-in tooling a lot, you only need to know python for it to work. Spring requires a bit more knowledge of eg. hibernate for database management. However I predict Django will outgrow spring at some point, because of cloud valuing fast iteration over code and quick startup time (auto-scaling apps) over large overhead apps and long boot times. Hoever, if you like java, I can recommend JHipster for java/spring webapp development to get up to speed very fast and learning the ways of REST CRUD api fast.
To combine 2 programs: write your main logic in one app, and write a small service in the second language, making sure its independent of the first app (no back and forth communication and complicated logic, but simple independent request/response, as if the main app was never there). Add a REST api to the second app and use eg. http requests to communicate.
What's possible in terms of combining languages:
connect different applications with each other: by letting them communicate through their APIs. For example a python api developed with flask or django can send requests to a java api developed with spring, as long as they have a way to communicate (eg over http, or via some queue like rabbitmq)
connect a webapp to 2 different backends: by using a shared authentication system: For example a keycloak authentication server to handle tokens, that your backend applications know about.
What's not possible (and also not preferable):
combining java with python code in the same program: there are some hacky ways to get it to work, but its asking for trouble and not readable.

Recommended Format for an HTML-embedded app?

I am trying to develop an application that can be embedded in the HTML code of a website. I looked into using a Java Applet, but I am turned off of this option from the fact that Applets are decreasing in popularity, and that I am not totally comfortable with Java.
I have experience with Visual Studio C# and VB, and I was wondering if there was some sort of option where I could write an embed-able application using Visual Studio, and if they have some sort of equivalent or similar tool to Applets that I could utilize.
Thank you for your responses.
This depends on whether you want the C# code to run on the client or server side.
Server side you will have to use ASP.NET.
If you want to run on the client side (which it sounds like), this is essentially impossible due to security concerns and technological limitations (a .net clr would need to be invoked and the code passed to it for execution).
You could potentially look into using javascript based activex/com objects to invoke the clr.
Embedding C# code was possible in earlier versions of Internet Explorer, but no longer.

Which option is suitable to replace Java Applet?

I would like to replace Java Applet which currently needs to use client's resources, i.e. external readers, and to communicate with a server via socket.
Reason:
1. I have thousands of client machines using this Java Applet program, and most of them are running out-dated JRE. When the Java Applet program is updated / added new features, all client machines will need updating the latest JRE.
Expected Solution:
The Java Applet program would be expected to be replaced by a web-based application, which allows to compile and run source code at client's side such that the new web-based application could still use client's resources and communicate with server via socket.
Can I use JavaScript to achieve it?
I would very appreciate your help/suggestion for this problem. Thank you!
JavaScript is a scripting language that gets evaluated in the browser.
I would not describe it as compiling and running but yes, it does mean you can run code in the client and is commonly used to create applications that run in the browser.
There's a staggering amount of frameworks that you can use to write your application. Take a look at the TodoMVC site to see the same TODO app created using several different frameworks.
If you come from Java applets, GWT may be interesting to look at.
If you wish to let the JavaScript client listen for messages from the server, take a look at websockets.
The smart card reader is going to be a problem, though!
See Architectures to access Smart Card from a generic browser? Or: How to bridge the gap from browser to PC/SC stack?
By the way:
The real issue with outdated JREs is not that your code will not run on old JREs, you can create perfectly fine applets using java 1.4 or java 5. Any libraries you may need you can deploy alongside your applet. The pain is a security problem. Anything but the latest version Java plugin is getting actively exploited and puts the user at risk. Occasionally, even the latest version is not safe.
try socket.io
I think this is the latest technology you can use to communicate with client browsers. it support the latest browsers and mobile browsers too.
hope this will help you.
Javascript has become very powerful with HTML 5.0. Here is a list of new elements that you can use to access all kinds of resources, including local files, audio, video, GPU rendering (canvas + WebGL) and GPU compute (WebCL). Here are even more things you can do, including database connections and networking. You can even create offline Javascript applications.
jQuery and jQuery layout make robust GUI development a lot easier. Rich tool suites, such as Google Closure offer optimization and a compiler for improving performance and detecting obvious mistakes early in the development process.
W3 offers useful stats for making an informed decision on how many users on average have access to which features. Note that the most annoying guy in that list arguably is IE8 due to it's lack of proper HTML 5.0 support.
In case you want to stick with Java, then one alternative would be to use my http://bck2brwsr.apidesign.org project. It's goal is to create small Java that can run in 100% of modern browsers without any plugin installed.
There are Java bindings to HTML (via knockout - one of the four most popular frameworks for HTML5) and that is why one can code whole business logic in Java and just render it via HTML. Should be enough to replace most of the applet UI.
In addition to that there is an experimental API to render on HTML canvas. People use it to write Java games that run in a pure browser.
There is a simple way to communicate with server via JSON REST API or via WebSockets. A live example is here.

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.

Suggestions for an embeddable scripting language for iPhone and Java app?

I'm developing an app for iPhone with a Java desktop companion that it synchs to over the network. I'd like to embed a scripting language into both apps so that end users can write scripts that add new behaviours and interact with the object model, and so that I can more rapidly develop some features.
Any suggestions for this, or anyone done this before and got experiences to share? I'm thinking of something like tcl which I've used in the past, but not tcl itself as I'm not a big fan of the language.
Main criteria are that it should be
lightweight as poss (memory usage)
easy to interface and extend with java and objective-c
(nice to have) readable/approachable for people with limited programming experience
My initial hunch is that I should be using one of python, ruby, or lua. My preference would be ruby, as I already have some experience with it and don't know much about the others. However my main unknown is which of these is easiest to get integrated with iPhone and Java.
edit 2: per Jason Coco in the comments, the SDK terms prohibit embedded scripting languages. Checking into this it does indeed seem to, but I read it to preclude dynamic installation and extension only. I would still be interested in answers here, as the agreement doesn't seem to preclude having prepackaged scripts inside the application bundle itself - Apple would still get to vet that code.
The agreement also seems to allow use of Apples "interpreters"...what are these? Javascript and what else? Any route to use those here?
JavaScript
As I understand the iPhone SDK Licence, there is nothing preventing you from using a scripting language in your app - just that you cannot intall any interpreters or runtimes of your own. You can only use those scripting languages for which Apple provides the interpreter in the SDK.
Given that you want to run the same scripts in your iPhone app and in a Java app, the obvious choice is JavaScript. You can use Apple's APIs in your iPhone app, and something like Rhino (http://www.mozilla.org/rhino/) in your Java App.
You have to be aware that there may be slight differences between the two interpreters in the more obscure regions of syntax or object model.
P.S. I assume that users are going to be writing their own scripts to run on their own device/desktop. These would be part of the application data, and should be fine under Apple's licence
The only thing I've seen that allows a non-objective-c/c/c++ application to run on the iPhone is Unity3d (http://unity3d.com/unity/features/iphone-publishing) - BUT, it uses C# via Mono and does a full static compilation (http://tirania.org/blog/archive/2008/Nov-05.html) down to native code in order to do it. So, by the time the app is on the phone, it's no longer C# so it's allowed by Apple (and several apps have already made it into the App Store - so this does seem to be acceptable).
I don't think you would be able to do the idea you're talking about even if you could do the equivalent for Java/Ruby/Lua/Python/other (so having your desktop app pre-compile and upload just the native code to the device). As far as I know, you can't execute code outside of your application bundle...and if you modify the application bundle, then you invalidate the codesigning Apple does which allows the app to run on your phone in the first place. So even if you could get executable code to the phone, I'm not sure that you would be able to run it if it didn't come along with the app in the first place.
I was researching this too, and it seems that it's possible to pre-compile a Lua script (by converting it to C using Lua and then compiling the C file). Because all of your code could then be part of the application bundle (including the embedded Lua interpreter), it should be acceptable as an iPhone app.
See here for a discussion and sample script:
http://lua-users.org/lists/lua-l/2008-11/msg00453.html
*Note that I haven't tried this (yet)

Categories