How to pass data from Java to Javascipt? [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I would like to create a website that visualises different algorithms. I would like to implement and compute the algorithms in Java but visualise and present in to the user on a website so using JS, HTML and CSS. To be clear I don't want to use Java for backend, I just want to implement the algorithms and compute them using Java. How would I go about doing that? Could this be done using micro-services?
I know that you can't run java in a browser. I just want to have some kind of service that computes the algorithms and passes the data about how to render it to a client side which renders it.

You certainly can, suppose you have a java component that handles the data processing and algorithm. This component can just be a simple java application that accepts parameters and produce some output. You then have a back-end micro service, a REST API for your front-end to consume. The back-end can be done with various frameworks and languages. The back-end would invoke/make request to this java component. You typically do this if you need heavy processing as a separate component. Imagine you need to do heavy machine learning or data analytic. Your back-end would make request to these component that do the heavy computing. Also if the processing is long and complex then you will have to do request, and poll for results. There are quite a few things to consider, but it depends on your needs.

Related

Should I use Python or Javascript to build a text-based adventure using Django? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I hope this doesn't come off like too strange a question, but I'm relatively new to Django specifically. I currently have a website going using Heroku and Django and I would like to post a bunch of mini-projects and such I make there. One of the ones I want to do is a text-based adventure. I'm relatively proficient in Python and Javascript individually and have built similar things in both, however I'm having trouble thinking how best to translate this into the Django framework.
Currently on my website I have a bunch of pages just for things like articles and written pieces. All of that is working fine and I've even added a mini CMS to the backend and that all works alright. However most of that was either building stuff entirely in backend, or entirely in frontend and then just doing a data linkage. There's no real python code going on in the backend outside of constructing the views and models etc. If I was to build this in Javascript I would likely just hardcode a lot of the writing for a text-based game, likewise with Python, however I feel with Django and a linked Postgres DB there's potential to make it more dynamic and less hard coded using this, but I can't quite figure out which is best.
My question based on this is: should I construct the game entirely in javascript which is just served to the webpage and then update the view using POST requests and a data table, or is there a way to create a python script which integrates with the web page a bit more effectively. I suppose the question is really more is it better to build the game in front-end or back-end, as I can't see a particularly effective way of dividing it across both?
You have to ask yourself about what data does the game needs from the backend (Django and Postgres)? Be clear and specific about what data and when that data need to be in the game frontend (Javascript)?
With that said, one way to approach this is to have the game written in a pure frontend and will be cleaner to be written in javascript. It should focus on the game logic and gameplay.
Seeding Initial Game Data
If you're very clear with what you need on the game (i.e. frontend) during the initial loading, then you can consider feeding all those data during the initial page load. (more detail: https://stackoverflow.com/a/298793/764592)
Subsequent Data
The other data from the backend which cannot be determined after the initial load will have to be requested via XMLHttpRequest to a separate Django views which returns the data only (either in JSON/XML/etc).
In those requests, you need to make sure if the backend logic does the necessary validation as well as the frontend logic. If you find that there is a duplication in the frontend and backend logic, do consider move that logic in the backend, and have the frontend call the backend instead.
Make sure you are clear with the responsibility of each backend and frontend.
The game runs on Javascript, and the backend stored data is validated in the Django.
Note: The above is just one way you can deal with it in a clear separation of responsibility. But if your game is extremely simple, you can even consider do everything in Django level without Javascript. Or Everything in Javascript without Django at all if no database/server logic required.

Convert a Qt C++ application to a web app [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I wrote an application which connects to a MySQL database and queries/adds/deletes data in Qt Framework. I want to convert to a web application run inside a browser. I have some experience in PHP and I could code the whole app in it, but I have a problem: I would be forced to reload the page every time when I want to do something with the database. I want to make something like Facebook/GMail/Facebook Messenger where accessing a database is achieved without reloading the whole page. This is the part which I never done before.
I have some questions about this:
What are the JavaScript libraries out there which I could use?
What is the appropriate way to do this: create a backend which is between the web app and the database, or connect to the database directly?
I don't necessarily need to stick to that languages, I'm open to new technologies, programming languages.
Edit:
Based on suggestions and my own research I found two technologies which I think I could use: AJAX and PHP(thanks to Hugo Dias) or NodeJS. I didn't wrote any code yet, so which of them would be better for my app? A little more information: this app will used by only the small number of users at the same time, like max 10.
You need to use a web server, for eg. Apache Tomcat. If you want to keep your code in c++, you could convert it into a CGI. Otherwise, you can use java servlets or JSP along with JDBC. You can set it up so that when a button is clicked the CGI script is triggered and the database queries are run.
Short answer:
Yes,there are libraries that helps you with that.
JQuery and PrototypeJS are some of them.
There are some ways of do this, but in any way,you need of a Backend. It's inherent in architecture of Web(Client-Server).
Long answer:
Yes,there are ways of do that. What you're looking for is called AJAX(and stands for Asynchronous JavaScript and XML).
AJAX is a technics that gathers some technologies like XHR and Javascript, mainly.
It allows you work with asynchronous requests,what basically lets you update your page without reload it.
You'll find extensive documentation here about it,and here a simple example with PHP.
The architecture of App is of your choice. Under the Client-Server architecture,you can apply what is best for you,since a monolithic system until a MVC or MVVM pattern.

infrastructure for aggregating data periodically and serving it using node.js [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm interested in using Node.js to aggregate various pieces of information from different servers using JSON API's. Summarize it and serving it as static web pages. The data I am collecting is ~100kbytes so I am assuming it would reside in the memory and be served when request.
So is there a way of aggregating caching data in memory as a JSON structure which could be served to static pages. I would prefer not to write it in MongoDB.
I am using 'serve-static' to serve static web pages from node.js.
The npm site shows 241 results for cron.. Another approach would be to remember the last time you did an update, and, everytime a user connects, check that time and do a "just in time" update. I have a site that does the latter. Depends on how long and complex is the update.
It seems to me that using a templating engine like JADE would be superior to serving static pages that aren't really static. Not that I like JADE, I don't, YMMV, but if your data is dynamic then using templates seems to make way more sense.
Storing JSON in memory or in Mongo is so simple that I really don't understand that part of your question.

Want to create a new application for website traffic monitoring ( analysis ) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to create my own application for monitoring traffic of my website without using any third party tools like google analytics. In which I want to log screenshots, user details, page details and cookies. So what technology should I opt so as to achieve this goal and which will be best suited and what work flow should I follow.
I've never done this kind of work previously so I'm new to this. Any help would be greatly appreciated.
The technologies I know are : javascript, nodejs, django(python).
You will have to break down your application as it is a humongous task to create something like GA.
You will have to track many user activities(click,spend time etc).so you can do that in plain js or use a cross-platform lightweight library(angular.js) that can make your life a little easy.
Now since you will have to send large set of traced data to you database with minimum latency,use Node.js in this scenario.Simple Ajax call would also work but then it would be very slow.
Now comes your database.Prefer NoSql since it suits your requirement of unstructured data ,preferrablly MongoDb which can help you with its own mapReduce,large storage capacity
.Since there will be lot of calculation involved you can use your python knowledge which can help you process data a lot faster.you can use other languages as well(eg.Go)
Your processed data and results can then be stored in Redis(which acts as a caching layer).
you can use sophisticated graphic library like d3.js,Highcharts.js for displaying Graphical data on the client-side.
There are a lot of factors that can be involved.This is just a very basic outline of what you could do.

Real time collaborative use interface on the web [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm wondering what the technologies and best practices are behind real time collaboration in web interfaces.
An example of this is of course Google Wave. Another is PivotalTracker.com.
I'm particularly interested in any work (frameworks, plugins, etc) people are doing with Ruby on Rails here.
I imagine it would have to use Javascript underneath at some level, but you would need a way to abstract this out. Probably polling the server periodically to see if changes have been made, and also a way to resolve conflicts if in the middle of editing something the server comes back and says someone else has updated it.
Thank you!
Wave has operational transform that has a nice property of being easily combinable. You have two users, each of them does "something" in the user interface and two "somethings" can be combined into final document. That allows you to skip the problems with conflict resolution.
A nice way to enable real-time updates to state of the app is by using Comet, which is essentially a geeky codename for keeping an alive, long standing, unterminated get/post request to the server, that server finishes and responds to when something happens on the server. It allows sending to the client instantaneous updates without having the client periodically poll.
I can't really say how to abstract this away in javascript/r'n'r, many of the underlying technical details are hard enough and application specific that no framework supports them out of the box.

Categories