How to use Java in PHP? [closed] - java

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 8 years ago.
Improve this question
I want to use WordPress for my web development, which is PHP written, including the database connection to MySql. The whole thing is PHP. But I need to use Java to back-end data processing and a number of existing Java open source libraries.
A google search shows that PHP/Java Bridge is a way to go. Is that bridge best way to go? If everything is PHP with WordPress, is still a way to use J2EE technologies, inlcuding JSP, Servelet, etc?
edit
Java is needed becaue I need to run machine learning algorithms, libraries for which are only available for Java. Also, PHP may run into efficiency issues when it's used to process large amount of data.
A good example of libraries in Java I am going to use is those processing Big Data, which are mainly Java, like Hadoop.

The very simple answer here is don't
PHP is designed to, at every page request start up, execute a small series of scripts as a single operation, output the data associated with those scripts and then immediately die after generating the output. It literally does not have time to wait for your Java programs and libraries to do their thing, so don't try to put one in the other, which is why PHP scripts that rely on databases tend to have heavily optimised databases for immediate retrieval, instead of general databases that rely on joins and selects that take a few seconds to form the correct data response. Neither PHP or users browsing websites have time for that.
What you could do is wrap your java tools in Java Servlets and have them running on the same server/host that your PHP instance is running from, so that your scripts can access the Servlets as http://127.0.0.1:7254/... as it would any other restful API it needs to use while generating your script output, as long as you make damn sure that you're not going to make PHP wait: if it has to send data to your tools, that is a post-and-forget operation, PHP should not be getting any response back other than an immediate "data accepted" or "data rejected" before the data is then actually handled by your tools. If you need to post data and then get a result back, you're going to have to use two calls. One to post the data, and then a second call to request the result of that posting.
For instance:
web page generation chain: WordPress CMS based on PHP -> your database
web input for processing: WordPress CMS based on PHP -> Java Servlets for machine learning
data processing chain: Java Servlets for machine learning -> your database
So you build pages only based on what's in your data base, you post data to your java Servlets only to get them to start doing something and you don't wait for a response, their result will end up in your database and you'll get it for pages once it's in, and your java programs do what they need to do independently of your WordPress setup.
And if you're going to do that, you should probably write that functionality as a WordPress plugin that can talk to your Java Servlets.
And now you have a second project you need to work on: turning your java programs into web servers. Not terribly complex, but definitely something you're going to lose some time on doing right (because you'll need to wrap with servlets, as well as make sure you can have those running without crashing on the same server as your wordpress instance, which is always fun)

Related

