Is JavaScript able to substitute php? - javascript

I have a friend who started learning website development and he's into php now. I, on the other side started studying Javascript. He asked me if it's possible to use JS instead of php code entirely?
Well, I started learning JS because someone told me, it can be used for both frontend, backend (via NodeJS) and the database (via MongoDB). Though, since I' m a beginner in this field, I'm not sure in the answer, and I'm interested anyway, so I ask you: is it possible?

He asked me if it's possible to use JS instead of php code entirely?
Yes, it's entirely possible. There are several server-side JavaScript options. Probably the most well-known is NodeJS (usually, but not necessarily, plus Express). But Microsoft has always supported JScript (their dialect of JavaScript) in classic ASP, you can use JavaScript in the Java JVM (via Rhino or Nashorn) and thus use JavaScript in servlets, for years there was SilkJS (built on Google's V8) and now there's its successor DecafJS (built on the JVM), etc.

Related

Java: How do we call java methods from Javascript

For most of time I have worked on the server side using Java, Spring, Hibernate and databases. But now I have decided to learn front end programming using HTML5, CSS3 and Javascript.
I have a simple and elementary question here. How do we invoke java methods from java script ? For example on click of a button or to perform some validations on the server side.
I understand that we can perform ReST calls using Jersey. Are there any other ways to make a call to Java from JavaScript. Since I am a beginner here, I don't want to use Ajax, Servlets or JSP for now.
I have already built a simple application using SWT: SWT: Table Resizing Issue. I am thinking of using this opportunity to learn web programming.
I have already tried searching for answer on StackOverflow but couldn't find one. I hope that I am not duplicating any question.
Thanks.
If you are building a web application that run on the browser (because JavaScript can be also used to build desktop application: NodeJS, Electron…), so everything going from the browser to the backend server should be a http request, this is how the web work. Server Side framework is just doing the job of behalf of you by transforming backend code (Java, .NET, PHP …) to Browser language (html, css and JavaScript) and then performing server call using Http methods (Get, Post …).

Best way for implementing JavaScript lib in Java WebApplication

