Different JAVA Versions in a single springboot app - java

I am not well versed on Java Spring Boot. I am asking for help here. Flow is this - a Message Streaming platform (supports only Java 8) --> Consumer --> Data Lake Platform (Supports only Java 11).
So We need to write a Consumer app on Spring boot consume a message from Streaming platform and update/insert into the Data Lake Platform. For now, wwe are trying to create two different springboot apps to consume and write. I wanted to know if we can have only one app (which can support multiple Java version based on source and destination). Is it even possible or not.

Short answer, no. You can run two JVM processes on one physical server using different Java executables, sure... However...
based on source and destination
This shouldn't matter. From what I understand, those are external services, and do not affect the serialization formats your Spring app would be able to use, as a stream consumer or data-lake client.
In fact, Java JRE 11 can run compiled "Java 8 code", so it would make more sense to simply update the Java version on the streaming platform side, if at all possible.
Same answer should apply to any Java framework, not only Spring. You may even be able to write such service without Java/Spring...

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.

Convert AWS SageMaker ml model into a java library

When using AWS SageMaker, after you complete the training of a model, SageMaker will output the model as a model.tar.gz file in a specificed S3 bucket. The next step the documentation recommends is to deploy the model onto SageMaker. However, I do not want to deploy the model. In my case, there are some service to service latency considerations for not going that route. Furthermore, I would also like to still utilize predictions from the model in offline scenarios. Has anyone been able to take the model.tar.gz and make it into a java library? What tools did you use? How did you parse the model?
Most of the machine learning in the recent years are developed in Python and it is very common and performing well to serve the model with Python environments. You can see the flow in SageMaker documentation (https://docs.aws.amazon.com/sagemaker/latest/dg/how-it-works-hosting.html), but this is completely open and can be achieved with NGNIX, GUnicorn.
You find some Java libraries for running some of the common machine learning algorithms, mainly: https://github.com/jpmml
Nevertheless, check if you must have Java as your run-time environment. Java will add very little value here (if any) and a lot of issues of compatibility.

Running a Java Program from a Browser without Plugins

Some weeks ago I wrote a little Java program showing a real time plot chart (i.e. records with tracking of current time), with a modest 25 kbps streaming rate, 20fps framing rate, and no relevant user interaction. Thinking on its eventual deployment as a Mobile App, a Web Server chart or simply as a PC as a program, being Java a perfect selection for me.
Before starting now the Web version of this program, i started to investigate and according the 2016 Oracle White Paper Migrating from Java Applets to Plugin Free Java Technologies:
The deprecated plugin technology will be completely removed from the
Oracle Java Development Kit (JDK) and Java Runtime Environment (JRE) in a
future Java release (TBD). Java Web Start applications do not rely on a
browser plugin and will not be affected by these changes.
And according 2019 OpenWebStart:
Java Web Start (JWS) was deprecated in Java 9, and starting with Java
11, Oracle removed JWS from their JDK distributions
And then I get lost.
Hence, which is the way to go with a Java program like this? Which is the proper sustainable Java way to do this (and not subject to something like what happened to Java Web Start)?.
Or should I simply move to another way to do it, now that the program is in its infancy, considering I am not precisely a fan of Phyton, considering PHP is not precisely the way for programming these kind of numerical things, and considering I am not so willing to give Microsoft technologies a chance?
It is not a problem for me to adapt and rewrite my current code if necessary, but possibly not doing this every 5 years.
Which article would you recommend me to get back to the proper path?
Thanks in advance.
The easiest and highest-performance option is TeaVM, a transpiler that converts Java classes into JavaScript. Your code then runs in the browser natively without any plugin.
Read an introductory article here: https://blogs.oracle.com/javamagazine/java-in-the-browser-with-teavm
TeaVM's main site is here: http://teavm.org/
Thinking on its eventual deployment as a Mobile App, a Web Server
chart or simply as a PC as a program, being Java a perfect selection
for me.
(..)
Hence, which is the way to go with a Java program like this? Which is
the proper sustainable Java way to do this (and not subject to
something like what happened to Java Web Start)?
Two lines of Java
What happened is that our old friend, the Java Standard Edition, split into two lines:
Oracle Java SE ("commercial Java"): needs paid license for commercial use for releases since April 16th, 2019
OpenJDK ("open source Java"): open source (GPLv2 with linking exception), does not contain Oracle's Java Web Start implementation
The Oracle Java SE version keeps Java Web Start and Java FX available and supported only for Java SE 8. Newer Java versions, esp. Java SE 11 do not carry these anymore.
It is not a complete client / desktop technology removal, because Oracle, according to the Java Client Roadmap Update 2018, continues to support AWT and Swing for at least 5 more years on both Java SE 8 and Java SE 11.
You can continue deployment via Java Web Start
Open source Java got a decent implementation of Java Web Start, which is free and available for Java SE 8 and newer Java versions like Java SE 11.
This is Karakun's OpenWebStart based on Red Hat's IcedTea-Web, now beyond version 1.0, which you already found.
Continued support is not guaranteed but seems likely. So you might continue on this track.
Or you might deploy via an app store
Oracle's explanation for dropping Java Web Start was, that they want to change the deployment model to applications with bundled runtime:
As client application development continues to shift from the old
“plugin” world to modern deployment, the need for a standalone Java
Runtime Environment (JRE) that is installed centrally, separately from
Java applications has diminished. Using the ‘jlink’ tool introduced
with JDK 9 will make it even easier for application developers to
package and deploy dedicated runtimes rather than relying on a
pre-installed system JRE.
(Source: Faster and Easier Use and Redistribution of Java SE)
Deployment, according to Oracle, would occur via some app store like the iTunes Store:
No doubt this was true, but the OSes have shifted hard and fast away
from this model. The "app store" model is now it. macOS has been
ratcheting this down hard for several years now. MSFT -- even in the
enterprise market -- has signaled this direction as well. For sure we
need to find options to support the legacy, but the future here is limited.
(Source: OpenJDK discussion mailing list)
Note that Java Start Web Start handled the updating of available new versions of applications on the client machines, and so do typical app stores.
Of course you can serve a version of your app with bundled runtime on your web site, but then you usually have to implement some mechanism to handle updates of your application on the machines of your users yourself.
What to choose?
It is true that the separate JRE installation has disadvantages, e.g. I changed my JRE recently and suddenly the IDE for Java did not work anymore. :-)
Moving deployment from a web site you control to an app store controled by the OS vendor or mighty players like Valve, has its own challenges. E.g. access restrictions, fees, release delays because of the review process, or they might not like your app for some reason and will not publish it.
Then adoption: Personally I have seen private use of app stores mostly on mobile devices and macs, but no use in companies yet. This might be a factor in your decision which road to pursue.
I've missed the Java on browser too. Because of curiosity I just developed an "JVM-Server", which precompiles the Java-Classes to native JavaScript and serves them to a WebBrowser.
Look here is a Hello World example application which is running on Browser:
https://github.com/neo-expert/jsjvm_helloworld
There is also a Library which implements WebGL bindings. In the above Example is a WebGL demo included, where a 3D cube will be rendered. The code is written in pure Java.
Is it a swing app? Will have to map that to a web (html) app to make it work on a browser nowadays.
You cannot run any of those programs from a browser directly.
Java used to java applets and java web start - where the browser helped you install a java app on local system but user had to seperately have installed JRE (Java run time) to run it locally.
Now all we have are web apps. basically apps that might have a a session, login, authenticaiton and authorition but in the end the app outputs HTML, Javascript, images and text data (JSON. XML etc) that is rendered on the web page.
Look at J2EE. I'm a java fan. but it takes longer to develop, but i think it runs better. Especially with a good framework like Spring Boot (it includes MVC see https://dzone.com/articles/7-best-java-frameworks-for-2016)
But learning curve is there. Buy a book or do a course online like udemy or similar.youtube has free videos. but not sure of the order/ quality.
If you choose php - many free and cheap servers like x10hosting to start with and learning curve is less too. Good framework - packages like drupal and wordpress.
On the browser HTML, Javacript run. There are frameworks for this too. Like gogole's angular https://angular.io/ this too needs a book/seperate study. Old days we used to use simple Javascript ...
For mobiles - sometimes can get away with using a URL OR there are frameworks that wrap a web page in an 'app' for android, iphone etc OR make a native app - but then will have different code bases.
I know someone who used a game engine to make a mostly single code base (some classes are specific to each platform like android, iphone) but used to render business graphs and a few interaction use cases (about 40). He used https://libgdx.badlogicgames.com/
As your research already revealed, Java is not a relevant web frontend technology anymore. Prefer Javascript and CSS for browser frontends, instead. Feed the frontend code with data served by Java backend services. The Java Servlet Specification is still the base for server-side Java. Many frameworks (like Spring or Jersey, to name a few) are build on top of it. Either chose one of these frameworks, or - for really simple use-cases - build an application only with plain servlets. Any servlet needs to be deployed in a servlet container (e.g. Apache Tomcat).
Your Java code needs probably some refactoring in order to provide an API for the web. As you are asking for near-realtime communication, you should have a look at the WebSockets standard which is designed for bidirectional and fast client-server-communication on the Internet and supported by all modern browsers (nice intro explaining the difference to WebRTC and arguing why WebSockets are often the better choice). To plot your data in a browser with Javascript and SVG, have a look on the D3.js library. A quick search brings you to demos like this one: D3 Real Time Chart. Also, there are other libraries that are built on top of D3, for example plotly.js.
Summary:
Java is fine for web backend services.
Your code needs refactoring to serve a backend API, preferably WebSockets. (introduction on how to start in Java at https://www.baeldung.com/java-websockets)
Get familiar with a Javascript browser plot library, such as D3.js.

How to extract Java Android sources and integrate in another project

We are developing a java based framework, running on Linux OS
that will provide an infrastructure for developed Applications (Java)
which is very similar to Android OS architecture.
Our framework consists of services and data providers running as different processes and providing
data to the applications running also in the system.
We want to use frameworks/base sources from the Android OS and use it in our framework
after some modifications, without building the entire Android OS.
Is this task possible to achieve in a reasonable amount of time?
If so, can you please point us where to start?
Thanks
If you want to modify a portion without needing to rebuild everything i think you could trying using AOP and compile time weaving, that is AspectJ in your case. Have a look here.

GAE: Python and Java services together under same App ID

I have some Python services and I have defined handler locations for them in app.yaml
I also have Java services and I have configured web.xml.
I want them both to be under same APP ID, e.g.
The Python app would be in http://myapp.appspot.com/pythonapp
The Java app would be in http://myapp.appspot.com/javaapp
So how can I accomplish this?
When I use GAE Java Eclipse plugin, it only uploads the Java service and deletes existing Python service.
When I use appcfg.py update it only uploads Python service and deletes existing Java service.
There is a hack: upload to different versions
You can have one instance version in Java and the other in Python. The default one will be visible to public via http://myapp.appspot.com.
You can access the other version (in browser or programmatically) viahttp://version.myapp.appspot.com, e.g. http://3.myapp.appspot.com
If you wan to acces both of them via the same URL, then you will need to proxy the request or do a redirect (if your client allows it).
There is no official way to use two runtime environments with one app. Jython is one way to run Python code in the Java runtime environment.
Depending on your needs, you can try using two different app versions with the same app ID. One version can use the Java runtime environment, and the other can use the Python runtime environment. Both versions would see the same datastore. You can address each app version separately using appspot.com URLs, though they're not pretty: http://version-id.latest.app-id.appspot.com Only one version can be the "default" version (http://myapp.appspot.com). This uses 2 of your 10 allowed versions, and you'll have to be careful to deploy each version with the correct version IDs. So it's not an ideal solution.
I'm sure that you can have only one app at same time, because it's different app servers/VMs for each type. I mean you can't upload different parts, can't have different sdk for different url on same app, etc.
Btw, you can try to use jython, it can interpret your Pythong code in Java project. I'm not sure that it's production ready (there was a lot of problems with it when i had tried it few years ago), but maybe it's helpful for your situation
As #splix said, deploying two app with different languages into the same appid seems to be impossible. So how about a workaround instead? Set a /pythonapp servlet on your Java app that will redirect all requests to mypythonapp.appspot.com via URLFetch.
The drawback of this workaround that come into my mind is that you are losing the information about the logged in user provided by the User API, so you would need to attach the information on the redirected request. Depending on the scenario of your app, I don't know whether this would be a show stopper or not.
EDIT: What I had in mind is what Peter suggested, using different versions rather than deploying them as totally different app, sorry that I mixed them up. Deployment to a different app would mean your Python app and Java app could not use a shared datastore.
The difference on my answer is that you could use URLFetches to forward the requests between different versions of your app. But having the redirection performed on the client's side as per Peter's suggestion rather than having it done on the server side as in my answer would probably be less hacky.

Categories