Styling Java with HTML/CSS [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
So im fairly new to Java, anyway i have a implemented a simple Java program on IntelliJ which runs in the IntelliJ terminal, it basically ask the user to input some details and then records them along with the current time.
I now want to style it out using HTML/CSS to convert it into a webpage, where the user would enter the details into input boxes etc.
Im not sure how to approach this, what would be my best shot?
Also the user input is also being stored in a variable at the moment, would i have to use a database instead for a webpage?
Thanks.
Well I would recommend you to read first about what is Model-View-Controller paradigm in web page architecture, then you can probably better reply to yourself in terms of what you need for your webpage in order to do what you want.
I will grasp some about the things that you need:
You will need a database to store your user input details along with with the current time. (MySQL for example)
After that you need to define which type of data you need to save, you will have to make models in java for parsing those details from java to the db and vice versa.
Then you will need to create some services (You can learn about repositories before services if you need, which you probably would) to support those connections with the database in which you will retrieve data from DB.
A way to control how those services to serve your webpage is having a controller for processing the HTTP requests.
Last but not least, the controller will "glue" your jsp views with the data from services to be shown in your browser.
There will be many other ways, at least this is the way I know. I use Spring framework for building the MVC.
You have to do full stack page with java backend and html & css for the front-end.
Do a webservice with spring boot this generate a restful API to communicate with your web page using HTTP methods ( Get, Post, Put and delete ) and use AngularJS for example to parse the webservice created.
check out this : example
Quite simply, you'll need a web server to spit out HTML. I mean, there's lots of ways you could do it, but far and away the most popular is a web server.
There are lots of options for you. As an Eclipse fanboy myself, I can't say specifically, but a cursory google search yields this Tomcat plugin which should allow you to run a web server via IntelliJ. There are probably dozens of other plugins for differnt web servers you could use.
What you put into that server is up to you - it could be a simple html document populated by parameters, a REST endpoint, a JSP, who knows what. That's beyond the scope of the question - the first step is getting your web server up and running and then deciding the framework to use.

suitable framework and technology stack for my project? [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 7 years ago.
Improve this question
I have to submit a project in my college for which I have only two months! I already have an idea of what to make but don't know which technology to go for. I want to use something latest so as to make my project more efficient and flexible.
I wanted to make something like "Attendance Management System" in which we can take attendance of students and save the records on underlying database, also to perform some kind of data mining on the data (to find some interesting patterns like the_most_attended_lecture or to apply some probabilistic model to estimate the_next_possible_bunk or analysis based on an individual student record to compute anything interesting...) and then to develop an android app for the UI that can handle request and response to the database.
I'm really confused as what to go for? Currently I have no knowledge of the following but my friend suggested me to choose among them: node.js (with express framework) REST API, PHP, JSP, JSON, and MongoDB.
I would really appreciate your help guys. Please help. Thanks
Lets try to decide the technology stack according to your requirements.
1. Latest technology - Although you didn't give any justification for this requirement. But as you want, latest fads going on are for web server are node, go lang, nginx(if you happen to choose php in the end) and mongo, elastic search for data store.
2. Less amount of time - You have only 2 months to learn the technology, build the prototype , design the db schema, implement everything and test. Hence I will suggest you to go with node.js or php(I am assuming you are familiar with JS and php).
3. High database IO - I don't know what scale you will be working upon but the only major thing you server will be doing is DB IO, hence you should choose some non-blocking technology and among them most famous is NODE.JS.
Node.js is something which is fulfilling every requirement.
If I were you, I would have choose express.js (express init and you are ready to go), Mysql (If you are not familiar with any NoSql as mysql seems to be fulfilling every requirement). And android app could be anything like cordova as app is doing nothing but HTTP request and some presentation of data.

Best and cheapest way to store users data [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 8 years ago.
Improve this question
I have an app out in the market and planning to maintain basic user data somewhere on backend.
My app is free so I am NOT getting any money from users.
My question is what is the best way to store this data(data has name, email, phonenumber etc.)
One option is to use Google Mobile Backend starter kit but that seems too complex for such a small requirement.
Appreciate your help.
Thanks.
Ok, there are many options you can achieve your goal and these options depends on your proficiency in other areas apart from java and your preferences. Below is just a small list,
Server side language: php, jsp, etc
Database: MySQL, NoSQL, SQLite, etc
Webhost: any free provider (just google "Free webhosting service")
Client side: as you mentioned you already have an app on play store so you will have to update you application accordingly and release new version.
I prefer to use combination of php and MySQL for all my back end work as I feel it is very easy to create and maintain. I also use 000webhost.com as free webhosting service, this service is completely free and also supports php and MySql without any restriction.
First Step I would suggest you is to choose your web-hosting provider, sign up on it and setup your database through PHPMyAdmin (Very easy to do so if you know basic database fundamentals).
Second step would be to create an API according to your choice of server side language (I am assuming you would use php but you are free to use any other language). If you don't know any server side language then you might want to follow some online tutorial and get your self familiar with php (which is again very easy of you know some other programming language). You can simply start from coding basic functions such as retrieving all data and echo them on browser or insert some fields in database, etc. I would advice you to completely code and test all your functionality on normal web browser before you go on about updating you android application and the reason is that once you know what response you are expecting and you have tested it on computer screen it becomes easy to code it for android.
And the final step would be to update your android application, for this well know process is using json strings for sending and/or retrieving data to/from database. If you are only looking to insert few fields in database then you can also use GET or POST methods to send and receive data. And the good news is there are many great tutorials available online for HttpRequest from android you can google it yourself.
Disclaimer: I am not promoting any free/paid service provider in my answer, the only reason I mentioned name is because OP has asked twice for it. If you are thinking of downvoting or flagging the answer for that reason please leave comment and I would delete it ASAP.
I would use a simple php page that captures user data via json from Android and saves them in a MySQL db (technology simple and very cheap, there are many hosting php + mysql free or very low cost);
but if you prefer a java-oriented approach, although slightly more complex
I advise you to Google App Engine that is free (with well-defined limits):
http://www.vogella.com/tutorials/GoogleAppEngineJava/article.html
using the latter you will need to use servlets (do not recommend endpoints) and use JPA to access the database which provides GAE (NoSQL database)

Simplest way to make java crud 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 9 years ago.
Improve this question
I am trying study web development using Java but its seems very intimidating. all the tutorials are showing very complex methods, even the sample applications that came with NetBeans. I have some experience working with PHP but none with java.
Is there any simple way to use java on the server to just accept post requests and save to database and then display data from database without using things like javaServer faces?
Is it necessary to use frameworks like spring?
Pls forgive if i am asking stupid questions. i cant seem to find where to start learning from and tutorials seem too confusing.
Links to any good article will be very helpful
Thanks
For this purpose you should be familiar with the Servlet API, and preferably also with MVC frameworks and so on.
For the whole world to be a bit more straightforward for you and to steer away from the average-PHP-community-drawbacks (e.g. nobody tells you how to code well), I'd recommend to read THIS book.
But first of all, start HERE and then move on to THIS SITE.
The other way around (talking about DB access, not the web service here) is using raw SQL via JDBC which I won't recommend unless you have a good reason for it and you're already familiar with using a DB the right way (mysql and mysqli libs of PHP won't necessarily drive you the right path; PDO most probably will however).
Of course you don't necessarily need to use frameworks, but you're (actually in any language) way better off using them. Yes, probably the closest thing to the "nobrainers-php-methodology" (mindless coding; wiring UI, DB access and business logic together in a single file; etc.) is using the Servlet API, and then through a java.sql.Connection send your GET/POST data directly to the DB via JDBC. But doing so is slightly worse than cruelly murdering cute little squirrels/bunnies/kitties/insert_your_favourite_cute_creature_here
You'll also need a servlet container, most common of which is Apache Tomcat.
To learn Web Developing with Java Play Framework 1 is very nice:
Step by Step guide for a cool blog: http://www.playframework.com/documentation/1.2.7/guide1
Documentation: http://www.playframework.com/documentation/1.2.7/home
CRUD module documentation: http://www.playframework.com/documentation/1.2.7/crud
You get compile feedback directly in the browser.
Run your tests in the browser.
No redeployment to containers necessary/hot deployment.
No servlets.
Play 2 is already around, but going through Play 1 is much simpler if you are new a the Java world.

Starting to develop a backend for my Flash game, Java or PHP? [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 8 years ago.
Improve this question
quick question, Im starting to develop the backend for a Flash game, and Im very used to AS3 sintax, and I know that Java has a very similar sintaxis, in the other hand I heard that it could be a little more complex to do than with php.
So, Im kind of new to php, and I could get used very quickly to Java, whats my best option?
(I need to do things like: user login, highscore table, etc)
It depends on the complexity that you have in the server side. Usually a Flash game do not need a complex business logic in the server side, I would use PHP in this case, Java otherwise.
If you are going to host this application, Java hosts are way more expensive than PHP ones also.
From what I understand here, Actionscript is more like JavaScript, not Java.
PHP and Java are both very suitable for a back-end to your game. I prefer PHP, but I am biased.
However, you are looking to stay within familiar territory, you should look at using Node.js, which is basically server-side JavaScript.
Yeah, I jumped from java to AS3 without any problem:D The one big advantage of php is that almost every server has it and with java is harder to find some reliable hostings. PHP could be also easier and little faster to develop some simple backend.
In terms of a similar programming experience one will find more comfort in Java than PHP. The main difference is that PHP is dynamic and the other two are compiled. The consequence is that debugging of Java and AS3 happens when it is being compiled, and in PHP when it runs. You also do not deal with predefining types in PHP for that matter and can totally ignore Object Orientation in it. Java and AS3 are more strict and require all these things. So in terms of choosing a language, Java will be more familiar (and easier) to pick up for a AS3 developer.
In terms of support for web based hosting and development, you'll find PHP more suitable since a majority of cheap hosting companies will have those installed by default. In addition, PHP was developed especially with the web in mind where precompiled web applications are not the best option in most cases. PHP in this regard deploys extremely easy (you just move the files onto your server). In terms of support for webdevelopment and specific examples for web based problems in combination with the support for PHP and deployment, you'll be better off with PHP.
Both have integration libraries, BlazeDS for Java, and AMFPHP for PHP, I haven't tried out the PHP integration I know from experience that Blaze is INCREDIBLY faster than XML or JSON for moving data back and forth. Assuming they're fairly equal then the question is where is it easier to find hosting, and which is better for you to develop and maintain.

Categories

Resources