I am an Android developer and I am new to java web development, so please apologize if my thought is wrong. In our web app project we have to compare images (GIF/PNG/JPEG) and have to show the result.
We got a javascript lib (Resemble.js) which will compare the images and will give the result.
Please help on implementing this lib to my web app project. As its a js lib we can implement it only in front end right? If so is this a correct way? Because we have all other process in backend. Or else how to use a js lib in backend
Or let me know the best way in implementing the same. We are using React.js for front-end.
To execute javascript you need a javascript engine. A java virtual machine is not designed to run javascript so short answer is: You should use the Resemble.js into your front-end browser's engine (or into a back-end server that process javascript like Node.js).
Long answer: There are implementation of JavaScript written in Java that you could use (I don't konw if supports HTML). Take a look at: How can I run JavaScript code at server side Java code?

What role does Node.js play in MEAN stack between JavaScript and Express compared to Django and Python?

I have background in implementing web applications using Python and its popular framework Django and PostgreSQL. Recently I've shifted my attention from Python to JavaScript and planned to take advantage of the benefits that MEAN stack has to offer.
In terms of backend structure, I understand MongoDB is the database to MEAN just like PostgreSQL (and other relational database) is to Python. Express is the framework just like Django. However, where does Node.js fit into? What does it do? What's the equivalent of Node.js in a Django structure? Why does Django+Python combination not need this "extra" layer of abstraction? What feature(s) do JavaScript lack that it needs this extra layer?
I know it might be a simple question but I'm having a hard time understanding it! Thank you very much in advance!
Note that "Javascript" is not in the acronym, whereas with something like LAMP, Python (or PHP or whichever) is. In MEAN, Node.js takes the place of Javascript.
Node.js is basically an interpreter and a runtime environment for Javascript. It is used in the acronym rather than Javascript to distinguish it as separate from browser Javascript. Plus, MEAJ is a pretty horrible acronym.
Node is the interpreter/environment. It's literally the thing that is executing your JavaScript code. I think a better comparison is to think about how the JVM relates to Java

Clientsided data-cleaning and analysis with sturts2

right now I'm trying to implement a webapp that does data cleaning and analysis and I have already a prototype written in Java. For the analysis part I tend to use WEKA (http://www.cs.waikato.ac.nz/ml/weka/). Because of performance reasons I thought it might be a good idea to let the client do most of the work. I started to learn struts2 and I have no experience using JavaScript. My questions are:
Is struts2 the right choise for this task?
Should I write a Java Applet or can it also be done by Java Script?
I don't have enough experience nor have I found a good solution searching the internet. Can you perhaps post some tutorials or websites that might help me with my questions?
If you want to do it client-side then you need to distribute an app, or use an applet. JavaScript is not Java, and you can't use the browser's JavaScript to run Weka.
If you want to do it client-side, why are you trying to implement a web app?
Struts 2 is fine, but it depends on what you're actually doing. There are many JVM-based web frameworks: Spring MVC, Grails, Play, etc. If you want to move analysis onto the client it probably doesn't matter what framework you use, but it's impossible to say from the info you've provided.

JavaScript on the server-side like PHP

I'm now thinking to establish my server-side code in JavaScript, and begin to do all on it, but I want to know about its security and flexibility compared to PHP.
I want to know too, if it can be successfully used to develop things like forum boards, full web-sites and things like this, as PHP does.
Javascript is just now starting to get some presence on the server, with things like ServerJS and nodeJS, but right now, you would probably be best off using PHP for your server side code, and javascript for client-side beautification.
The question is very, very broad. Interpreting it as "can I use Javascript on the server":
Fundamentally, sure, Javascript is a very powerful language and so you can do development in it server-side just like you can client-side (and if you do client-side scripting as well, you get some definite reuse benefits using Javascript on the server).
For Apache systems, there's the v8cgi project (a FastCGI Javascript plug-in with connectors, using Google's freaky-fast V8 engine).
On Microsoft-based systems, IIS supports Javascript (JScript) on the server out of the box (I use that all the time), which has access to all of the ActiveX stuff (e.g., for talking to databases, dealing with the file system, etc.).
If your server framework is JVM-based, there's Rhino, which is Javascript for the Java platform and has access to all (or nearly all) of the libraries available for Java — e.g., a huge ecosystem of libraries and plug-ins.
Aside from v8cgi, there are a couple of other projects built on Google's V8 engine.
There's a place that does a full stack for you called chromeserver (I don't know what their backend is; I'm not going to infer from the name).
Paul mentioned ServerJS and NodeJS.
There's the whole CommonJS project.
Etc. etc. etc. There's quite a list on Wikipedia.
Arguing against, there's a very rich ecosystem built around PHP. Unless you're using something like Rhino for the Java platform or JScript on IIS (because of the ecosystems they leverage), you may find that you don't have nearly that ecosystem available to you when developing in Javascript for the server. I mean, if you're looking for pre-built forum or wiki software (for example), let's just say you can't swing a dead cat without finding one based on PHP, and the same cannot be said of Javascript on the server.
The way they are usually used, PHP and JavaScript run in entirely different worlds, and are not really comparable. (There is a server-side version of JavaScript but it's fair to say it's not especially widespread yet, and doesn't run on standard web hosting.)
The security issues you are going to encounter in JavaScript (on the browser) side are very different from what you have to look out for in PHP.
I want to know too, if it can be sucessfully used to develop things like forum boards, full web-sites and things like this, as PHP does.
No, not with client-side Javascript. For dynamic applications, you will always need some server-side language backing it, be it PHP or some other language like ASP, Python, Ruby, Perl....
To replace PHP with Javascript, you need server-side Javascript and there is a lot happening on that front. Mozilla’s Rhino runs Javascript atop the JVM and it seems Google is also working on its own server side Javascript framework. The most popular in-production implementations are:
Helma: Several active projects are using it, runs on Jetty & Rhino and lets developers leverage the power of JVM, has its own object-oriented MVC framework
Project Phobos: runs on Glassfish & Rhino and lets developers leverage the power of JVM, includes plug-ins for NetBeans and integrates with jMaki Web UI framework
JSSP: A very simple server side framework, a lot like classic ASP, JSP and PHP
Aptana’s Jaxer showed a lot of promise, especially by bringing the DOM to the server side, but the project seems dead now. From what I understand, node.js is not a server-side Javascript framework in the same sense as Helma and Phobos. Instead it can be used for writing event-driven servers in Javascript (for example: writing your own web server).
Yes, my site is written by node.js
Using websvr, it's Java style have filter and handlers, hosting on debian OS.
This is slightly off-topic, but it may actually get to the core of your question:
if you want to use only one language for web applications, you may wanna have a look at Haxe.
It is a cross-platform language, that (among other targets) compiles to JavaScript and PHP source as well as NekoVM bytecode. For server-side JavaScript, there are NodeJS bindings.
This way you are not bound to a specific platform. The neko and PHP APIs are largely compatible, so you can deploy on both platforms, having the option to choose neko's speed and persistency or PHP's ease of deployment. Please note however, the PHP output has a little overhead although common optimizers as eaccelerator will make this barely noticeable.
Haxe is significantly less forgiving than both JavaScript and PHP. This makes it harder to learn, but a much safer, robust and in the end more productive tool.
In a word: no. Javascript is a client-side language. In order to do the things that you are describing, you need a server-side language such as PHP.
EDIT: OK, technically it is possible to implement Javascript in other areas besides the browser, but this is not very common.
5 YEAR EDIT: Well, 5 years later, this answer obviously is not accurate, with the popularity of things like node.js. Let that be a testament to how quickly things can change!
PHP and JavaScript are two different languages that do two different things. One cannot replace the other. You are most likely going to use a combination of the two. JavaScript for client-side stuff. PHP for server-side stuff.

Categories

Resources